blob: dc17854f21a55da92d51512da5a8d1ca68dbff07 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * $Id$
31 */
32
33#include "defs.h"
34
35#include <dirent.h>
Roland McGrathc531e572008-08-01 01:13:10 +000036
Michal Ludvig53b320f2002-09-23 13:30:09 +000037#ifdef LINUX
Roland McGrathc531e572008-08-01 01:13:10 +000038struct kernel_dirent {
39 unsigned long d_ino;
40 unsigned long d_off;
41 unsigned short d_reclen;
42 char d_name[1];
43};
Wichert Akkerman9524bb91999-05-25 23:11:18 +000044#else
Roland McGrathc531e572008-08-01 01:13:10 +000045# define kernel_dirent dirent
Wichert Akkerman9524bb91999-05-25 23:11:18 +000046#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
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000241#if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000242 { 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
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000330/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
331 * extension to get the right value. We do this by declaring fd as int here.
332 */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000333static void
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000334print_dirfd(int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000335{
336 if (fd == AT_FDCWD)
337 tprintf("AT_FDCWD, ");
338 else
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000339 tprintf("%d, ", fd);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000340}
341#endif
342
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000343/*
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000344 * Pity stpcpy() is not standardized...
345 */
346static char *
347str_append(char *dst, const char *src)
348{
349 while ((*dst = *src++) != '\0')
350 dst++;
351 return dst;
352}
353
354/*
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000355 * low bits of the open(2) flags define access mode,
356 * other bits are real flags.
357 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000358const char *
359sprint_open_modes(mode_t flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000360{
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000361 static char outstr[1024];
362 char *p;
363 char sep = 0;
364 const char *str;
365 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000366
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000367 p = str_append(outstr, "flags ");
368 str = xlookup(open_access_modes, flags & 3);
369 if (str) {
370 p = str_append(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000371 flags &= ~3;
372 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000373 return outstr;
374 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000375 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000376
377 for (x = open_mode_flags; x->str; x++) {
378 if ((flags & x->val) == x->val) {
379 if (sep)
380 *p++ = sep;
381 p = str_append(p, x->str);
382 flags &= ~x->val;
383 if (!flags)
384 return outstr;
385 sep = '|';
386 }
387 }
388 /* flags is still nonzero */
389 if (sep)
390 *p++ = sep;
391 sprintf(p, "%#x", flags);
392 return outstr;
393}
394
395void
396tprint_open_modes(mode_t flags)
397{
Dmitry V. Levin4bcd5ef2009-06-01 10:32:27 +0000398 tprintf("%s", sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000399}
400
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000401static int
402decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000403{
404 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000405 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406 tprintf(", ");
407 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000408 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000409 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000410 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000411 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000412 }
413 }
414 return 0;
415}
416
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000417int
418sys_open(struct tcb *tcp)
419{
420 return decode_open(tcp, 0);
421}
422
423#ifdef LINUX
424int
425sys_openat(struct tcb *tcp)
426{
427 if (entering(tcp))
428 print_dirfd(tcp->u_arg[0]);
429 return decode_open(tcp, 1);
430}
431#endif
432
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000433#ifdef LINUXSPARC
Roland McGratha4d48532005-06-08 20:45:28 +0000434static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000435 { 0, "O_RDWR" },
436 { 1, "O_RDONLY" },
437 { 2, "O_WRONLY" },
438 { 0x80, "O_NONBLOCK" },
439 { 8, "O_APPEND" },
440 { 0x100, "O_CREAT" },
441 { 0x200, "O_TRUNC" },
442 { 0x400, "O_EXCL" },
443 { 0x800, "O_NOCTTY" },
444 { 0x10, "O_SYNC" },
445 { 0x40, "O_DSYNC" },
446 { 0x8000, "O_RSYNC" },
447 { 4, "O_NDELAY" },
448 { 0x1000, "O_PRIV" },
449 { 0, NULL },
450};
451
452int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000453solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000454{
455 if (entering(tcp)) {
456 printpath(tcp, tcp->u_arg[0]);
457 tprintf(", ");
458 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000459 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000460 if (tcp->u_arg[1] & 0x100) {
461 /* mode */
462 tprintf(", %#lo", tcp->u_arg[2]);
463 }
464 }
465 return 0;
466}
467
468#endif
469
470int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000471sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000472{
473 if (entering(tcp)) {
474 printpath(tcp, tcp->u_arg[0]);
475 tprintf(", %#lo", tcp->u_arg[1]);
476 }
477 return 0;
478}
479
Roland McGrathd9f816f2004-09-04 03:39:20 +0000480static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000481 { F_OK, "F_OK", },
482 { R_OK, "R_OK" },
483 { W_OK, "W_OK" },
484 { X_OK, "X_OK" },
485#ifdef EFF_ONLY_OK
486 { EFF_ONLY_OK, "EFF_ONLY_OK" },
487#endif
488#ifdef EX_OK
489 { EX_OK, "EX_OK" },
490#endif
491 { 0, NULL },
492};
493
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000494static int
495decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000496{
497 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000498 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000499 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000500 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000501 }
502 return 0;
503}
504
505int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000506sys_access(struct tcb *tcp)
507{
508 return decode_access(tcp, 0);
509}
510
511#ifdef LINUX
512int
513sys_faccessat(struct tcb *tcp)
514{
515 if (entering(tcp))
516 print_dirfd(tcp->u_arg[0]);
517 return decode_access(tcp, 1);
518}
519#endif
520
521int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000522sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000523{
524 if (entering(tcp)) {
525 tprintf("%#lo", tcp->u_arg[0]);
526 }
527 return RVAL_OCTAL;
528}
529
Roland McGrathd9f816f2004-09-04 03:39:20 +0000530static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000531 { SEEK_SET, "SEEK_SET" },
532 { SEEK_CUR, "SEEK_CUR" },
533 { SEEK_END, "SEEK_END" },
534 { 0, NULL },
535};
536
John Hughes70623be2001-03-08 13:59:00 +0000537#ifndef HAVE_LONG_LONG_OFF_T
Roland McGrath542c2c62008-05-20 01:11:56 +0000538#if defined (LINUX_MIPSN32)
539int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000540sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000541{
542 long long offset;
543 int _whence;
544
545 if (entering(tcp)) {
546 tprintf("%ld, ", tcp->u_arg[0]);
547 offset = tcp->ext_arg[1];
548 _whence = tcp->u_arg[2];
549 if (_whence == SEEK_SET)
550 tprintf("%llu, ", offset);
551 else
552 tprintf("%lld, ", offset);
553 printxval(whence, _whence, "SEEK_???");
554 }
555 return RVAL_UDECIMAL;
556}
557#else /* !LINUX_MIPSN32 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000559sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000560{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000561 off_t offset;
562 int _whence;
563
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564 if (entering(tcp)) {
565 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000566 offset = tcp->u_arg[1];
567 _whence = tcp->u_arg[2];
568 if (_whence == SEEK_SET)
569 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000570 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000571 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000572 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000573 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000574 return RVAL_UDECIMAL;
575}
Roland McGrath542c2c62008-05-20 01:11:56 +0000576#endif /* LINUX_MIPSN32 */
John Hughes5a826b82001-03-07 13:21:24 +0000577#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000578
Michal Ludvig53b320f2002-09-23 13:30:09 +0000579#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000580int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000581sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000582{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000583 if (entering(tcp)) {
584 /*
585 * This one call takes explicitly two 32-bit arguments hi, lo,
586 * rather than one 64-bit argument for which LONG_LONG works
587 * appropriate for the native byte order.
588 */
589 if (tcp->u_arg[4] == SEEK_SET)
590 tprintf("%ld, %llu, ", tcp->u_arg[0],
591 (((long long int) tcp->u_arg[1]) << 32
592 | (unsigned long long) (unsigned) tcp->u_arg[2]));
593 else
594 tprintf("%ld, %lld, ", tcp->u_arg[0],
595 (((long long int) tcp->u_arg[1]) << 32
596 | (unsigned long long) (unsigned) tcp->u_arg[2]));
597 }
598 else {
599 long long int off;
600 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
601 tprintf("%#lx, ", tcp->u_arg[3]);
602 else
603 tprintf("[%llu], ", off);
604 printxval(whence, tcp->u_arg[4], "SEEK_???");
605 }
606 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000607}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000608
609int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000610sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000611{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000612 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100613 int argn;
614 tprintf("%ld, ", tcp->u_arg[0]);
615 argn = printllval(tcp, "%lld", 1);
616 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000617 }
618 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000619}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000620#endif
621
John Hughes70623be2001-03-08 13:59:00 +0000622#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000623int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000624sys_lseek64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +0000625{
626 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100627 int argn;
628 tprintf("%ld, ", tcp->u_arg[0]);
John Hughesbdf48f52001-03-06 15:08:09 +0000629 if (tcp->u_arg[3] == SEEK_SET)
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100630 argn = printllval(tcp, "%llu, ", 1);
John Hughesbdf48f52001-03-06 15:08:09 +0000631 else
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100632 argn = printllval(tcp, "%lld, ", 1);
633 printxval(whence, tcp->u_arg[argn], "SEEK_???");
John Hughesbdf48f52001-03-06 15:08:09 +0000634 }
635 return RVAL_LUDECIMAL;
636}
637#endif
638
John Hughes70623be2001-03-08 13:59:00 +0000639#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000640int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000641sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000642{
643 if (entering(tcp)) {
644 printpath(tcp, tcp->u_arg[0]);
645 tprintf(", %lu", tcp->u_arg[1]);
646 }
647 return 0;
648}
John Hughes5a826b82001-03-07 13:21:24 +0000649#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000650
John Hughes70623be2001-03-08 13:59:00 +0000651#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000652int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000653sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000654{
655 if (entering(tcp)) {
656 printpath(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100657 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000658 }
659 return 0;
660}
661#endif
662
John Hughes70623be2001-03-08 13:59:00 +0000663#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000664int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000665sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000666{
667 if (entering(tcp)) {
668 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
669 }
670 return 0;
671}
John Hughes5a826b82001-03-07 13:21:24 +0000672#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000673
John Hughes70623be2001-03-08 13:59:00 +0000674#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000675int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000676sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000677{
678 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100679 tprintf("%ld, ", tcp->u_arg[0]);
680 printllval(tcp, "%llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000681 }
682 return 0;
683}
684#endif
685
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000686/* several stats */
687
Roland McGrathd9f816f2004-09-04 03:39:20 +0000688static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000689 { S_IFREG, "S_IFREG" },
690 { S_IFSOCK, "S_IFSOCK" },
691 { S_IFIFO, "S_IFIFO" },
692 { S_IFLNK, "S_IFLNK" },
693 { S_IFDIR, "S_IFDIR" },
694 { S_IFBLK, "S_IFBLK" },
695 { S_IFCHR, "S_IFCHR" },
696 { 0, NULL },
697};
698
Roland McGrathf9c49b22004-10-06 22:11:54 +0000699static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000700sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000701{
702 static char buf[64];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000703 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000704
705 if ((mode & S_IFMT) == 0)
706 s = "";
707 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
708 sprintf(buf, "%#o", mode);
709 return buf;
710 }
711 sprintf(buf, "%s%s%s%s", s,
712 (mode & S_ISUID) ? "|S_ISUID" : "",
713 (mode & S_ISGID) ? "|S_ISGID" : "",
714 (mode & S_ISVTX) ? "|S_ISVTX" : "");
715 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
716 if (mode)
717 sprintf(buf + strlen(buf), "|%#o", mode);
718 s = (*buf == '|') ? buf + 1 : buf;
719 return *s ? s : "0";
720}
721
722static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000723sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000724{
725 struct tm *tmp;
726 static char buf[32];
727
728 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000729 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000730 return buf;
731 }
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000732 if ((tmp = localtime(&t)))
733 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
734 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
735 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
736 else
737 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
738
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000739 return buf;
740}
741
742#ifdef LINUXSPARC
743typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000744 int tv_sec;
745 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000746} timestruct_t;
747
748struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000749 unsigned st_dev;
750 int st_pad1[3]; /* network id */
751 unsigned st_ino;
752 unsigned st_mode;
753 unsigned st_nlink;
754 unsigned st_uid;
755 unsigned st_gid;
756 unsigned st_rdev;
757 int st_pad2[2];
758 int st_size;
759 int st_pad3; /* st_size, off_t expansion */
760 timestruct_t st_atime;
761 timestruct_t st_mtime;
762 timestruct_t st_ctime;
763 int st_blksize;
764 int st_blocks;
765 char st_fstype[16];
766 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000767};
768
769static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000770printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000771{
772 struct solstat statbuf;
773
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000774 if (umove(tcp, addr, &statbuf) < 0) {
775 tprintf("{...}");
776 return;
777 }
778 if (!abbrev(tcp)) {
779 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
780 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
781 (unsigned long) (statbuf.st_dev & 0x3ffff),
782 (unsigned long) statbuf.st_ino,
783 sprintmode(statbuf.st_mode));
784 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
785 (unsigned long) statbuf.st_nlink,
786 (unsigned long) statbuf.st_uid,
787 (unsigned long) statbuf.st_gid);
788 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
789 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
790 }
791 else
792 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
793 switch (statbuf.st_mode & S_IFMT) {
794 case S_IFCHR: case S_IFBLK:
795 tprintf("st_rdev=makedev(%lu, %lu), ",
796 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
797 (unsigned long) (statbuf.st_rdev & 0x3ffff));
798 break;
799 default:
800 tprintf("st_size=%u, ", statbuf.st_size);
801 break;
802 }
803 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000804 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
805 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
806 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000807 }
808 else
809 tprintf("...}");
810}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000811
812#if defined (SPARC64)
813static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000814printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000815{
816 struct stat_sparc64 statbuf;
817
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000818 if (umove(tcp, addr, &statbuf) < 0) {
819 tprintf("{...}");
820 return;
821 }
822
823 if (!abbrev(tcp)) {
824 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
825 (unsigned long) major(statbuf.st_dev),
826 (unsigned long) minor(statbuf.st_dev),
827 (unsigned long) statbuf.st_ino,
828 sprintmode(statbuf.st_mode));
829 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
830 (unsigned long) statbuf.st_nlink,
831 (unsigned long) statbuf.st_uid,
832 (unsigned long) statbuf.st_gid);
833 tprintf("st_blksize=%lu, ",
834 (unsigned long) statbuf.st_blksize);
835 tprintf("st_blocks=%lu, ",
836 (unsigned long) statbuf.st_blocks);
837 }
838 else
839 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
840 switch (statbuf.st_mode & S_IFMT) {
841 case S_IFCHR: case S_IFBLK:
842 tprintf("st_rdev=makedev(%lu, %lu), ",
843 (unsigned long) major(statbuf.st_rdev),
844 (unsigned long) minor(statbuf.st_rdev));
845 break;
846 default:
847 tprintf("st_size=%lu, ", statbuf.st_size);
848 break;
849 }
850 if (!abbrev(tcp)) {
851 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
852 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
853 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
854 tprintf("}");
855 }
856 else
857 tprintf("...}");
858}
859#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000860#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000861
Andreas Schwabd69fa492010-07-12 21:39:57 +0200862#if defined LINUX && defined POWERPC64
863struct stat_powerpc32 {
864 unsigned int st_dev;
865 unsigned int st_ino;
866 unsigned int st_mode;
867 unsigned short st_nlink;
868 unsigned int st_uid;
869 unsigned int st_gid;
870 unsigned int st_rdev;
871 unsigned int st_size;
872 unsigned int st_blksize;
873 unsigned int st_blocks;
874 unsigned int st_atime;
875 unsigned int st_atime_nsec;
876 unsigned int st_mtime;
877 unsigned int st_mtime_nsec;
878 unsigned int st_ctime;
879 unsigned int st_ctime_nsec;
880 unsigned int __unused4;
881 unsigned int __unused5;
882};
883
884static void
885printstat_powerpc32(struct tcb *tcp, long addr)
886{
887 struct stat_powerpc32 statbuf;
888
889 if (umove(tcp, addr, &statbuf) < 0) {
890 tprintf("{...}");
891 return;
892 }
893
894 if (!abbrev(tcp)) {
895 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
896 major(statbuf.st_dev), minor(statbuf.st_dev),
897 statbuf.st_ino,
898 sprintmode(statbuf.st_mode));
899 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
900 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
901 tprintf("st_blksize=%u, ", statbuf.st_blksize);
902 tprintf("st_blocks=%u, ", statbuf.st_blocks);
903 }
904 else
905 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
906 switch (statbuf.st_mode & S_IFMT) {
907 case S_IFCHR: case S_IFBLK:
908 tprintf("st_rdev=makedev(%lu, %lu), ",
909 (unsigned long) major(statbuf.st_rdev),
910 (unsigned long) minor(statbuf.st_rdev));
911 break;
912 default:
913 tprintf("st_size=%u, ", statbuf.st_size);
914 break;
915 }
916 if (!abbrev(tcp)) {
917 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
918 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
919 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
920 tprintf("}");
921 }
922 else
923 tprintf("...}");
924}
925#endif /* LINUX && POWERPC64 */
926
Roland McGratha4d48532005-06-08 20:45:28 +0000927static const struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000928#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000929 { UF_NODUMP, "UF_NODUMP" },
930 { UF_IMMUTABLE, "UF_IMMUTABLE" },
931 { UF_APPEND, "UF_APPEND" },
932 { UF_OPAQUE, "UF_OPAQUE" },
933 { UF_NOUNLINK, "UF_NOUNLINK" },
934 { SF_ARCHIVED, "SF_ARCHIVED" },
935 { SF_IMMUTABLE, "SF_IMMUTABLE" },
936 { SF_APPEND, "SF_APPEND" },
937 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000938#elif UNIXWARE >= 2
939#ifdef _S_ISMLD
940 { _S_ISMLD, "_S_ISMLD" },
941#endif
942#ifdef _S_ISMOUNTED
943 { _S_ISMOUNTED, "_S_ISMOUNTED" },
944#endif
945#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000946 { 0, NULL },
947};
948
John Hughesc0fc3fd2001-03-08 16:10:40 +0000949#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000950int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000951sys_chflags(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000952{
953 if (entering(tcp)) {
954 printpath(tcp, tcp->u_arg[0]);
955 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000956 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000957 }
958 return 0;
959}
960
961int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000962sys_fchflags(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000963{
964 if (entering(tcp)) {
965 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000966 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000967 }
968 return 0;
969}
970#endif
971
John Hughes70623be2001-03-08 13:59:00 +0000972#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000973static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000974realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000975{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000976 if (!abbrev(tcp)) {
977 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
978 (unsigned long) major(statbuf->st_dev),
979 (unsigned long) minor(statbuf->st_dev),
980 (unsigned long) statbuf->st_ino,
981 sprintmode(statbuf->st_mode));
982 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
983 (unsigned long) statbuf->st_nlink,
984 (unsigned long) statbuf->st_uid,
985 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000986#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000987 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
988#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000989#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000990 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
991#endif
992 }
993 else
994 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
995 switch (statbuf->st_mode & S_IFMT) {
996 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000997#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000998 tprintf("st_rdev=makedev(%lu, %lu), ",
999 (unsigned long) major(statbuf->st_rdev),
1000 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001001#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +00001002 tprintf("st_size=makedev(%lu, %lu), ",
1003 (unsigned long) major(statbuf->st_size),
1004 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001005#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +00001006 break;
1007 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +00001008 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +00001009 break;
1010 }
1011 if (!abbrev(tcp)) {
1012 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
1013 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
1014 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001015#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +00001016 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001017 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001018#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001019#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001020 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
1021#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001022#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001023 tprintf(", st_level=%ld", statbuf->st_level);
1024#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001025#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001026 tprintf(", st_fstype=%.*s",
1027 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
1028#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001029#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001030 tprintf(", st_gen=%u", statbuf->st_gen);
1031#endif
1032 tprintf("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +00001033 }
1034 else
1035 tprintf("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001036}
1037
Nate Sammons771a6ff1999-04-05 22:39:31 +00001038
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001039static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001040printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001041{
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001042 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001043
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001044 if (!addr) {
1045 tprintf("NULL");
1046 return;
1047 }
1048 if (syserror(tcp) || !verbose(tcp)) {
1049 tprintf("%#lx", addr);
1050 return;
1051 }
1052
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001053#ifdef LINUXSPARC
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001054 if (current_personality == 1) {
1055 printstatsol(tcp, addr);
1056 return;
1057 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001058#ifdef SPARC64
1059 else if (current_personality == 2) {
1060 printstat_sparc64(tcp, addr);
1061 return;
1062 }
1063#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001064#endif /* LINUXSPARC */
1065
Andreas Schwabd69fa492010-07-12 21:39:57 +02001066#if defined LINUX && defined POWERPC64
1067 if (current_personality == 1) {
1068 printstat_powerpc32(tcp, addr);
1069 return;
1070 }
1071#endif
1072
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001073 if (umove(tcp, addr, &statbuf) < 0) {
1074 tprintf("{...}");
1075 return;
1076 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001077
1078 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001079}
John Hughes70623be2001-03-08 13:59:00 +00001080#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001081
Roland McGrathe6d0f712007-08-07 01:22:49 +00001082#if !defined HAVE_STAT64 && defined LINUX && defined X86_64
1083/*
1084 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1085 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1086 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1087 * __GNUC__ is needed for the required __attribute__ below.
1088 */
1089struct stat64 {
1090 unsigned long long st_dev;
1091 unsigned char __pad0[4];
1092 unsigned int __st_ino;
1093 unsigned int st_mode;
1094 unsigned int st_nlink;
1095 unsigned int st_uid;
1096 unsigned int st_gid;
1097 unsigned long long st_rdev;
1098 unsigned char __pad3[4];
1099 long long st_size;
1100 unsigned int st_blksize;
1101 unsigned long long st_blocks;
1102 unsigned int st_atime;
1103 unsigned int st_atime_nsec;
1104 unsigned int st_mtime;
1105 unsigned int st_mtime_nsec;
1106 unsigned int st_ctime;
1107 unsigned int st_ctime_nsec;
1108 unsigned long long st_ino;
1109} __attribute__((packed));
1110# define HAVE_STAT64 1
1111# define STAT64_SIZE 96
1112#endif
1113
Wichert Akkermanc7926982000-04-10 22:22:31 +00001114#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001115static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001116printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001117{
1118 struct stat64 statbuf;
1119
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001120#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001121 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1122#endif
1123
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001124 if (!addr) {
1125 tprintf("NULL");
1126 return;
1127 }
1128 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001129 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001130 return;
1131 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001132
1133#ifdef LINUXSPARC
1134 if (current_personality == 1) {
1135 printstatsol(tcp, addr);
1136 return;
1137 }
1138# ifdef SPARC64
1139 else if (current_personality == 2) {
1140 printstat_sparc64(tcp, addr);
1141 return;
1142 }
1143# endif
1144#endif /* LINUXSPARC */
1145
Andreas Schwab61b74352009-10-16 11:37:13 +02001146#if defined LINUX && defined X86_64
1147 if (current_personality == 0) {
1148 printstat(tcp, addr);
1149 return;
1150 }
1151#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +00001152
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001153 if (umove(tcp, addr, &statbuf) < 0) {
1154 tprintf("{...}");
1155 return;
1156 }
1157
1158 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001159#ifdef HAVE_LONG_LONG
1160 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1161#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001162 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001163#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001164 (unsigned long) major(statbuf.st_dev),
1165 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001166#ifdef HAVE_LONG_LONG
1167 (unsigned long long) statbuf.st_ino,
1168#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001169 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001170#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001171 sprintmode(statbuf.st_mode));
1172 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1173 (unsigned long) statbuf.st_nlink,
1174 (unsigned long) statbuf.st_uid,
1175 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001176#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001177 tprintf("st_blksize=%lu, ",
1178 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001179#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1180#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001181 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001182#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001183 }
1184 else
1185 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1186 switch (statbuf.st_mode & S_IFMT) {
1187 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001188#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001189 tprintf("st_rdev=makedev(%lu, %lu), ",
1190 (unsigned long) major(statbuf.st_rdev),
1191 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001192#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001193 tprintf("st_size=makedev(%lu, %lu), ",
1194 (unsigned long) major(statbuf.st_size),
1195 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001196#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001197 break;
1198 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001199#ifdef HAVE_LONG_LONG
1200 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1201#else
1202 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1203#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001204 break;
1205 }
1206 if (!abbrev(tcp)) {
1207 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1208 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001209 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001210#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +00001211 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001212 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001213#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001214#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001215 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1216#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001217#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001218 tprintf(", st_level=%ld", statbuf.st_level);
1219#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001220#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001221 tprintf(", st_fstype=%.*s",
1222 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1223#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001224#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001225 tprintf(", st_gen=%u", statbuf.st_gen);
1226#endif
1227 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001228 }
1229 else
1230 tprintf("...}");
1231}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001232#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001233
Roland McGrath79db8af2003-06-27 21:20:09 +00001234#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001235static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001236convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001237{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001238 newbuf->st_dev = oldbuf->st_dev;
1239 newbuf->st_ino = oldbuf->st_ino;
1240 newbuf->st_mode = oldbuf->st_mode;
1241 newbuf->st_nlink = oldbuf->st_nlink;
1242 newbuf->st_uid = oldbuf->st_uid;
1243 newbuf->st_gid = oldbuf->st_gid;
1244 newbuf->st_rdev = oldbuf->st_rdev;
1245 newbuf->st_size = oldbuf->st_size;
1246 newbuf->st_atime = oldbuf->st_atime;
1247 newbuf->st_mtime = oldbuf->st_mtime;
1248 newbuf->st_ctime = oldbuf->st_ctime;
1249 newbuf->st_blksize = 0; /* not supported in old_stat */
1250 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001251}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001252
1253
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001254static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001255printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001256{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001257 struct __old_kernel_stat statbuf;
1258 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001259
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001260 if (!addr) {
1261 tprintf("NULL");
1262 return;
1263 }
1264 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001265 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001266 return;
1267 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001268
1269#ifdef LINUXSPARC
1270 if (current_personality == 1) {
1271 printstatsol(tcp, addr);
1272 return;
1273 }
1274#endif /* LINUXSPARC */
1275
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001276 if (umove(tcp, addr, &statbuf) < 0) {
1277 tprintf("{...}");
1278 return;
1279 }
1280
1281 convertoldstat(&statbuf, &newstatbuf);
1282 realprintstat(tcp, &newstatbuf);
1283}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001284#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001285
John Hughes70623be2001-03-08 13:59:00 +00001286#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001287int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001288sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001289{
1290 if (entering(tcp)) {
1291 printpath(tcp, tcp->u_arg[0]);
1292 tprintf(", ");
1293 } else {
1294 printstat(tcp, tcp->u_arg[1]);
1295 }
1296 return 0;
1297}
John Hughesb8c9f772001-03-07 16:53:07 +00001298#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001299
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001300int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001301sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001302{
1303#ifdef HAVE_STAT64
1304 if (entering(tcp)) {
1305 printpath(tcp, tcp->u_arg[0]);
1306 tprintf(", ");
1307 } else {
1308 printstat64(tcp, tcp->u_arg[1]);
1309 }
1310 return 0;
1311#else
1312 return printargs(tcp);
1313#endif
1314}
1315
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001316#ifdef LINUX
1317static const struct xlat fstatatflags[] = {
1318#ifndef AT_SYMLINK_NOFOLLOW
1319# define AT_SYMLINK_NOFOLLOW 0x100
1320#endif
1321 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1322 { 0, NULL },
1323};
Roland McGrath6afc5652007-07-24 01:57:11 +00001324#define utimensatflags fstatatflags
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001325
1326int
1327sys_newfstatat(struct tcb *tcp)
1328{
1329 if (entering(tcp)) {
1330 print_dirfd(tcp->u_arg[0]);
1331 printpath(tcp, tcp->u_arg[1]);
1332 tprintf(", ");
1333 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001334#ifdef POWERPC64
1335 if (current_personality == 0)
1336 printstat(tcp, tcp->u_arg[2]);
1337 else
1338 printstat64(tcp, tcp->u_arg[2]);
1339#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001340 printstat64(tcp, tcp->u_arg[2]);
1341#else
1342 printstat(tcp, tcp->u_arg[2]);
1343#endif
1344 tprintf(", ");
1345 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1346 }
1347 return 0;
1348}
1349#endif
1350
Roland McGrath79db8af2003-06-27 21:20:09 +00001351#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001352int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001353sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001354{
1355 if (entering(tcp)) {
1356 printpath(tcp, tcp->u_arg[0]);
1357 tprintf(", ");
1358 } else {
1359 printoldstat(tcp, tcp->u_arg[1]);
1360 }
1361 return 0;
1362}
Roland McGrath79db8af2003-06-27 21:20:09 +00001363#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001364
John Hughes70623be2001-03-08 13:59:00 +00001365#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001366int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001367sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001368{
1369 if (entering(tcp))
1370 tprintf("%ld, ", tcp->u_arg[0]);
1371 else {
1372 printstat(tcp, tcp->u_arg[1]);
1373 }
1374 return 0;
1375}
John Hughesb8c9f772001-03-07 16:53:07 +00001376#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001377
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001378int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001379sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001380{
1381#ifdef HAVE_STAT64
1382 if (entering(tcp))
1383 tprintf("%ld, ", tcp->u_arg[0]);
1384 else {
1385 printstat64(tcp, tcp->u_arg[1]);
1386 }
1387 return 0;
1388#else
1389 return printargs(tcp);
1390#endif
1391}
1392
Roland McGrath79db8af2003-06-27 21:20:09 +00001393#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001394int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001395sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001396{
1397 if (entering(tcp))
1398 tprintf("%ld, ", tcp->u_arg[0]);
1399 else {
1400 printoldstat(tcp, tcp->u_arg[1]);
1401 }
1402 return 0;
1403}
Roland McGrath79db8af2003-06-27 21:20:09 +00001404#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001405
John Hughes70623be2001-03-08 13:59:00 +00001406#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001407int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001408sys_lstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001409{
1410 if (entering(tcp)) {
1411 printpath(tcp, tcp->u_arg[0]);
1412 tprintf(", ");
1413 } else {
1414 printstat(tcp, tcp->u_arg[1]);
1415 }
1416 return 0;
1417}
John Hughesb8c9f772001-03-07 16:53:07 +00001418#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001419
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001420int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001421sys_lstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001422{
1423#ifdef HAVE_STAT64
1424 if (entering(tcp)) {
1425 printpath(tcp, tcp->u_arg[0]);
1426 tprintf(", ");
1427 } else {
1428 printstat64(tcp, tcp->u_arg[1]);
1429 }
1430 return 0;
1431#else
1432 return printargs(tcp);
1433#endif
1434}
1435
Roland McGrath79db8af2003-06-27 21:20:09 +00001436#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001437int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001438sys_oldlstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001439{
1440 if (entering(tcp)) {
1441 printpath(tcp, tcp->u_arg[0]);
1442 tprintf(", ");
1443 } else {
1444 printoldstat(tcp, tcp->u_arg[1]);
1445 }
1446 return 0;
1447}
Roland McGrath79db8af2003-06-27 21:20:09 +00001448#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001449
1450
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001451#if defined(SVR4) || defined(LINUXSPARC)
1452
1453int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001454sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001455{
1456 if (entering(tcp)) {
1457 tprintf("%ld, ", tcp->u_arg[0]);
1458 printpath(tcp, tcp->u_arg[1]);
1459 tprintf(", ");
1460 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001461#ifdef _STAT64_VER
1462 if (tcp->u_arg[0] == _STAT64_VER)
1463 printstat64 (tcp, tcp->u_arg[2]);
1464 else
1465#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001466 printstat(tcp, tcp->u_arg[2]);
1467 }
1468 return 0;
1469}
1470
1471int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001472sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001473{
1474 if (entering(tcp))
1475 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1476 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001477#ifdef _STAT64_VER
1478 if (tcp->u_arg[0] == _STAT64_VER)
1479 printstat64 (tcp, tcp->u_arg[2]);
1480 else
1481#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001482 printstat(tcp, tcp->u_arg[2]);
1483 }
1484 return 0;
1485}
1486
1487int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001488sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001489{
1490 if (entering(tcp)) {
1491 tprintf("%ld, ", tcp->u_arg[0]);
1492 printpath(tcp, tcp->u_arg[1]);
1493 tprintf(", ");
1494 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001495#ifdef _STAT64_VER
1496 if (tcp->u_arg[0] == _STAT64_VER)
1497 printstat64 (tcp, tcp->u_arg[2]);
1498 else
1499#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001500 printstat(tcp, tcp->u_arg[2]);
1501 }
1502 return 0;
1503}
1504
1505int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001506sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001507{
1508 int mode = tcp->u_arg[2];
1509
1510 if (entering(tcp)) {
1511 tprintf("%ld, ", tcp->u_arg[0]);
1512 printpath(tcp, tcp->u_arg[1]);
1513 tprintf(", %s", sprintmode(mode));
1514 switch (mode & S_IFMT) {
1515 case S_IFCHR: case S_IFBLK:
1516#ifdef LINUXSPARC
1517 tprintf(", makedev(%lu, %lu)",
1518 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1519 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001520#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001521 tprintf(", makedev(%lu, %lu)",
1522 (unsigned long) major(tcp->u_arg[3]),
1523 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001524#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001525 break;
1526 default:
1527 break;
1528 }
1529 }
1530 return 0;
1531}
1532
Wichert Akkerman8829a551999-06-11 13:18:40 +00001533#ifdef HAVE_SYS_ACL_H
1534
1535#include <sys/acl.h>
1536
Roland McGratha4d48532005-06-08 20:45:28 +00001537static const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001538#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001539 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001540#endif
1541#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001542 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001543#endif
1544#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001545 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001546#endif
1547#ifdef ACL_GET
1548 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001549#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001550#ifdef ACL_SET
1551 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001552#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001553#ifdef ACL_CNT
1554 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001555#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001556 { 0, NULL },
1557};
1558
1559int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001560sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001561{
1562 if (entering(tcp)) {
1563 printpath(tcp, tcp->u_arg[0]);
1564 tprintf(", ");
1565 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1566 tprintf(", %ld", tcp->u_arg[2]);
1567 /*
1568 * FIXME - dump out the list of aclent_t's pointed to
1569 * by "tcp->u_arg[3]" if it's not NULL.
1570 */
1571 if (tcp->u_arg[3])
1572 tprintf(", %#lx", tcp->u_arg[3]);
1573 else
1574 tprintf(", NULL");
1575 }
1576 return 0;
1577}
1578
1579
1580int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001581sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001582{
1583 if (entering(tcp)) {
1584 tprintf("%ld, ", tcp->u_arg[0]);
1585 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1586 tprintf(", %ld", tcp->u_arg[2]);
1587 /*
1588 * FIXME - dump out the list of aclent_t's pointed to
1589 * by "tcp->u_arg[3]" if it's not NULL.
1590 */
1591 if (tcp->u_arg[3])
1592 tprintf(", %#lx", tcp->u_arg[3]);
1593 else
1594 tprintf(", NULL");
1595 }
1596 return 0;
1597}
1598
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001599
Roland McGratha4d48532005-06-08 20:45:28 +00001600static const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001601#ifdef IPC_SHM
1602 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001603#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001604#ifdef IPC_SEM
1605 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001606#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001607#ifdef IPC_MSG
1608 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001609#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001610 { 0, NULL },
1611};
1612
1613
1614int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001615sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001616{
1617 if (entering(tcp)) {
1618 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1619 tprintf(", %#lx, ", tcp->u_arg[1]);
1620 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1621 tprintf(", %ld", tcp->u_arg[3]);
1622 /*
1623 * FIXME - dump out the list of aclent_t's pointed to
1624 * by "tcp->u_arg[4]" if it's not NULL.
1625 */
1626 if (tcp->u_arg[4])
1627 tprintf(", %#lx", tcp->u_arg[4]);
1628 else
1629 tprintf(", NULL");
1630 }
1631 return 0;
1632}
1633
Wichert Akkerman8829a551999-06-11 13:18:40 +00001634#endif /* HAVE_SYS_ACL_H */
1635
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001636#endif /* SVR4 || LINUXSPARC */
1637
Michal Ludvig53b320f2002-09-23 13:30:09 +00001638#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001639
Roland McGrathd9f816f2004-09-04 03:39:20 +00001640static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001641 { 0x73757245, "CODA_SUPER_MAGIC" },
1642 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1643 { 0x1373, "DEVFS_SUPER_MAGIC" },
1644 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1645 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001646 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1647 { 0xef53, "EXT2_SUPER_MAGIC" },
1648 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001649 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001650 { 0x9660, "ISOFS_SUPER_MAGIC" },
1651 { 0x137f, "MINIX_SUPER_MAGIC" },
1652 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001653 { 0x2468, "MINIX2_SUPER_MAGIC" },
1654 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001655 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001656 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001657 { 0x6969, "NFS_SUPER_MAGIC" },
1658 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001659 { 0x002f, "QNX4_SUPER_MAGIC" },
1660 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1661 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1662 { 0x517b, "SMB_SUPER_MAGIC" },
1663 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1664 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1665 { 0x00011954, "UFS_MAGIC" },
1666 { 0x54190100, "UFS_CIGAM" },
1667 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001668 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001669 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001670 { 0, NULL },
1671};
1672
Michal Ludvig53b320f2002-09-23 13:30:09 +00001673#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001674
1675#ifndef SVR4
1676
Roland McGrathf9c49b22004-10-06 22:11:54 +00001677static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001678sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001679{
1680 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001681#ifdef LINUX
Roland McGrathf9c49b22004-10-06 22:11:54 +00001682 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001683
1684 s = xlookup(fsmagic, magic);
1685 if (s) {
1686 sprintf(buf, "\"%s\"", s);
1687 return buf;
1688 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001689#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001690 sprintf(buf, "%#x", magic);
1691 return buf;
1692}
1693
1694static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001695printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001696{
1697 struct statfs statbuf;
1698
1699 if (syserror(tcp) || !verbose(tcp)) {
1700 tprintf("%#lx", addr);
1701 return;
1702 }
1703 if (umove(tcp, addr, &statbuf) < 0) {
1704 tprintf("{...}");
1705 return;
1706 }
1707#ifdef ALPHA
1708
1709 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1710 sprintfstype(statbuf.f_type),
1711 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001712 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1713 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1714 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1715 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001716#else /* !ALPHA */
1717 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1718 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001719 (unsigned long)statbuf.f_bsize,
1720 (unsigned long)statbuf.f_blocks,
1721 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001722 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1723 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001724 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001725 (unsigned long)statbuf.f_ffree,
1726 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001727#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001728 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001729#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001730#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001731#ifdef _STATFS_F_FRSIZE
1732 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1733#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001734 tprintf("}");
1735}
1736
1737int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001738sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001739{
1740 if (entering(tcp)) {
1741 printpath(tcp, tcp->u_arg[0]);
1742 tprintf(", ");
1743 } else {
1744 printstatfs(tcp, tcp->u_arg[1]);
1745 }
1746 return 0;
1747}
1748
1749int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001750sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001751{
1752 if (entering(tcp)) {
1753 tprintf("%lu, ", tcp->u_arg[0]);
1754 } else {
1755 printstatfs(tcp, tcp->u_arg[1]);
1756 }
1757 return 0;
1758}
1759
Bernhard Reutner-Fischer9906e6d2009-10-14 16:33:58 +02001760#if defined LINUX && defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001761static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001762printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001763{
1764 struct statfs64 statbuf;
1765
1766 if (syserror(tcp) || !verbose(tcp)) {
1767 tprintf("%#lx", addr);
1768 return;
1769 }
1770 if (umove(tcp, addr, &statbuf) < 0) {
1771 tprintf("{...}");
1772 return;
1773 }
Roland McGrath08738432005-06-03 02:40:39 +00001774 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001775 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001776 (unsigned long long)statbuf.f_bsize,
1777 (unsigned long long)statbuf.f_blocks,
1778 (unsigned long long)statbuf.f_bfree);
1779 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1780 (unsigned long long)statbuf.f_bavail,
1781 (unsigned long long)statbuf.f_files,
1782 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001783 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1784 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001785#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001786 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001787#endif
1788 tprintf("}");
1789}
1790
1791int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001792sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001793{
1794 if (entering(tcp)) {
1795 printpath(tcp, tcp->u_arg[0]);
1796 tprintf(", %lu, ", tcp->u_arg[1]);
1797 } else {
1798 if (tcp->u_arg[1] == sizeof (struct statfs64))
1799 printstatfs64(tcp, tcp->u_arg[2]);
1800 else
1801 tprintf("{???}");
1802 }
1803 return 0;
1804}
1805
1806int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001807sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001808{
1809 if (entering(tcp)) {
1810 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1811 } else {
1812 if (tcp->u_arg[1] == sizeof (struct statfs64))
1813 printstatfs64(tcp, tcp->u_arg[2]);
1814 else
1815 tprintf("{???}");
1816 }
1817 return 0;
1818}
1819#endif
1820
Michal Ludvig53b320f2002-09-23 13:30:09 +00001821#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001822
1823int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001824osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001825{
1826 if (entering(tcp)) {
1827 printpath(tcp, tcp->u_arg[0]);
1828 tprintf(", ");
1829 } else {
1830 printstatfs(tcp, tcp->u_arg[1]);
1831 tprintf(", %lu", tcp->u_arg[2]);
1832 }
1833 return 0;
1834}
1835
1836int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001837osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001838{
1839 if (entering(tcp)) {
1840 tprintf("%lu, ", tcp->u_arg[0]);
1841 } else {
1842 printstatfs(tcp, tcp->u_arg[1]);
1843 tprintf(", %lu", tcp->u_arg[2]);
1844 }
1845 return 0;
1846}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001847#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001848
1849#endif /* !SVR4 */
1850
1851#ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001852int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001853sys_ustat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001854{
1855 struct ustat statbuf;
1856
1857 if (entering(tcp)) {
1858 tprintf("makedev(%lu, %lu), ",
1859 (long) major(tcp->u_arg[0]),
1860 (long) minor(tcp->u_arg[0]));
1861 }
1862 else {
1863 if (syserror(tcp) || !verbose(tcp))
1864 tprintf("%#lx", tcp->u_arg[1]);
1865 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1866 tprintf("{...}");
1867 else {
1868 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1869 statbuf.f_tfree, statbuf.f_tinode);
1870 tprintf("f_fname=\"%.*s\", ",
1871 (int) sizeof(statbuf.f_fname),
1872 statbuf.f_fname);
1873 tprintf("f_fpack=\"%.*s\"}",
1874 (int) sizeof(statbuf.f_fpack),
1875 statbuf.f_fpack);
1876 }
1877 }
1878 return 0;
1879}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001880#endif /* SUNOS4 */
1881
Wichert Akkermanc7926982000-04-10 22:22:31 +00001882int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001883sys_pivotroot(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +00001884{
1885 if (entering(tcp)) {
1886 printpath(tcp, tcp->u_arg[0]);
1887 tprintf(", ");
1888 printpath(tcp, tcp->u_arg[1]);
1889 }
1890 return 0;
1891}
1892
1893
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001894/* directory */
1895int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001896sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001897{
1898 if (entering(tcp)) {
1899 printpath(tcp, tcp->u_arg[0]);
1900 }
1901 return 0;
1902}
1903
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001904static int
1905decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001906{
1907 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001908 printpath(tcp, tcp->u_arg[offset]);
1909 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001910 }
1911 return 0;
1912}
1913
1914int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001915sys_mkdir(struct tcb *tcp)
1916{
1917 return decode_mkdir(tcp, 0);
1918}
1919
1920#ifdef LINUX
1921int
1922sys_mkdirat(struct tcb *tcp)
1923{
1924 if (entering(tcp))
1925 print_dirfd(tcp->u_arg[0]);
1926 return decode_mkdir(tcp, 1);
1927}
1928#endif
1929
1930int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001931sys_rmdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001932{
1933 if (entering(tcp)) {
1934 printpath(tcp, tcp->u_arg[0]);
1935 }
1936 return 0;
1937}
1938
1939int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001940sys_fchdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001941{
1942 if (entering(tcp)) {
1943 tprintf("%ld", tcp->u_arg[0]);
1944 }
1945 return 0;
1946}
1947
1948int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001949sys_chroot(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001950{
1951 if (entering(tcp)) {
1952 printpath(tcp, tcp->u_arg[0]);
1953 }
1954 return 0;
1955}
1956
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001957#if defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001958int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001959sys_fchroot(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001960{
1961 if (entering(tcp)) {
1962 tprintf("%ld", tcp->u_arg[0]);
1963 }
1964 return 0;
1965}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001966#endif /* SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001967
1968int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001969sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001970{
1971 if (entering(tcp)) {
1972 printpath(tcp, tcp->u_arg[0]);
1973 tprintf(", ");
1974 printpath(tcp, tcp->u_arg[1]);
1975 }
1976 return 0;
1977}
1978
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001979#ifdef LINUX
1980int
1981sys_linkat(struct tcb *tcp)
1982{
1983 if (entering(tcp)) {
1984 print_dirfd(tcp->u_arg[0]);
1985 printpath(tcp, tcp->u_arg[1]);
1986 tprintf(", ");
1987 print_dirfd(tcp->u_arg[2]);
1988 printpath(tcp, tcp->u_arg[3]);
1989 tprintf(", %ld", tcp->u_arg[4]);
1990 }
1991 return 0;
1992}
1993#endif
1994
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001995int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001996sys_unlink(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001997{
1998 if (entering(tcp)) {
1999 printpath(tcp, tcp->u_arg[0]);
2000 }
2001 return 0;
2002}
2003
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002004#ifdef LINUX
2005static const struct xlat unlinkatflags[] = {
2006#ifndef AT_REMOVEDIR
2007# define AT_REMOVEDIR 0x200
2008#endif
2009 { AT_REMOVEDIR, "AT_REMOVEDIR" },
2010 { 0, NULL },
2011};
2012
2013int
2014sys_unlinkat(struct tcb *tcp)
2015{
2016 if (entering(tcp)) {
2017 print_dirfd(tcp->u_arg[0]);
2018 printpath(tcp, tcp->u_arg[1]);
2019 tprintf(", ");
2020 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
2021 }
2022 return 0;
2023}
2024#endif
2025
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002026int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002027sys_symlink(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002028{
2029 if (entering(tcp)) {
2030 printpath(tcp, tcp->u_arg[0]);
2031 tprintf(", ");
2032 printpath(tcp, tcp->u_arg[1]);
2033 }
2034 return 0;
2035}
2036
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002037#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002038int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002039sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002040{
2041 if (entering(tcp)) {
2042 printpath(tcp, tcp->u_arg[0]);
2043 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002044 print_dirfd(tcp->u_arg[1]);
2045 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002046 }
2047 return 0;
2048}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002049#endif
2050
2051static int
2052decode_readlink(struct tcb *tcp, int offset)
2053{
2054 if (entering(tcp)) {
2055 printpath(tcp, tcp->u_arg[offset]);
2056 tprintf(", ");
2057 } else {
2058 if (syserror(tcp))
2059 tprintf("%#lx", tcp->u_arg[offset + 1]);
2060 else
2061 printpathn(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
2062 tprintf(", %lu", tcp->u_arg[offset + 2]);
2063 }
2064 return 0;
2065}
2066
2067int
2068sys_readlink(struct tcb *tcp)
2069{
2070 return decode_readlink(tcp, 0);
2071}
2072
2073#ifdef LINUX
2074int
2075sys_readlinkat(struct tcb *tcp)
2076{
2077 if (entering(tcp))
2078 print_dirfd(tcp->u_arg[0]);
2079 return decode_readlink(tcp, 1);
2080}
2081#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002082
2083int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002084sys_rename(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002085{
2086 if (entering(tcp)) {
2087 printpath(tcp, tcp->u_arg[0]);
2088 tprintf(", ");
2089 printpath(tcp, tcp->u_arg[1]);
2090 }
2091 return 0;
2092}
2093
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002094#ifdef LINUX
2095int
2096sys_renameat(struct tcb *tcp)
2097{
2098 if (entering(tcp)) {
2099 print_dirfd(tcp->u_arg[0]);
2100 printpath(tcp, tcp->u_arg[1]);
2101 tprintf(", ");
2102 print_dirfd(tcp->u_arg[2]);
2103 printpath(tcp, tcp->u_arg[3]);
2104 }
2105 return 0;
2106}
2107#endif
2108
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002109int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002110sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002111{
2112 if (entering(tcp)) {
2113 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002114 printuid(", ", tcp->u_arg[1]);
2115 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002116 }
2117 return 0;
2118}
2119
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002120#ifdef LINUX
2121int
2122sys_fchownat(struct tcb *tcp)
2123{
2124 if (entering(tcp)) {
2125 print_dirfd(tcp->u_arg[0]);
2126 printpath(tcp, tcp->u_arg[1]);
2127 printuid(", ", tcp->u_arg[2]);
2128 printuid(", ", tcp->u_arg[3]);
2129 tprintf(", ");
2130 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
2131 }
2132 return 0;
2133}
2134#endif
2135
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002136int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002137sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002138{
2139 if (entering(tcp)) {
Roland McGrath6bc12202003-11-13 22:32:27 +00002140 tprintf("%ld", tcp->u_arg[0]);
2141 printuid(", ", tcp->u_arg[1]);
2142 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002143 }
2144 return 0;
2145}
2146
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002147static int
2148decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002149{
2150 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002151 printpath(tcp, tcp->u_arg[offset]);
2152 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002153 }
2154 return 0;
2155}
2156
2157int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002158sys_chmod(struct tcb *tcp)
2159{
2160 return decode_chmod(tcp, 0);
2161}
2162
2163#ifdef LINUX
2164int
2165sys_fchmodat(struct tcb *tcp)
2166{
2167 if (entering(tcp))
2168 print_dirfd(tcp->u_arg[0]);
2169 return decode_chmod(tcp, 1);
2170}
2171#endif
2172
2173int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002174sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002175{
2176 if (entering(tcp)) {
2177 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
2178 }
2179 return 0;
2180}
2181
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002182#ifdef ALPHA
2183int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002184sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002185{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002186 if (entering(tcp)) {
2187 printpath(tcp, tcp->u_arg[0]);
2188 tprintf(", ");
2189 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2190 }
2191 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002192}
2193#endif
2194
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002195static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002196decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002197{
2198 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002199 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002200 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002201 if (tcp->u_arg[offset + 1] == 0)
2202 tprintf("NULL");
2203 else {
2204 tprintf("{");
2205 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2206 BITNESS_CURRENT, special);
2207 tprintf(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002208 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Roland McGrath6afc5652007-07-24 01:57:11 +00002209 + sizeof (struct timeval),
2210 BITNESS_CURRENT, special);
2211 tprintf("}");
2212 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002213 }
2214 return 0;
2215}
2216
2217int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002218sys_utimes(struct tcb *tcp)
2219{
Roland McGrath6afc5652007-07-24 01:57:11 +00002220 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002221}
2222
2223#ifdef LINUX
2224int
2225sys_futimesat(struct tcb *tcp)
2226{
2227 if (entering(tcp))
2228 print_dirfd(tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002229 return decode_utimes(tcp, 1, 0);
2230}
2231
2232int
2233sys_utimensat(struct tcb *tcp)
2234{
2235 if (entering(tcp)) {
2236 print_dirfd(tcp->u_arg[0]);
2237 decode_utimes(tcp, 1, 1);
2238 tprintf(", ");
2239 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2240 }
2241 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002242}
2243#endif
2244
2245int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002246sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002247{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002248 union {
2249 long utl[2];
2250 int uti[2];
2251 } u;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002252
2253 if (entering(tcp)) {
2254 printpath(tcp, tcp->u_arg[0]);
2255 tprintf(", ");
2256 if (!tcp->u_arg[1])
2257 tprintf("NULL");
2258 else if (!verbose(tcp))
2259 tprintf("%#lx", tcp->u_arg[1]);
Roland McGrath7e9817c2007-07-05 20:31:58 +00002260 else if (umoven(tcp, tcp->u_arg[1],
2261 2 * personality_wordsize[current_personality],
2262 (char *) &u) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002263 tprintf("[?, ?]");
Roland McGrath7e9817c2007-07-05 20:31:58 +00002264 else if (personality_wordsize[current_personality]
2265 == sizeof u.utl[0]) {
2266 tprintf("[%s,", sprinttime(u.utl[0]));
2267 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002268 }
Roland McGrath7e9817c2007-07-05 20:31:58 +00002269 else if (personality_wordsize[current_personality]
2270 == sizeof u.uti[0]) {
2271 tprintf("[%s,", sprinttime(u.uti[0]));
2272 tprintf(" %s]", sprinttime(u.uti[1]));
2273 }
2274 else
2275 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002276 }
2277 return 0;
2278}
2279
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002280static int
2281decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002282{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002283 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002284
2285 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002286 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002287 tprintf(", %s", sprintmode(mode));
2288 switch (mode & S_IFMT) {
2289 case S_IFCHR: case S_IFBLK:
2290#ifdef LINUXSPARC
2291 if (current_personality == 1)
2292 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002293 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2294 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002295 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002296#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002297 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002298 (unsigned long) major(tcp->u_arg[offset + 2]),
2299 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002300 break;
2301 default:
2302 break;
2303 }
2304 }
2305 return 0;
2306}
2307
2308int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002309sys_mknod(struct tcb *tcp)
2310{
2311 return decode_mknod(tcp, 0);
2312}
2313
2314#ifdef LINUX
2315int
2316sys_mknodat(struct tcb *tcp)
2317{
2318 if (entering(tcp))
2319 print_dirfd(tcp->u_arg[0]);
2320 return decode_mknod(tcp, 1);
2321}
2322#endif
2323
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002324#ifdef FREEBSD
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002325int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002326sys_mkfifo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002327{
2328 if (entering(tcp)) {
2329 printpath(tcp, tcp->u_arg[0]);
2330 tprintf(", %#lo", tcp->u_arg[1]);
2331 }
2332 return 0;
2333}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002334#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002335
2336int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002337sys_fsync(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002338{
2339 if (entering(tcp)) {
2340 tprintf("%ld", tcp->u_arg[0]);
2341 }
2342 return 0;
2343}
2344
Michal Ludvig53b320f2002-09-23 13:30:09 +00002345#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002346
2347static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002348printdir(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002349{
2350 struct dirent d;
2351
2352 if (!verbose(tcp)) {
2353 tprintf("%#lx", addr);
2354 return;
2355 }
2356 if (umove(tcp, addr, &d) < 0) {
2357 tprintf("{...}");
2358 return;
2359 }
2360 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002361 tprintf("d_name=");
2362 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2363 tprintf("}");
2364}
2365
2366int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002367sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002368{
2369 if (entering(tcp)) {
2370 tprintf("%lu, ", tcp->u_arg[0]);
2371 } else {
2372 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2373 tprintf("%#lx", tcp->u_arg[1]);
2374 else
2375 printdir(tcp, tcp->u_arg[1]);
2376 /* Not much point in printing this out, it is always 1. */
2377 if (tcp->u_arg[2] != 1)
2378 tprintf(", %lu", tcp->u_arg[2]);
2379 }
2380 return 0;
2381}
2382
Michal Ludvig53b320f2002-09-23 13:30:09 +00002383#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002384
Roland McGrath40542842004-01-13 09:47:49 +00002385#if defined FREEBSD || defined LINUX
Roland McGratha4d48532005-06-08 20:45:28 +00002386static const struct xlat direnttypes[] = {
Roland McGrath40542842004-01-13 09:47:49 +00002387 { DT_UNKNOWN, "DT_UNKNOWN" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002388 { DT_FIFO, "DT_FIFO" },
2389 { DT_CHR, "DT_CHR" },
2390 { DT_DIR, "DT_DIR" },
2391 { DT_BLK, "DT_BLK" },
2392 { DT_REG, "DT_REG" },
2393 { DT_LNK, "DT_LNK" },
2394 { DT_SOCK, "DT_SOCK" },
2395 { DT_WHT, "DT_WHT" },
2396 { 0, NULL },
2397};
2398
2399#endif
2400
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002401int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002402sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002403{
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 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002415 len = tcp->u_rval;
Mike Frysinger229738c2009-10-07 20:41:56 -04002416 buf = len ? malloc(len) : NULL;
2417 if (len && !buf) {
Roland McGrath46100d02005-06-01 18:55:42 +00002418 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2419 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002420 return 0;
2421 }
2422 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002423 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002424 free(buf);
2425 return 0;
2426 }
2427 if (!abbrev(tcp))
2428 tprintf("{");
2429 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002430 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002431#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002432 if (!abbrev(tcp)) {
2433 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2434 i ? " " : "", d->d_ino, d->d_off);
2435 tprintf("d_reclen=%u, d_name=\"%s\"}",
2436 d->d_reclen, d->d_name);
2437 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002438#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002439#ifdef SVR4
2440 if (!abbrev(tcp)) {
2441 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002442 i ? " " : "",
2443 (unsigned long) d->d_ino,
2444 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002445 tprintf("d_reclen=%u, d_name=\"%s\"}",
2446 d->d_reclen, d->d_name);
2447 }
2448#endif /* SVR4 */
2449#ifdef SUNOS4
2450 if (!abbrev(tcp)) {
2451 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2452 i ? " " : "", d->d_off, d->d_fileno,
2453 d->d_reclen);
2454 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2455 d->d_namlen, d->d_namlen, d->d_name);
2456 }
2457#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002458#ifdef FREEBSD
2459 if (!abbrev(tcp)) {
2460 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2461 i ? " " : "", d->d_fileno, d->d_reclen);
2462 printxval(direnttypes, d->d_type, "DT_???");
2463 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2464 d->d_namlen, d->d_namlen, d->d_name);
2465 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002466#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002467 if (!d->d_reclen) {
2468 tprintf("/* d_reclen == 0, problem here */");
2469 break;
2470 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002471 i += d->d_reclen;
2472 dents++;
2473 }
2474 if (!abbrev(tcp))
2475 tprintf("}");
2476 else
2477 tprintf("/* %u entries */", dents);
2478 tprintf(", %lu", tcp->u_arg[2]);
2479 free(buf);
2480 return 0;
2481}
2482
John Hughesbdf48f52001-03-06 15:08:09 +00002483
2484#if _LFS64_LARGEFILE
2485int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002486sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002487{
2488 int i, len, dents = 0;
2489 char *buf;
2490
2491 if (entering(tcp)) {
2492 tprintf("%lu, ", tcp->u_arg[0]);
2493 return 0;
2494 }
2495 if (syserror(tcp) || !verbose(tcp)) {
2496 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2497 return 0;
2498 }
2499 len = tcp->u_rval;
Mike Frysinger229738c2009-10-07 20:41:56 -04002500 buf = len ? malloc(len) : NULL;
2501 if (len && !buf) {
Roland McGrath46100d02005-06-01 18:55:42 +00002502 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2503 fprintf(stderr, "out of memory\n");
John Hughesbdf48f52001-03-06 15:08:09 +00002504 return 0;
2505 }
2506 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002507 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002508 free(buf);
2509 return 0;
2510 }
2511 if (!abbrev(tcp))
2512 tprintf("{");
2513 for (i = 0; i < len;) {
2514 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002515#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002516 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002517 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002518 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002519 d->d_ino,
2520 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002521#ifdef LINUX
2522 tprintf("d_type=");
2523 printxval(direnttypes, d->d_type, "DT_???");
2524 tprintf(", ");
2525#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002526 tprintf("d_reclen=%u, d_name=\"%s\"}",
2527 d->d_reclen, d->d_name);
2528 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002529#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002530#ifdef SUNOS4
2531 if (!abbrev(tcp)) {
2532 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2533 i ? " " : "", d->d_off, d->d_fileno,
2534 d->d_reclen);
2535 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2536 d->d_namlen, d->d_namlen, d->d_name);
2537 }
2538#endif /* SUNOS4 */
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002539 if (!d->d_reclen) {
2540 tprintf("/* d_reclen == 0, problem here */");
2541 break;
2542 }
John Hughesbdf48f52001-03-06 15:08:09 +00002543 i += d->d_reclen;
2544 dents++;
2545 }
2546 if (!abbrev(tcp))
2547 tprintf("}");
2548 else
2549 tprintf("/* %u entries */", dents);
2550 tprintf(", %lu", tcp->u_arg[2]);
2551 free(buf);
2552 return 0;
2553}
2554#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002555
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002556#ifdef FREEBSD
2557int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002558sys_getdirentries(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002559{
2560 int i, len, dents = 0;
2561 long basep;
2562 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002563
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002564 if (entering(tcp)) {
2565 tprintf("%lu, ", tcp->u_arg[0]);
2566 return 0;
2567 }
2568 if (syserror(tcp) || !verbose(tcp)) {
2569 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2570 return 0;
2571 }
2572 len = tcp->u_rval;
2573 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002574 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2575 fprintf(stderr, "out of memory\n");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002576 return 0;
2577 }
2578 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002579 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002580 free(buf);
2581 return 0;
2582 }
2583 if (!abbrev(tcp))
2584 tprintf("{");
2585 for (i = 0; i < len;) {
2586 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2587 if (!abbrev(tcp)) {
2588 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2589 i ? " " : "", d->d_fileno, d->d_reclen);
2590 printxval(direnttypes, d->d_type, "DT_???");
2591 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2592 d->d_namlen, d->d_namlen, d->d_name);
2593 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002594 if (!d->d_reclen) {
2595 tprintf("/* d_reclen == 0, problem here */");
2596 break;
2597 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002598 i += d->d_reclen;
2599 dents++;
2600 }
2601 if (!abbrev(tcp))
2602 tprintf("}");
2603 else
2604 tprintf("/* %u entries */", dents);
2605 free(buf);
2606 tprintf(", %lu", tcp->u_arg[2]);
2607 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2608 tprintf(", %#lx", tcp->u_arg[3]);
2609 else
2610 tprintf(", [%lu]", basep);
2611 return 0;
2612}
2613#endif
2614
Michal Ludvig53b320f2002-09-23 13:30:09 +00002615#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002616int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002617sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002618{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002619 if (exiting(tcp)) {
2620 if (syserror(tcp))
2621 tprintf("%#lx", tcp->u_arg[0]);
2622 else
2623 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2624 tprintf(", %lu", tcp->u_arg[1]);
2625 }
2626 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002627}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002628#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002629
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002630#ifdef FREEBSD
2631int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002632sys___getcwd(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002633{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002634 if (exiting(tcp)) {
2635 if (syserror(tcp))
2636 tprintf("%#lx", tcp->u_arg[0]);
2637 else
2638 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2639 tprintf(", %lu", tcp->u_arg[1]);
2640 }
2641 return 0;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002642}
2643#endif
2644
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002645#ifdef HAVE_SYS_ASYNCH_H
2646
2647int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002648sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002649{
2650 struct aio_result_t res;
2651
2652 if (entering(tcp)) {
2653 tprintf("%lu, ", tcp->u_arg[0]);
2654 } else {
2655 if (syserror(tcp))
2656 tprintf("%#lx", tcp->u_arg[1]);
2657 else
2658 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2659 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2660 printxval(whence, tcp->u_arg[4], "L_???");
2661 if (syserror(tcp) || tcp->u_arg[5] == 0
2662 || umove(tcp, tcp->u_arg[5], &res) < 0)
2663 tprintf(", %#lx", tcp->u_arg[5]);
2664 else
2665 tprintf(", {aio_return %d aio_errno %d}",
2666 res.aio_return, res.aio_errno);
2667 }
2668 return 0;
2669}
2670
2671int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002672sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002673{
2674 struct aio_result_t res;
2675
2676 if (entering(tcp)) {
2677 tprintf("%lu, ", tcp->u_arg[0]);
2678 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2679 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2680 printxval(whence, tcp->u_arg[4], "L_???");
2681 }
2682 else {
2683 if (tcp->u_arg[5] == 0)
2684 tprintf(", NULL");
2685 else if (syserror(tcp)
2686 || umove(tcp, tcp->u_arg[5], &res) < 0)
2687 tprintf(", %#lx", tcp->u_arg[5]);
2688 else
2689 tprintf(", {aio_return %d aio_errno %d}",
2690 res.aio_return, res.aio_errno);
2691 }
2692 return 0;
2693}
2694
2695int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002696sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002697{
2698 if (entering(tcp))
2699 printtv(tcp, tcp->u_arg[0]);
2700 return 0;
2701}
2702
2703int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002704sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002705{
2706 struct aio_result_t res;
2707
2708 if (exiting(tcp)) {
2709 if (tcp->u_arg[0] == 0)
2710 tprintf("NULL");
2711 else if (syserror(tcp)
2712 || umove(tcp, tcp->u_arg[0], &res) < 0)
2713 tprintf("%#lx", tcp->u_arg[0]);
2714 else
2715 tprintf("{aio_return %d aio_errno %d}",
2716 res.aio_return, res.aio_errno);
2717 }
2718 return 0;
2719}
2720
2721#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002722
Roland McGratha4d48532005-06-08 20:45:28 +00002723static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002724#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002725 { XATTR_CREATE, "XATTR_CREATE" },
2726 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002727#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002728 { 0, NULL }
2729};
2730
Roland McGrath3292e222004-08-31 06:30:48 +00002731static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002732print_xattr_val(struct tcb *tcp, int failed,
2733 unsigned long arg,
2734 unsigned long insize,
2735 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002736{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002737 if (!failed) {
2738 unsigned long capacity = 4 * size + 1;
2739 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2740 if (buf == NULL || /* probably a bogus size argument */
2741 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2742 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002743 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002744 else {
2745 unsigned char *out = buf;
2746 unsigned char *in = &buf[3 * size];
2747 size_t i;
2748 for (i = 0; i < size; ++i) {
2749 if (isprint(in[i]))
2750 *out++ = in[i];
2751 else {
2752#define tohex(n) "0123456789abcdef"[n]
2753 *out++ = '\\';
2754 *out++ = 'x';
2755 *out++ = tohex(in[i] / 16);
2756 *out++ = tohex(in[i] % 16);
2757 }
2758 }
2759 /* Don't print terminating NUL if there is one. */
2760 if (i > 0 && in[i - 1] == '\0')
2761 out -= 4;
2762 *out = '\0';
2763 tprintf(", \"%s\", %ld", buf, insize);
2764 }
2765 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002766 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002767 if (failed)
2768 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002769}
2770
Roland McGrath186c5ac2002-12-15 23:58:23 +00002771int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002772sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002773{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002774 if (entering(tcp)) {
2775 printpath(tcp, tcp->u_arg[0]);
2776 tprintf(", ");
2777 printstr(tcp, tcp->u_arg[1], -1);
2778 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2779 tprintf(", ");
2780 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2781 }
2782 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002783}
2784
2785int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002786sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002787{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002788 if (entering(tcp)) {
2789 tprintf("%ld, ", tcp->u_arg[0]);
2790 printstr(tcp, tcp->u_arg[1], -1);
2791 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2792 tprintf(", ");
2793 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2794 }
2795 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002796}
2797
2798int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002799sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002800{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002801 if (entering(tcp)) {
2802 printpath(tcp, tcp->u_arg[0]);
2803 tprintf(", ");
2804 printstr(tcp, tcp->u_arg[1], -1);
2805 } else {
2806 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2807 tcp->u_rval);
2808 }
2809 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002810}
2811
2812int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002813sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002814{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002815 if (entering(tcp)) {
2816 tprintf("%ld, ", tcp->u_arg[0]);
2817 printstr(tcp, tcp->u_arg[1], -1);
2818 } else {
2819 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2820 tcp->u_rval);
2821 }
2822 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002823}
2824
2825int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002826sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002827{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002828 if (entering(tcp)) {
2829 printpath(tcp, tcp->u_arg[0]);
2830 } else {
2831 /* XXX Print value in format */
2832 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2833 }
2834 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002835}
2836
2837int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002838sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002839{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002840 if (entering(tcp)) {
2841 tprintf("%ld", tcp->u_arg[0]);
2842 } else {
2843 /* XXX Print value in format */
2844 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2845 }
2846 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002847}
2848
2849int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002850sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002851{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002852 if (entering(tcp)) {
2853 printpath(tcp, tcp->u_arg[0]);
2854 tprintf(", ");
2855 printstr(tcp, tcp->u_arg[1], -1);
2856 }
2857 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002858}
2859
2860int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002861sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002862{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002863 if (entering(tcp)) {
2864 tprintf("%ld, ", tcp->u_arg[0]);
2865 printstr(tcp, tcp->u_arg[1], -1);
2866 }
2867 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002868}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002869
2870
2871static const struct xlat advise[] = {
2872 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2873 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2874 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2875 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2876 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2877 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2878 { 0, NULL }
2879};
2880
2881
Roland McGrathe27ed342004-10-20 02:24:19 +00002882#ifdef LINUX
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002883int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002884sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002885{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002886 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002887 int argn;
2888 tprintf("%ld, ", tcp->u_arg[0]);
2889 argn = printllval(tcp, "%lld", 1);
2890 tprintf(", %ld, ", tcp->u_arg[argn++]);
2891 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002892 }
2893 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002894}
2895#endif
2896
2897
2898int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002899sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002900{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002901 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002902 int argn;
2903 tprintf("%ld, ", tcp->u_arg[0]);
2904#if defined ARM || defined POWERPC
2905 argn = printllval(tcp, "%lld, ", 2);
2906#else
2907 argn = printllval(tcp, "%lld, ", 1);
2908#endif
2909 argn = printllval(tcp, "%lld, ", argn);
2910#if defined ARM || defined POWERPC
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002911 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002912#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002913 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002914#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002915 }
2916 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002917}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002918
2919#ifdef LINUX
2920static const struct xlat inotify_modes[] = {
2921 { 0x00000001, "IN_ACCESS" },
2922 { 0x00000002, "IN_MODIFY" },
2923 { 0x00000004, "IN_ATTRIB" },
2924 { 0x00000008, "IN_CLOSE_WRITE" },
2925 { 0x00000010, "IN_CLOSE_NOWRITE" },
2926 { 0x00000020, "IN_OPEN" },
2927 { 0x00000040, "IN_MOVED_FROM" },
2928 { 0x00000080, "IN_MOVED_TO" },
2929 { 0x00000100, "IN_CREATE" },
2930 { 0x00000200, "IN_DELETE" },
2931 { 0x00000400, "IN_DELETE_SELF" },
2932 { 0x00000800, "IN_MOVE_SELF" },
2933 { 0x00002000, "IN_UNMOUNT" },
2934 { 0x00004000, "IN_Q_OVERFLOW" },
2935 { 0x00008000, "IN_IGNORED" },
2936 { 0x01000000, "IN_ONLYDIR" },
2937 { 0x02000000, "IN_DONT_FOLLOW" },
2938 { 0x20000000, "IN_MASK_ADD" },
2939 { 0x40000000, "IN_ISDIR" },
2940 { 0x80000000, "IN_ONESHOT" }
2941};
2942
2943int
2944sys_inotify_add_watch(struct tcb *tcp)
2945{
2946 if (entering(tcp)) {
2947 tprintf("%ld, ", tcp->u_arg[0]);
2948 printpath(tcp, tcp->u_arg[1]);
2949 tprintf(", ");
2950 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2951 }
2952 return 0;
2953}
2954
2955int
2956sys_inotify_rm_watch(struct tcb *tcp)
2957{
2958 if (entering(tcp)) {
2959 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
2960 }
2961 return 0;
2962}
Roland McGrath96a96612008-05-20 04:56:18 +00002963
2964int
Mark Wielaardbab89402010-03-21 14:41:26 +01002965sys_inotify_init1(struct tcb *tcp)
2966{
2967 if (entering(tcp))
2968 printflags(open_mode_flags, tcp->u_arg[0], "O_???");
2969 return 0;
2970}
2971
2972int
Roland McGrath96a96612008-05-20 04:56:18 +00002973sys_fallocate(struct tcb *tcp)
2974{
2975 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002976 int argn;
Roland McGrath96a96612008-05-20 04:56:18 +00002977 tprintf("%ld, ", tcp->u_arg[0]); /* fd */
2978 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002979 argn = printllval(tcp, "%llu, ", 2); /* offset */
2980 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002981 }
2982 return 0;
2983}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002984#endif