blob: db024ef83891d3ffde0784f7e9ec13eb22fe0895 [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
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200260 { 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
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200264 { O_DIRECTORY, "O_DIRECTORY" },
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000265#endif
266#ifdef O_NOFOLLOW
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200267 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000268#endif
Roland McGrath1025c3e2005-05-09 07:40:35 +0000269#ifdef O_NOATIME
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200270 { O_NOATIME, "O_NOATIME" },
Roland McGrath1025c3e2005-05-09 07:40:35 +0000271#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#ifdef FNDELAY
276 { FNDELAY, "FNDELAY" },
277#endif
278#ifdef FAPPEND
279 { FAPPEND, "FAPPEND" },
280#endif
281#ifdef FMARK
282 { FMARK, "FMARK" },
283#endif
284#ifdef FDEFER
285 { FDEFER, "FDEFER" },
286#endif
287#ifdef FASYNC
288 { FASYNC, "FASYNC" },
289#endif
290#ifdef FSHLOCK
291 { FSHLOCK, "FSHLOCK" },
292#endif
293#ifdef FEXLOCK
294 { FEXLOCK, "FEXLOCK" },
295#endif
296#ifdef FCREAT
297 { FCREAT, "FCREAT" },
298#endif
299#ifdef FTRUNC
300 { FTRUNC, "FTRUNC" },
301#endif
302#ifdef FEXCL
303 { FEXCL, "FEXCL" },
304#endif
305#ifdef FNBIO
306 { FNBIO, "FNBIO" },
307#endif
308#ifdef FSYNC
309 { FSYNC, "FSYNC" },
310#endif
311#ifdef FNOCTTY
312 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000313#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000314#ifdef O_SHLOCK
315 { O_SHLOCK, "O_SHLOCK" },
316#endif
317#ifdef O_EXLOCK
318 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000319#endif
320 { 0, NULL },
321};
322
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000323#ifdef LINUX
324
325#ifndef AT_FDCWD
326# define AT_FDCWD -100
327#endif
328
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000329/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
330 * extension to get the right value. We do this by declaring fd as int here.
331 */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000332static void
Dmitry V. Levin31382132011-03-04 05:08:02 +0300333print_dirfd(struct tcb *tcp, int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000334{
335 if (fd == AT_FDCWD)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200336 tprints("AT_FDCWD, ");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200337 else {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300338 printfd(tcp, fd);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200339 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300340 }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000341}
342#endif
343
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000344/*
345 * low bits of the open(2) flags define access mode,
346 * other bits are real flags.
347 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000348const char *
349sprint_open_modes(mode_t flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000350{
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100351 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000352 char *p;
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100353 char sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000354 const char *str;
355 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000356
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100357 sep = ' ';
358 p = stpcpy(outstr, "flags");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000359 str = xlookup(open_access_modes, flags & 3);
360 if (str) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100361 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200362 p = stpcpy(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000363 flags &= ~3;
364 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000365 return outstr;
366 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000367 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000368
369 for (x = open_mode_flags; x->str; x++) {
370 if ((flags & x->val) == x->val) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100371 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200372 p = stpcpy(p, x->str);
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000373 flags &= ~x->val;
374 if (!flags)
375 return outstr;
376 sep = '|';
377 }
378 }
379 /* flags is still nonzero */
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100380 *p++ = sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000381 sprintf(p, "%#x", flags);
382 return outstr;
383}
384
385void
386tprint_open_modes(mode_t flags)
387{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200388 tprints(sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000389}
390
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000391static int
392decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000393{
394 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000395 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200396 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000397 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000398 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000399 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000400 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000401 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000402 }
403 }
404 return 0;
405}
406
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000407int
408sys_open(struct tcb *tcp)
409{
410 return decode_open(tcp, 0);
411}
412
413#ifdef LINUX
414int
415sys_openat(struct tcb *tcp)
416{
417 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300418 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000419 return decode_open(tcp, 1);
420}
421#endif
422
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000423#ifdef LINUXSPARC
Roland McGratha4d48532005-06-08 20:45:28 +0000424static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000425 { 0, "O_RDWR" },
426 { 1, "O_RDONLY" },
427 { 2, "O_WRONLY" },
428 { 0x80, "O_NONBLOCK" },
429 { 8, "O_APPEND" },
430 { 0x100, "O_CREAT" },
431 { 0x200, "O_TRUNC" },
432 { 0x400, "O_EXCL" },
433 { 0x800, "O_NOCTTY" },
434 { 0x10, "O_SYNC" },
435 { 0x40, "O_DSYNC" },
436 { 0x8000, "O_RSYNC" },
437 { 4, "O_NDELAY" },
438 { 0x1000, "O_PRIV" },
439 { 0, NULL },
440};
441
442int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000443solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000444{
445 if (entering(tcp)) {
446 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200447 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000448 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000449 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000450 if (tcp->u_arg[1] & 0x100) {
451 /* mode */
452 tprintf(", %#lo", tcp->u_arg[2]);
453 }
454 }
455 return 0;
456}
457
458#endif
459
460int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000461sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000462{
463 if (entering(tcp)) {
464 printpath(tcp, tcp->u_arg[0]);
465 tprintf(", %#lo", tcp->u_arg[1]);
466 }
467 return 0;
468}
469
Roland McGrathd9f816f2004-09-04 03:39:20 +0000470static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000471 { F_OK, "F_OK", },
472 { R_OK, "R_OK" },
473 { W_OK, "W_OK" },
474 { X_OK, "X_OK" },
475#ifdef EFF_ONLY_OK
476 { EFF_ONLY_OK, "EFF_ONLY_OK" },
477#endif
478#ifdef EX_OK
479 { EX_OK, "EX_OK" },
480#endif
481 { 0, NULL },
482};
483
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000484static int
485decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000486{
487 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000488 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200489 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000490 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000491 }
492 return 0;
493}
494
495int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000496sys_access(struct tcb *tcp)
497{
498 return decode_access(tcp, 0);
499}
500
501#ifdef LINUX
502int
503sys_faccessat(struct tcb *tcp)
504{
505 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300506 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000507 return decode_access(tcp, 1);
508}
509#endif
510
511int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000512sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000513{
514 if (entering(tcp)) {
515 tprintf("%#lo", tcp->u_arg[0]);
516 }
517 return RVAL_OCTAL;
518}
519
Roland McGrathd9f816f2004-09-04 03:39:20 +0000520static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000521 { SEEK_SET, "SEEK_SET" },
522 { SEEK_CUR, "SEEK_CUR" },
523 { SEEK_END, "SEEK_END" },
524 { 0, NULL },
525};
526
John Hughes70623be2001-03-08 13:59:00 +0000527#ifndef HAVE_LONG_LONG_OFF_T
Roland McGrath542c2c62008-05-20 01:11:56 +0000528#if defined (LINUX_MIPSN32)
529int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000530sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000531{
532 long long offset;
533 int _whence;
534
535 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300536 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200537 tprints(", ");
Roland McGrath542c2c62008-05-20 01:11:56 +0000538 offset = tcp->ext_arg[1];
539 _whence = tcp->u_arg[2];
540 if (_whence == SEEK_SET)
541 tprintf("%llu, ", offset);
542 else
543 tprintf("%lld, ", offset);
544 printxval(whence, _whence, "SEEK_???");
545 }
546 return RVAL_UDECIMAL;
547}
548#else /* !LINUX_MIPSN32 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000549int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000550sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000551{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000552 off_t offset;
553 int _whence;
554
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000555 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300556 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200557 tprints(", ");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000558 offset = tcp->u_arg[1];
559 _whence = tcp->u_arg[2];
560 if (_whence == SEEK_SET)
561 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000562 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000563 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000564 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000565 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000566 return RVAL_UDECIMAL;
567}
Roland McGrath542c2c62008-05-20 01:11:56 +0000568#endif /* LINUX_MIPSN32 */
John Hughes5a826b82001-03-07 13:21:24 +0000569#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000570
Michal Ludvig53b320f2002-09-23 13:30:09 +0000571#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000572int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000573sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000574{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000575 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300576 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000577 /*
578 * This one call takes explicitly two 32-bit arguments hi, lo,
579 * rather than one 64-bit argument for which LONG_LONG works
580 * appropriate for the native byte order.
581 */
582 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300583 tprintf(", %llu, ",
584 ((long long int) tcp->u_arg[1]) << 32 |
585 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000586 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300587 tprintf(", %lld, ",
588 ((long long int) tcp->u_arg[1]) << 32 |
589 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000590 }
591 else {
592 long long int off;
593 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
594 tprintf("%#lx, ", tcp->u_arg[3]);
595 else
596 tprintf("[%llu], ", off);
597 printxval(whence, tcp->u_arg[4], "SEEK_???");
598 }
599 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000600}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000601
602int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000603sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000604{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000605 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100606 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300607 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200608 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100609 argn = printllval(tcp, "%lld", 1);
610 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000611 }
612 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000613}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000614#endif
615
John Hughes70623be2001-03-08 13:59:00 +0000616#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000617int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000618sys_lseek64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +0000619{
620 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100621 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300622 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200623 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000624 if (tcp->u_arg[3] == SEEK_SET)
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100625 argn = printllval(tcp, "%llu, ", 1);
John Hughesbdf48f52001-03-06 15:08:09 +0000626 else
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100627 argn = printllval(tcp, "%lld, ", 1);
628 printxval(whence, tcp->u_arg[argn], "SEEK_???");
John Hughesbdf48f52001-03-06 15:08:09 +0000629 }
630 return RVAL_LUDECIMAL;
631}
632#endif
633
John Hughes70623be2001-03-08 13:59:00 +0000634#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000635int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000636sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000637{
638 if (entering(tcp)) {
639 printpath(tcp, tcp->u_arg[0]);
640 tprintf(", %lu", tcp->u_arg[1]);
641 }
642 return 0;
643}
John Hughes5a826b82001-03-07 13:21:24 +0000644#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000645
John Hughes70623be2001-03-08 13:59:00 +0000646#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000647int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000648sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000649{
650 if (entering(tcp)) {
651 printpath(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100652 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000653 }
654 return 0;
655}
656#endif
657
John Hughes70623be2001-03-08 13:59:00 +0000658#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000659int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000660sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000661{
662 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300663 printfd(tcp, tcp->u_arg[0]);
664 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000665 }
666 return 0;
667}
John Hughes5a826b82001-03-07 13:21:24 +0000668#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000669
John Hughes70623be2001-03-08 13:59:00 +0000670#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000671int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000672sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000673{
674 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300675 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200676 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100677 printllval(tcp, "%llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000678 }
679 return 0;
680}
681#endif
682
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000683/* several stats */
684
Roland McGrathd9f816f2004-09-04 03:39:20 +0000685static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000686 { S_IFREG, "S_IFREG" },
687 { S_IFSOCK, "S_IFSOCK" },
688 { S_IFIFO, "S_IFIFO" },
689 { S_IFLNK, "S_IFLNK" },
690 { S_IFDIR, "S_IFDIR" },
691 { S_IFBLK, "S_IFBLK" },
692 { S_IFCHR, "S_IFCHR" },
693 { 0, NULL },
694};
695
Roland McGrathf9c49b22004-10-06 22:11:54 +0000696static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000697sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000698{
699 static char buf[64];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000700 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000701
702 if ((mode & S_IFMT) == 0)
703 s = "";
704 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
705 sprintf(buf, "%#o", mode);
706 return buf;
707 }
708 sprintf(buf, "%s%s%s%s", s,
709 (mode & S_ISUID) ? "|S_ISUID" : "",
710 (mode & S_ISGID) ? "|S_ISGID" : "",
711 (mode & S_ISVTX) ? "|S_ISVTX" : "");
712 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
713 if (mode)
714 sprintf(buf + strlen(buf), "|%#o", mode);
715 s = (*buf == '|') ? buf + 1 : buf;
716 return *s ? s : "0";
717}
718
719static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000720sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000721{
722 struct tm *tmp;
723 static char buf[32];
724
725 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000726 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000727 return buf;
728 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200729 tmp = localtime(&t);
730 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000731 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
732 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
733 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
734 else
735 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
736
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000737 return buf;
738}
739
740#ifdef LINUXSPARC
741typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000742 int tv_sec;
743 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000744} timestruct_t;
745
746struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000747 unsigned st_dev;
748 int st_pad1[3]; /* network id */
749 unsigned st_ino;
750 unsigned st_mode;
751 unsigned st_nlink;
752 unsigned st_uid;
753 unsigned st_gid;
754 unsigned st_rdev;
755 int st_pad2[2];
756 int st_size;
757 int st_pad3; /* st_size, off_t expansion */
758 timestruct_t st_atime;
759 timestruct_t st_mtime;
760 timestruct_t st_ctime;
761 int st_blksize;
762 int st_blocks;
763 char st_fstype[16];
764 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000765};
766
767static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000768printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000769{
770 struct solstat statbuf;
771
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000772 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200773 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000774 return;
775 }
776 if (!abbrev(tcp)) {
777 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
778 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
779 (unsigned long) (statbuf.st_dev & 0x3ffff),
780 (unsigned long) statbuf.st_ino,
781 sprintmode(statbuf.st_mode));
782 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
783 (unsigned long) statbuf.st_nlink,
784 (unsigned long) statbuf.st_uid,
785 (unsigned long) statbuf.st_gid);
786 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
787 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
788 }
789 else
790 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
791 switch (statbuf.st_mode & S_IFMT) {
792 case S_IFCHR: case S_IFBLK:
793 tprintf("st_rdev=makedev(%lu, %lu), ",
794 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
795 (unsigned long) (statbuf.st_rdev & 0x3ffff));
796 break;
797 default:
798 tprintf("st_size=%u, ", statbuf.st_size);
799 break;
800 }
801 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000802 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
803 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
804 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000805 }
806 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200807 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000808}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000809
810#if defined (SPARC64)
811static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000812printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000813{
814 struct stat_sparc64 statbuf;
815
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000816 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200817 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000818 return;
819 }
820
821 if (!abbrev(tcp)) {
822 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
823 (unsigned long) major(statbuf.st_dev),
824 (unsigned long) minor(statbuf.st_dev),
825 (unsigned long) statbuf.st_ino,
826 sprintmode(statbuf.st_mode));
827 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
828 (unsigned long) statbuf.st_nlink,
829 (unsigned long) statbuf.st_uid,
830 (unsigned long) statbuf.st_gid);
831 tprintf("st_blksize=%lu, ",
832 (unsigned long) statbuf.st_blksize);
833 tprintf("st_blocks=%lu, ",
834 (unsigned long) statbuf.st_blocks);
835 }
836 else
837 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
838 switch (statbuf.st_mode & S_IFMT) {
839 case S_IFCHR: case S_IFBLK:
840 tprintf("st_rdev=makedev(%lu, %lu), ",
841 (unsigned long) major(statbuf.st_rdev),
842 (unsigned long) minor(statbuf.st_rdev));
843 break;
844 default:
845 tprintf("st_size=%lu, ", statbuf.st_size);
846 break;
847 }
848 if (!abbrev(tcp)) {
849 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
850 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
851 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200852 tprints("}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000853 }
854 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200855 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000856}
857#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000858#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000859
Andreas Schwabd69fa492010-07-12 21:39:57 +0200860#if defined LINUX && defined POWERPC64
861struct stat_powerpc32 {
862 unsigned int st_dev;
863 unsigned int st_ino;
864 unsigned int st_mode;
865 unsigned short st_nlink;
866 unsigned int st_uid;
867 unsigned int st_gid;
868 unsigned int st_rdev;
869 unsigned int st_size;
870 unsigned int st_blksize;
871 unsigned int st_blocks;
872 unsigned int st_atime;
873 unsigned int st_atime_nsec;
874 unsigned int st_mtime;
875 unsigned int st_mtime_nsec;
876 unsigned int st_ctime;
877 unsigned int st_ctime_nsec;
878 unsigned int __unused4;
879 unsigned int __unused5;
880};
881
882static void
883printstat_powerpc32(struct tcb *tcp, long addr)
884{
885 struct stat_powerpc32 statbuf;
886
887 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200888 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200889 return;
890 }
891
892 if (!abbrev(tcp)) {
893 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
894 major(statbuf.st_dev), minor(statbuf.st_dev),
895 statbuf.st_ino,
896 sprintmode(statbuf.st_mode));
897 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
898 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
899 tprintf("st_blksize=%u, ", statbuf.st_blksize);
900 tprintf("st_blocks=%u, ", statbuf.st_blocks);
901 }
902 else
903 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
904 switch (statbuf.st_mode & S_IFMT) {
905 case S_IFCHR: case S_IFBLK:
906 tprintf("st_rdev=makedev(%lu, %lu), ",
907 (unsigned long) major(statbuf.st_rdev),
908 (unsigned long) minor(statbuf.st_rdev));
909 break;
910 default:
911 tprintf("st_size=%u, ", statbuf.st_size);
912 break;
913 }
914 if (!abbrev(tcp)) {
915 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
916 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
917 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200918 tprints("}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200919 }
920 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200921 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200922}
923#endif /* LINUX && POWERPC64 */
924
Roland McGratha4d48532005-06-08 20:45:28 +0000925static const struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000926#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000927 { UF_NODUMP, "UF_NODUMP" },
928 { UF_IMMUTABLE, "UF_IMMUTABLE" },
929 { UF_APPEND, "UF_APPEND" },
930 { UF_OPAQUE, "UF_OPAQUE" },
931 { UF_NOUNLINK, "UF_NOUNLINK" },
932 { SF_ARCHIVED, "SF_ARCHIVED" },
933 { SF_IMMUTABLE, "SF_IMMUTABLE" },
934 { SF_APPEND, "SF_APPEND" },
935 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000936#elif UNIXWARE >= 2
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200937#ifdef _S_ISMLD
938 { _S_ISMLD, "_S_ISMLD" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000939#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200940#ifdef _S_ISMOUNTED
941 { _S_ISMOUNTED, "_S_ISMOUNTED" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000942#endif
943#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000944 { 0, NULL },
945};
946
John Hughesc0fc3fd2001-03-08 16:10:40 +0000947#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000948int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000949sys_chflags(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000950{
951 if (entering(tcp)) {
952 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200953 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000954 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000955 }
956 return 0;
957}
958
959int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000960sys_fchflags(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000961{
962 if (entering(tcp)) {
963 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000964 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000965 }
966 return 0;
967}
968#endif
969
John Hughes70623be2001-03-08 13:59:00 +0000970#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000971static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000972realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000973{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000974 if (!abbrev(tcp)) {
975 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
976 (unsigned long) major(statbuf->st_dev),
977 (unsigned long) minor(statbuf->st_dev),
978 (unsigned long) statbuf->st_ino,
979 sprintmode(statbuf->st_mode));
980 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
981 (unsigned long) statbuf->st_nlink,
982 (unsigned long) statbuf->st_uid,
983 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000984#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000985 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
986#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000987#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000988 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
989#endif
990 }
991 else
992 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
993 switch (statbuf->st_mode & S_IFMT) {
994 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000995#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000996 tprintf("st_rdev=makedev(%lu, %lu), ",
997 (unsigned long) major(statbuf->st_rdev),
998 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000999#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +00001000 tprintf("st_size=makedev(%lu, %lu), ",
1001 (unsigned long) major(statbuf->st_size),
1002 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001003#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +00001004 break;
1005 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +00001006 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +00001007 break;
1008 }
1009 if (!abbrev(tcp)) {
1010 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
1011 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
1012 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001013#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001014 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001015 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001016#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001017#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001018 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
1019#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001020#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001021 tprintf(", st_level=%ld", statbuf->st_level);
1022#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001023#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001024 tprintf(", st_fstype=%.*s",
1025 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
1026#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001027#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001028 tprintf(", st_gen=%u", statbuf->st_gen);
1029#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001030 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +00001031 }
1032 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001033 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001034}
1035
Nate Sammons771a6ff1999-04-05 22:39:31 +00001036
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001037static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001038printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001039{
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001040 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001041
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001042 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001043 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001044 return;
1045 }
1046 if (syserror(tcp) || !verbose(tcp)) {
1047 tprintf("%#lx", addr);
1048 return;
1049 }
1050
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001051#ifdef LINUXSPARC
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001052 if (current_personality == 1) {
1053 printstatsol(tcp, addr);
1054 return;
1055 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001056#ifdef SPARC64
1057 else if (current_personality == 2) {
1058 printstat_sparc64(tcp, addr);
1059 return;
1060 }
1061#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001062#endif /* LINUXSPARC */
1063
Andreas Schwabd69fa492010-07-12 21:39:57 +02001064#if defined LINUX && defined POWERPC64
1065 if (current_personality == 1) {
1066 printstat_powerpc32(tcp, addr);
1067 return;
1068 }
1069#endif
1070
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001071 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001072 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001073 return;
1074 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001075
1076 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001077}
John Hughes70623be2001-03-08 13:59:00 +00001078#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001079
Roland McGrathe6d0f712007-08-07 01:22:49 +00001080#if !defined HAVE_STAT64 && defined LINUX && defined X86_64
1081/*
1082 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1083 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1084 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1085 * __GNUC__ is needed for the required __attribute__ below.
1086 */
1087struct stat64 {
1088 unsigned long long st_dev;
1089 unsigned char __pad0[4];
1090 unsigned int __st_ino;
1091 unsigned int st_mode;
1092 unsigned int st_nlink;
1093 unsigned int st_uid;
1094 unsigned int st_gid;
1095 unsigned long long st_rdev;
1096 unsigned char __pad3[4];
1097 long long st_size;
1098 unsigned int st_blksize;
1099 unsigned long long st_blocks;
1100 unsigned int st_atime;
1101 unsigned int st_atime_nsec;
1102 unsigned int st_mtime;
1103 unsigned int st_mtime_nsec;
1104 unsigned int st_ctime;
1105 unsigned int st_ctime_nsec;
1106 unsigned long long st_ino;
1107} __attribute__((packed));
1108# define HAVE_STAT64 1
1109# define STAT64_SIZE 96
1110#endif
1111
Wichert Akkermanc7926982000-04-10 22:22:31 +00001112#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001113static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001114printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001115{
1116 struct stat64 statbuf;
1117
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001118#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001119 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1120#endif
1121
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001122 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001123 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001124 return;
1125 }
1126 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001127 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001128 return;
1129 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001130
1131#ifdef LINUXSPARC
1132 if (current_personality == 1) {
1133 printstatsol(tcp, addr);
1134 return;
1135 }
1136# ifdef SPARC64
1137 else if (current_personality == 2) {
1138 printstat_sparc64(tcp, addr);
1139 return;
1140 }
1141# endif
1142#endif /* LINUXSPARC */
1143
Andreas Schwab61b74352009-10-16 11:37:13 +02001144#if defined LINUX && defined X86_64
1145 if (current_personality == 0) {
1146 printstat(tcp, addr);
1147 return;
1148 }
1149#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +00001150
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001151 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001152 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001153 return;
1154 }
1155
1156 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001157#ifdef HAVE_LONG_LONG
1158 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1159#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001160 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001161#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001162 (unsigned long) major(statbuf.st_dev),
1163 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001164#ifdef HAVE_LONG_LONG
1165 (unsigned long long) statbuf.st_ino,
1166#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001167 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001168#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001169 sprintmode(statbuf.st_mode));
1170 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1171 (unsigned long) statbuf.st_nlink,
1172 (unsigned long) statbuf.st_uid,
1173 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001174#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001175 tprintf("st_blksize=%lu, ",
1176 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001177#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1178#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001179 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001180#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001181 }
1182 else
1183 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1184 switch (statbuf.st_mode & S_IFMT) {
1185 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001186#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001187 tprintf("st_rdev=makedev(%lu, %lu), ",
1188 (unsigned long) major(statbuf.st_rdev),
1189 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001190#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001191 tprintf("st_size=makedev(%lu, %lu), ",
1192 (unsigned long) major(statbuf.st_size),
1193 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001194#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001195 break;
1196 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001197#ifdef HAVE_LONG_LONG
1198 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1199#else
1200 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1201#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001202 break;
1203 }
1204 if (!abbrev(tcp)) {
1205 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1206 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001207 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001208#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001209 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001210 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001211#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001212#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001213 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1214#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001215#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001216 tprintf(", st_level=%ld", statbuf.st_level);
1217#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001218#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001219 tprintf(", st_fstype=%.*s",
1220 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1221#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001222#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001223 tprintf(", st_gen=%u", statbuf.st_gen);
1224#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001225 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001226 }
1227 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001228 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001229}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001230#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001231
H.J. Lua13b3fe2012-02-03 10:10:30 -08001232#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT) \
1233 && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001234static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001235convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001236{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001237 newbuf->st_dev = oldbuf->st_dev;
1238 newbuf->st_ino = oldbuf->st_ino;
1239 newbuf->st_mode = oldbuf->st_mode;
1240 newbuf->st_nlink = oldbuf->st_nlink;
1241 newbuf->st_uid = oldbuf->st_uid;
1242 newbuf->st_gid = oldbuf->st_gid;
1243 newbuf->st_rdev = oldbuf->st_rdev;
1244 newbuf->st_size = oldbuf->st_size;
1245 newbuf->st_atime = oldbuf->st_atime;
1246 newbuf->st_mtime = oldbuf->st_mtime;
1247 newbuf->st_ctime = oldbuf->st_ctime;
1248 newbuf->st_blksize = 0; /* not supported in old_stat */
1249 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001250}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001251
1252
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001253static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001254printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001255{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001256 struct __old_kernel_stat statbuf;
1257 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001258
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001259 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001260 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001261 return;
1262 }
1263 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001264 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001265 return;
1266 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001267
1268#ifdef LINUXSPARC
1269 if (current_personality == 1) {
1270 printstatsol(tcp, addr);
1271 return;
1272 }
1273#endif /* LINUXSPARC */
1274
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001275 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001276 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001277 return;
1278 }
1279
1280 convertoldstat(&statbuf, &newstatbuf);
1281 realprintstat(tcp, &newstatbuf);
1282}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001283#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001284
John Hughes70623be2001-03-08 13:59:00 +00001285#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001286int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001287sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001288{
1289 if (entering(tcp)) {
1290 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001291 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292 } else {
1293 printstat(tcp, tcp->u_arg[1]);
1294 }
1295 return 0;
1296}
John Hughesb8c9f772001-03-07 16:53:07 +00001297#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001298
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001299int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001300sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001301{
1302#ifdef HAVE_STAT64
1303 if (entering(tcp)) {
1304 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001305 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001306 } else {
1307 printstat64(tcp, tcp->u_arg[1]);
1308 }
1309 return 0;
1310#else
1311 return printargs(tcp);
1312#endif
1313}
1314
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001315#ifdef LINUX
1316static const struct xlat fstatatflags[] = {
1317#ifndef AT_SYMLINK_NOFOLLOW
1318# define AT_SYMLINK_NOFOLLOW 0x100
1319#endif
1320 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1321 { 0, NULL },
1322};
Roland McGrath6afc5652007-07-24 01:57:11 +00001323#define utimensatflags fstatatflags
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001324
1325int
1326sys_newfstatat(struct tcb *tcp)
1327{
1328 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001329 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001330 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001331 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001332 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001333#ifdef POWERPC64
1334 if (current_personality == 0)
1335 printstat(tcp, tcp->u_arg[2]);
1336 else
1337 printstat64(tcp, tcp->u_arg[2]);
1338#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001339 printstat64(tcp, tcp->u_arg[2]);
1340#else
1341 printstat(tcp, tcp->u_arg[2]);
1342#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001343 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001344 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1345 }
1346 return 0;
1347}
1348#endif
1349
H.J. Lua13b3fe2012-02-03 10:10:30 -08001350#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT) \
1351 && !defined(HAVE_LONG_LONG_OFF_T)
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]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001357 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001358 } 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{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001369 if (entering(tcp)) {
1370 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001371 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001372 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001373 printstat(tcp, tcp->u_arg[1]);
1374 }
1375 return 0;
1376}
John Hughesb8c9f772001-03-07 16:53:07 +00001377#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001378
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001379int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001380sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001381{
1382#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001383 if (entering(tcp)) {
1384 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001385 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001386 } else {
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001387 printstat64(tcp, tcp->u_arg[1]);
1388 }
1389 return 0;
1390#else
1391 return printargs(tcp);
1392#endif
1393}
1394
H.J. Lua13b3fe2012-02-03 10:10:30 -08001395#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT) \
1396 && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001397int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001398sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001399{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001400 if (entering(tcp)) {
1401 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001402 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001403 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001404 printoldstat(tcp, tcp->u_arg[1]);
1405 }
1406 return 0;
1407}
Roland McGrath79db8af2003-06-27 21:20:09 +00001408#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001409
John Hughes70623be2001-03-08 13:59:00 +00001410#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001411int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001412sys_lstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413{
1414 if (entering(tcp)) {
1415 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001416 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001417 } else {
1418 printstat(tcp, tcp->u_arg[1]);
1419 }
1420 return 0;
1421}
John Hughesb8c9f772001-03-07 16:53:07 +00001422#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001423
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001424int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001425sys_lstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001426{
1427#ifdef HAVE_STAT64
1428 if (entering(tcp)) {
1429 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001430 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001431 } else {
1432 printstat64(tcp, tcp->u_arg[1]);
1433 }
1434 return 0;
1435#else
1436 return printargs(tcp);
1437#endif
1438}
1439
H.J. Lua13b3fe2012-02-03 10:10:30 -08001440#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT) \
1441 && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001442int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001443sys_oldlstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001444{
1445 if (entering(tcp)) {
1446 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001447 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001448 } else {
1449 printoldstat(tcp, tcp->u_arg[1]);
1450 }
1451 return 0;
1452}
Roland McGrath79db8af2003-06-27 21:20:09 +00001453#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001454
1455
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001456#if defined(SVR4) || defined(LINUXSPARC)
1457
1458int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001459sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001460{
1461 if (entering(tcp)) {
1462 tprintf("%ld, ", tcp->u_arg[0]);
1463 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001464 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001465 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001466#ifdef _STAT64_VER
1467 if (tcp->u_arg[0] == _STAT64_VER)
1468 printstat64 (tcp, tcp->u_arg[2]);
1469 else
1470#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001471 printstat(tcp, tcp->u_arg[2]);
1472 }
1473 return 0;
1474}
1475
1476int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001477sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001478{
1479 if (entering(tcp))
1480 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1481 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001482#ifdef _STAT64_VER
1483 if (tcp->u_arg[0] == _STAT64_VER)
1484 printstat64 (tcp, tcp->u_arg[2]);
1485 else
1486#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001487 printstat(tcp, tcp->u_arg[2]);
1488 }
1489 return 0;
1490}
1491
1492int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001493sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001494{
1495 if (entering(tcp)) {
1496 tprintf("%ld, ", tcp->u_arg[0]);
1497 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001498 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001499 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001500#ifdef _STAT64_VER
1501 if (tcp->u_arg[0] == _STAT64_VER)
1502 printstat64 (tcp, tcp->u_arg[2]);
1503 else
1504#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001505 printstat(tcp, tcp->u_arg[2]);
1506 }
1507 return 0;
1508}
1509
1510int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001511sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001512{
1513 int mode = tcp->u_arg[2];
1514
1515 if (entering(tcp)) {
1516 tprintf("%ld, ", tcp->u_arg[0]);
1517 printpath(tcp, tcp->u_arg[1]);
1518 tprintf(", %s", sprintmode(mode));
1519 switch (mode & S_IFMT) {
1520 case S_IFCHR: case S_IFBLK:
1521#ifdef LINUXSPARC
1522 tprintf(", makedev(%lu, %lu)",
1523 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1524 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001525#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001526 tprintf(", makedev(%lu, %lu)",
1527 (unsigned long) major(tcp->u_arg[3]),
1528 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001529#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001530 break;
1531 default:
1532 break;
1533 }
1534 }
1535 return 0;
1536}
1537
Wichert Akkerman8829a551999-06-11 13:18:40 +00001538#ifdef HAVE_SYS_ACL_H
1539
1540#include <sys/acl.h>
1541
Roland McGratha4d48532005-06-08 20:45:28 +00001542static const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001543#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001544 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001545#endif
1546#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001547 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001548#endif
1549#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001550 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001551#endif
1552#ifdef ACL_GET
1553 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001554#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001555#ifdef ACL_SET
1556 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001557#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001558#ifdef ACL_CNT
1559 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001560#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001561 { 0, NULL },
1562};
1563
1564int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001565sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001566{
1567 if (entering(tcp)) {
1568 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001569 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001570 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1571 tprintf(", %ld", tcp->u_arg[2]);
1572 /*
1573 * FIXME - dump out the list of aclent_t's pointed to
1574 * by "tcp->u_arg[3]" if it's not NULL.
1575 */
1576 if (tcp->u_arg[3])
1577 tprintf(", %#lx", tcp->u_arg[3]);
1578 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001579 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001580 }
1581 return 0;
1582}
1583
1584
1585int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001586sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001587{
1588 if (entering(tcp)) {
1589 tprintf("%ld, ", tcp->u_arg[0]);
1590 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1591 tprintf(", %ld", tcp->u_arg[2]);
1592 /*
1593 * FIXME - dump out the list of aclent_t's pointed to
1594 * by "tcp->u_arg[3]" if it's not NULL.
1595 */
1596 if (tcp->u_arg[3])
1597 tprintf(", %#lx", tcp->u_arg[3]);
1598 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001599 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001600 }
1601 return 0;
1602}
1603
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001604
Roland McGratha4d48532005-06-08 20:45:28 +00001605static const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001606#ifdef IPC_SHM
1607 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001608#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001609#ifdef IPC_SEM
1610 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001611#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001612#ifdef IPC_MSG
1613 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001614#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001615 { 0, NULL },
1616};
1617
1618
1619int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001620sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001621{
1622 if (entering(tcp)) {
1623 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1624 tprintf(", %#lx, ", tcp->u_arg[1]);
1625 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1626 tprintf(", %ld", tcp->u_arg[3]);
1627 /*
1628 * FIXME - dump out the list of aclent_t's pointed to
1629 * by "tcp->u_arg[4]" if it's not NULL.
1630 */
1631 if (tcp->u_arg[4])
1632 tprintf(", %#lx", tcp->u_arg[4]);
1633 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001634 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001635 }
1636 return 0;
1637}
1638
Wichert Akkerman8829a551999-06-11 13:18:40 +00001639#endif /* HAVE_SYS_ACL_H */
1640
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001641#endif /* SVR4 || LINUXSPARC */
1642
Michal Ludvig53b320f2002-09-23 13:30:09 +00001643#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001644
Roland McGrathd9f816f2004-09-04 03:39:20 +00001645static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001646 { 0x73757245, "CODA_SUPER_MAGIC" },
1647 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1648 { 0x1373, "DEVFS_SUPER_MAGIC" },
1649 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1650 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001651 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1652 { 0xef53, "EXT2_SUPER_MAGIC" },
1653 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001654 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001655 { 0x9660, "ISOFS_SUPER_MAGIC" },
1656 { 0x137f, "MINIX_SUPER_MAGIC" },
1657 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001658 { 0x2468, "MINIX2_SUPER_MAGIC" },
1659 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001660 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001661 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001662 { 0x6969, "NFS_SUPER_MAGIC" },
1663 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001664 { 0x002f, "QNX4_SUPER_MAGIC" },
1665 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1666 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1667 { 0x517b, "SMB_SUPER_MAGIC" },
1668 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1669 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1670 { 0x00011954, "UFS_MAGIC" },
1671 { 0x54190100, "UFS_CIGAM" },
1672 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001673 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001674 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001675 { 0, NULL },
1676};
1677
Michal Ludvig53b320f2002-09-23 13:30:09 +00001678#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001679
1680#ifndef SVR4
1681
Roland McGrathf9c49b22004-10-06 22:11:54 +00001682static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001683sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001684{
1685 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001686#ifdef LINUX
Roland McGrathf9c49b22004-10-06 22:11:54 +00001687 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001688
1689 s = xlookup(fsmagic, magic);
1690 if (s) {
1691 sprintf(buf, "\"%s\"", s);
1692 return buf;
1693 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001694#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001695 sprintf(buf, "%#x", magic);
1696 return buf;
1697}
1698
1699static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001700printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001701{
1702 struct statfs statbuf;
1703
1704 if (syserror(tcp) || !verbose(tcp)) {
1705 tprintf("%#lx", addr);
1706 return;
1707 }
1708 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001709 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001710 return;
1711 }
1712#ifdef ALPHA
1713
1714 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1715 sprintfstype(statbuf.f_type),
1716 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001717 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001718 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001719 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1720 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001721#else /* !ALPHA */
1722 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1723 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001724 (unsigned long)statbuf.f_bsize,
1725 (unsigned long)statbuf.f_blocks,
1726 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001727 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1728 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001729 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001730 (unsigned long)statbuf.f_ffree,
1731 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001732#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001733 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001734#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001735#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001736#ifdef _STATFS_F_FRSIZE
1737 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1738#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001739 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001740}
1741
1742int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001743sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001744{
1745 if (entering(tcp)) {
1746 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001747 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001748 } else {
1749 printstatfs(tcp, tcp->u_arg[1]);
1750 }
1751 return 0;
1752}
1753
1754int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001755sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001756{
1757 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001758 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001759 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001760 } else {
1761 printstatfs(tcp, tcp->u_arg[1]);
1762 }
1763 return 0;
1764}
1765
Bernhard Reutner-Fischer9906e6d2009-10-14 16:33:58 +02001766#if defined LINUX && defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001767static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001768printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001769{
1770 struct statfs64 statbuf;
1771
1772 if (syserror(tcp) || !verbose(tcp)) {
1773 tprintf("%#lx", addr);
1774 return;
1775 }
1776 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001777 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001778 return;
1779 }
Roland McGrath08738432005-06-03 02:40:39 +00001780 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001781 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001782 (unsigned long long)statbuf.f_bsize,
1783 (unsigned long long)statbuf.f_blocks,
1784 (unsigned long long)statbuf.f_bfree);
1785 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1786 (unsigned long long)statbuf.f_bavail,
1787 (unsigned long long)statbuf.f_files,
1788 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001789 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1790 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001791#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001792 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001793#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001794#ifdef _STATFS_F_FLAGS
1795 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1796#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001797 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001798}
1799
Andreas Schwab7d558012012-01-17 18:14:22 +01001800struct compat_statfs64 {
1801 uint32_t f_type;
1802 uint32_t f_bsize;
1803 uint64_t f_blocks;
1804 uint64_t f_bfree;
1805 uint64_t f_bavail;
1806 uint64_t f_files;
1807 uint64_t f_ffree;
1808 fsid_t f_fsid;
1809 uint32_t f_namelen;
1810 uint32_t f_frsize;
1811 uint32_t f_flags;
1812 uint32_t f_spare[4];
1813}
1814#if defined(X86_64) || defined(IA64)
1815 __attribute__ ((packed, aligned(4)))
1816#endif
1817;
1818
1819static void
1820printcompat_statfs64(struct tcb *tcp, long addr)
1821{
1822 struct compat_statfs64 statbuf;
1823
1824 if (syserror(tcp) || !verbose(tcp)) {
1825 tprintf("%#lx", addr);
1826 return;
1827 }
1828 if (umove(tcp, addr, &statbuf) < 0) {
1829 tprints("{...}");
1830 return;
1831 }
1832 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1833 sprintfstype(statbuf.f_type),
1834 (unsigned long)statbuf.f_bsize,
1835 (unsigned long long)statbuf.f_blocks,
1836 (unsigned long long)statbuf.f_bfree);
1837 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1838 (unsigned long long)statbuf.f_bavail,
1839 (unsigned long long)statbuf.f_files,
1840 (unsigned long long)statbuf.f_ffree,
1841 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1842 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1843 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1844 tprintf(", f_flags=%lu", (unsigned long)statbuf.f_frsize);
1845 tprints("}");
1846}
1847
Roland McGrathab147c52003-07-17 09:03:02 +00001848int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001849sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001850{
1851 if (entering(tcp)) {
1852 printpath(tcp, tcp->u_arg[0]);
1853 tprintf(", %lu, ", tcp->u_arg[1]);
1854 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001855 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001856 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001857 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1858 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001859 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001860 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001861 }
1862 return 0;
1863}
1864
1865int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001866sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001867{
1868 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001869 printfd(tcp, tcp->u_arg[0]);
1870 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001871 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001872 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001873 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001874 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1875 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001876 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001877 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001878 }
1879 return 0;
1880}
1881#endif
1882
Michal Ludvig53b320f2002-09-23 13:30:09 +00001883#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001884
1885int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001886osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001887{
1888 if (entering(tcp)) {
1889 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001890 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001891 } else {
1892 printstatfs(tcp, tcp->u_arg[1]);
1893 tprintf(", %lu", tcp->u_arg[2]);
1894 }
1895 return 0;
1896}
1897
1898int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001899osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001900{
1901 if (entering(tcp)) {
1902 tprintf("%lu, ", tcp->u_arg[0]);
1903 } else {
1904 printstatfs(tcp, tcp->u_arg[1]);
1905 tprintf(", %lu", tcp->u_arg[2]);
1906 }
1907 return 0;
1908}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001909#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001910
1911#endif /* !SVR4 */
1912
1913#ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001914int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001915sys_ustat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001916{
1917 struct ustat statbuf;
1918
1919 if (entering(tcp)) {
1920 tprintf("makedev(%lu, %lu), ",
1921 (long) major(tcp->u_arg[0]),
1922 (long) minor(tcp->u_arg[0]));
1923 }
1924 else {
1925 if (syserror(tcp) || !verbose(tcp))
1926 tprintf("%#lx", tcp->u_arg[1]);
1927 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001928 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001929 else {
1930 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1931 statbuf.f_tfree, statbuf.f_tinode);
1932 tprintf("f_fname=\"%.*s\", ",
1933 (int) sizeof(statbuf.f_fname),
1934 statbuf.f_fname);
1935 tprintf("f_fpack=\"%.*s\"}",
1936 (int) sizeof(statbuf.f_fpack),
1937 statbuf.f_fpack);
1938 }
1939 }
1940 return 0;
1941}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001942#endif /* SUNOS4 */
1943
1944/* directory */
1945int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001946sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001947{
1948 if (entering(tcp)) {
1949 printpath(tcp, tcp->u_arg[0]);
1950 }
1951 return 0;
1952}
1953
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001954static int
1955decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001956{
1957 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001958 printpath(tcp, tcp->u_arg[offset]);
1959 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001960 }
1961 return 0;
1962}
1963
1964int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001965sys_mkdir(struct tcb *tcp)
1966{
1967 return decode_mkdir(tcp, 0);
1968}
1969
1970#ifdef LINUX
1971int
1972sys_mkdirat(struct tcb *tcp)
1973{
1974 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001975 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001976 return decode_mkdir(tcp, 1);
1977}
1978#endif
1979
1980int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001981sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001982{
1983 if (entering(tcp)) {
1984 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001985 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001986 printpath(tcp, tcp->u_arg[1]);
1987 }
1988 return 0;
1989}
1990
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001991#ifdef LINUX
1992int
1993sys_linkat(struct tcb *tcp)
1994{
1995 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001996 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001997 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001998 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001999 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002000 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002001 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03002002 printfd(tcp, tcp->u_arg[4]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002003 }
2004 return 0;
2005}
2006#endif
2007
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002008#ifdef LINUX
2009static const struct xlat unlinkatflags[] = {
2010#ifndef AT_REMOVEDIR
2011# define AT_REMOVEDIR 0x200
2012#endif
2013 { AT_REMOVEDIR, "AT_REMOVEDIR" },
2014 { 0, NULL },
2015};
2016
2017int
2018sys_unlinkat(struct tcb *tcp)
2019{
2020 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002021 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002022 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002023 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002024 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
2025 }
2026 return 0;
2027}
2028#endif
2029
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002030#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002031int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002032sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002033{
2034 if (entering(tcp)) {
2035 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002036 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03002037 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002038 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002039 }
2040 return 0;
2041}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002042#endif
2043
2044static int
2045decode_readlink(struct tcb *tcp, int offset)
2046{
2047 if (entering(tcp)) {
2048 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002049 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002050 } else {
2051 if (syserror(tcp))
2052 tprintf("%#lx", tcp->u_arg[offset + 1]);
2053 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01002054 /* Used to use printpathn(), but readlink
2055 * neither includes NUL in the returned count,
2056 * nor actually writes it into memory.
2057 * printpathn() would decide on printing
2058 * "..." continuation based on garbage
2059 * past return buffer's end.
2060 */
2061 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002062 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))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002078 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002079 return decode_readlink(tcp, 1);
2080}
2081#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002082
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002083#ifdef LINUX
2084int
2085sys_renameat(struct tcb *tcp)
2086{
2087 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002088 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002089 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002090 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03002091 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002092 printpath(tcp, tcp->u_arg[3]);
2093 }
2094 return 0;
2095}
2096#endif
2097
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002098int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002099sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002100{
2101 if (entering(tcp)) {
2102 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002103 printuid(", ", tcp->u_arg[1]);
2104 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002105 }
2106 return 0;
2107}
2108
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002109#ifdef LINUX
2110int
2111sys_fchownat(struct tcb *tcp)
2112{
2113 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002114 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002115 printpath(tcp, tcp->u_arg[1]);
2116 printuid(", ", tcp->u_arg[2]);
2117 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002118 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002119 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
2120 }
2121 return 0;
2122}
2123#endif
2124
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002125int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002126sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002127{
2128 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002129 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002130 printuid(", ", tcp->u_arg[1]);
2131 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002132 }
2133 return 0;
2134}
2135
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002136static int
2137decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002138{
2139 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002140 printpath(tcp, tcp->u_arg[offset]);
2141 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002142 }
2143 return 0;
2144}
2145
2146int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002147sys_chmod(struct tcb *tcp)
2148{
2149 return decode_chmod(tcp, 0);
2150}
2151
2152#ifdef LINUX
2153int
2154sys_fchmodat(struct tcb *tcp)
2155{
2156 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002157 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002158 return decode_chmod(tcp, 1);
2159}
2160#endif
2161
2162int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002163sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002164{
2165 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002166 printfd(tcp, tcp->u_arg[0]);
2167 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002168 }
2169 return 0;
2170}
2171
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002172#ifdef ALPHA
2173int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002174sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002175{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002176 if (entering(tcp)) {
2177 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002178 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002179 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2180 }
2181 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002182}
2183#endif
2184
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002185static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002186decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002187{
2188 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002189 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002190 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002191 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002192 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00002193 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002194 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00002195 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2196 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002197 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002198 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002199 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00002200 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002201 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00002202 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002203 }
2204 return 0;
2205}
2206
2207int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002208sys_utimes(struct tcb *tcp)
2209{
Roland McGrath6afc5652007-07-24 01:57:11 +00002210 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002211}
2212
2213#ifdef LINUX
2214int
2215sys_futimesat(struct tcb *tcp)
2216{
2217 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002218 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002219 return decode_utimes(tcp, 1, 0);
2220}
2221
2222int
2223sys_utimensat(struct tcb *tcp)
2224{
2225 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002226 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002227 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002228 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002229 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2230 }
2231 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002232}
2233#endif
2234
2235int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002236sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002237{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002238 union {
2239 long utl[2];
2240 int uti[2];
2241 } u;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002242
2243 if (entering(tcp)) {
2244 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002245 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002246 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002247 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002248 else if (!verbose(tcp))
2249 tprintf("%#lx", tcp->u_arg[1]);
Roland McGrath7e9817c2007-07-05 20:31:58 +00002250 else if (umoven(tcp, tcp->u_arg[1],
2251 2 * personality_wordsize[current_personality],
2252 (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002253 tprints("[?, ?]");
Roland McGrath7e9817c2007-07-05 20:31:58 +00002254 else if (personality_wordsize[current_personality]
2255 == sizeof u.utl[0]) {
2256 tprintf("[%s,", sprinttime(u.utl[0]));
2257 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002258 }
Roland McGrath7e9817c2007-07-05 20:31:58 +00002259 else if (personality_wordsize[current_personality]
2260 == sizeof u.uti[0]) {
2261 tprintf("[%s,", sprinttime(u.uti[0]));
2262 tprintf(" %s]", sprinttime(u.uti[1]));
2263 }
2264 else
2265 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002266 }
2267 return 0;
2268}
2269
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002270static int
2271decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002272{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002273 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002274
2275 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002276 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002277 tprintf(", %s", sprintmode(mode));
2278 switch (mode & S_IFMT) {
2279 case S_IFCHR: case S_IFBLK:
2280#ifdef LINUXSPARC
2281 if (current_personality == 1)
2282 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002283 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2284 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002285 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002286#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002287 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002288 (unsigned long) major(tcp->u_arg[offset + 2]),
2289 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002290 break;
2291 default:
2292 break;
2293 }
2294 }
2295 return 0;
2296}
2297
2298int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002299sys_mknod(struct tcb *tcp)
2300{
2301 return decode_mknod(tcp, 0);
2302}
2303
2304#ifdef LINUX
2305int
2306sys_mknodat(struct tcb *tcp)
2307{
2308 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002309 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002310 return decode_mknod(tcp, 1);
2311}
2312#endif
2313
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002314#ifdef FREEBSD
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002315int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002316sys_mkfifo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002317{
2318 if (entering(tcp)) {
2319 printpath(tcp, tcp->u_arg[0]);
2320 tprintf(", %#lo", tcp->u_arg[1]);
2321 }
2322 return 0;
2323}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002324#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002325
2326int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002327sys_fsync(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002328{
2329 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002330 printfd(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002331 }
2332 return 0;
2333}
2334
Michal Ludvig53b320f2002-09-23 13:30:09 +00002335#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002336
2337static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002338printdir(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002339{
2340 struct dirent d;
2341
2342 if (!verbose(tcp)) {
2343 tprintf("%#lx", addr);
2344 return;
2345 }
2346 if (umove(tcp, addr, &d) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002347 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002348 return;
2349 }
2350 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002351 tprints("d_name=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002352 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002353 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002354}
2355
2356int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002357sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002358{
2359 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002360 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002361 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002362 } else {
2363 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2364 tprintf("%#lx", tcp->u_arg[1]);
2365 else
2366 printdir(tcp, tcp->u_arg[1]);
2367 /* Not much point in printing this out, it is always 1. */
2368 if (tcp->u_arg[2] != 1)
2369 tprintf(", %lu", tcp->u_arg[2]);
2370 }
2371 return 0;
2372}
2373
Michal Ludvig53b320f2002-09-23 13:30:09 +00002374#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002375
Roland McGrath40542842004-01-13 09:47:49 +00002376#if defined FREEBSD || defined LINUX
Roland McGratha4d48532005-06-08 20:45:28 +00002377static const struct xlat direnttypes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002378 { DT_UNKNOWN, "DT_UNKNOWN" },
2379 { DT_FIFO, "DT_FIFO" },
2380 { DT_CHR, "DT_CHR" },
2381 { DT_DIR, "DT_DIR" },
2382 { DT_BLK, "DT_BLK" },
2383 { DT_REG, "DT_REG" },
2384 { DT_LNK, "DT_LNK" },
2385 { DT_SOCK, "DT_SOCK" },
2386 { DT_WHT, "DT_WHT" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002387 { 0, NULL },
2388};
2389
2390#endif
2391
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002392int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002393sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002394{
2395 int i, len, dents = 0;
2396 char *buf;
2397
2398 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002399 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002400 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002401 return 0;
2402 }
2403 if (syserror(tcp) || !verbose(tcp)) {
2404 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2405 return 0;
2406 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002407 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002408 /* Beware of insanely large or negative values in tcp->u_rval */
2409 if (tcp->u_rval > 1024*1024)
2410 len = 1024*1024;
2411 if (tcp->u_rval < 0)
2412 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002413 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002414 if (len && !buf)
2415 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002416 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002417 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002418 free(buf);
2419 return 0;
2420 }
2421 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002422 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002423 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002424 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002425#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002426 if (!abbrev(tcp)) {
2427 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2428 i ? " " : "", d->d_ino, d->d_off);
2429 tprintf("d_reclen=%u, d_name=\"%s\"}",
2430 d->d_reclen, d->d_name);
2431 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002432#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002433#ifdef SVR4
2434 if (!abbrev(tcp)) {
2435 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002436 i ? " " : "",
2437 (unsigned long) d->d_ino,
2438 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002439 tprintf("d_reclen=%u, d_name=\"%s\"}",
2440 d->d_reclen, d->d_name);
2441 }
2442#endif /* SVR4 */
2443#ifdef SUNOS4
2444 if (!abbrev(tcp)) {
2445 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2446 i ? " " : "", d->d_off, d->d_fileno,
2447 d->d_reclen);
2448 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2449 d->d_namlen, d->d_namlen, d->d_name);
2450 }
2451#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002452#ifdef FREEBSD
2453 if (!abbrev(tcp)) {
2454 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2455 i ? " " : "", d->d_fileno, d->d_reclen);
2456 printxval(direnttypes, d->d_type, "DT_???");
2457 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2458 d->d_namlen, d->d_namlen, d->d_name);
2459 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002460#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002461 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002462 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002463 break;
2464 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002465 i += d->d_reclen;
2466 dents++;
2467 }
2468 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002469 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002470 else
2471 tprintf("/* %u entries */", dents);
2472 tprintf(", %lu", tcp->u_arg[2]);
2473 free(buf);
2474 return 0;
2475}
2476
John Hughesbdf48f52001-03-06 15:08:09 +00002477
2478#if _LFS64_LARGEFILE
2479int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002480sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002481{
2482 int i, len, dents = 0;
2483 char *buf;
2484
2485 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002486 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002487 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002488 return 0;
2489 }
2490 if (syserror(tcp) || !verbose(tcp)) {
2491 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2492 return 0;
2493 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002494
John Hughesbdf48f52001-03-06 15:08:09 +00002495 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002496 /* Beware of insanely large or negative tcp->u_rval */
2497 if (tcp->u_rval > 1024*1024)
2498 len = 1024*1024;
2499 if (tcp->u_rval < 0)
2500 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002501 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002502 if (len && !buf)
2503 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002504
John Hughesbdf48f52001-03-06 15:08:09 +00002505 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002506 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002507 free(buf);
2508 return 0;
2509 }
2510 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002511 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002512 for (i = 0; i < len;) {
2513 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002514#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002515 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002516 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002517 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002518 d->d_ino,
2519 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002520#ifdef LINUX
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002521 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002522 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002523 tprints(", ");
Roland McGrath40542842004-01-13 09:47:49 +00002524#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002525 tprintf("d_reclen=%u, d_name=\"%s\"}",
2526 d->d_reclen, d->d_name);
2527 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002528#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002529#ifdef SUNOS4
2530 if (!abbrev(tcp)) {
2531 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2532 i ? " " : "", d->d_off, d->d_fileno,
2533 d->d_reclen);
2534 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2535 d->d_namlen, d->d_namlen, d->d_name);
2536 }
2537#endif /* SUNOS4 */
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002538 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002539 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002540 break;
2541 }
John Hughesbdf48f52001-03-06 15:08:09 +00002542 i += d->d_reclen;
2543 dents++;
2544 }
2545 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002546 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002547 else
2548 tprintf("/* %u entries */", dents);
2549 tprintf(", %lu", tcp->u_arg[2]);
2550 free(buf);
2551 return 0;
2552}
2553#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002554
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002555#ifdef FREEBSD
2556int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002557sys_getdirentries(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002558{
2559 int i, len, dents = 0;
2560 long basep;
2561 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002562
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002563 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002564 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002565 tprints(", ");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002566 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 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002572
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002573 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002574 /* Beware of insanely large or negative tcp->u_rval */
2575 if (tcp->u_rval > 1024*1024)
2576 len = 1024*1024;
2577 if (tcp->u_rval < 0)
2578 len = 0;
Denys Vlasenko5d645812011-08-20 12:48:18 +02002579 buf = malloc(len);
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002580 if (!buf)
2581 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002582
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002583 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002584 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002585 free(buf);
2586 return 0;
2587 }
2588 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002589 tprints("{");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002590 for (i = 0; i < len;) {
2591 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2592 if (!abbrev(tcp)) {
2593 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2594 i ? " " : "", d->d_fileno, d->d_reclen);
2595 printxval(direnttypes, d->d_type, "DT_???");
2596 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2597 d->d_namlen, d->d_namlen, d->d_name);
2598 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002599 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002600 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002601 break;
2602 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002603 i += d->d_reclen;
2604 dents++;
2605 }
2606 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002607 tprints("}");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002608 else
2609 tprintf("/* %u entries */", dents);
2610 free(buf);
2611 tprintf(", %lu", tcp->u_arg[2]);
2612 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2613 tprintf(", %#lx", tcp->u_arg[3]);
2614 else
2615 tprintf(", [%lu]", basep);
2616 return 0;
2617}
2618#endif
2619
Michal Ludvig53b320f2002-09-23 13:30:09 +00002620#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002621int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002622sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002623{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002624 if (exiting(tcp)) {
2625 if (syserror(tcp))
2626 tprintf("%#lx", tcp->u_arg[0]);
2627 else
2628 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2629 tprintf(", %lu", tcp->u_arg[1]);
2630 }
2631 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002632}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002633#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002634
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002635#ifdef FREEBSD
2636int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002637sys___getcwd(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002638{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002639 if (exiting(tcp)) {
2640 if (syserror(tcp))
2641 tprintf("%#lx", tcp->u_arg[0]);
2642 else
2643 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2644 tprintf(", %lu", tcp->u_arg[1]);
2645 }
2646 return 0;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002647}
2648#endif
2649
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002650#ifdef HAVE_SYS_ASYNCH_H
2651
2652int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002653sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002654{
2655 struct aio_result_t res;
2656
2657 if (entering(tcp)) {
2658 tprintf("%lu, ", tcp->u_arg[0]);
2659 } else {
2660 if (syserror(tcp))
2661 tprintf("%#lx", tcp->u_arg[1]);
2662 else
2663 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2664 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2665 printxval(whence, tcp->u_arg[4], "L_???");
2666 if (syserror(tcp) || tcp->u_arg[5] == 0
2667 || umove(tcp, tcp->u_arg[5], &res) < 0)
2668 tprintf(", %#lx", tcp->u_arg[5]);
2669 else
2670 tprintf(", {aio_return %d aio_errno %d}",
2671 res.aio_return, res.aio_errno);
2672 }
2673 return 0;
2674}
2675
2676int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002677sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002678{
2679 struct aio_result_t res;
2680
2681 if (entering(tcp)) {
2682 tprintf("%lu, ", tcp->u_arg[0]);
2683 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2684 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2685 printxval(whence, tcp->u_arg[4], "L_???");
2686 }
2687 else {
2688 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002689 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002690 else if (syserror(tcp)
2691 || umove(tcp, tcp->u_arg[5], &res) < 0)
2692 tprintf(", %#lx", tcp->u_arg[5]);
2693 else
2694 tprintf(", {aio_return %d aio_errno %d}",
2695 res.aio_return, res.aio_errno);
2696 }
2697 return 0;
2698}
2699
2700int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002701sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002702{
2703 if (entering(tcp))
2704 printtv(tcp, tcp->u_arg[0]);
2705 return 0;
2706}
2707
2708int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002709sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002710{
2711 struct aio_result_t res;
2712
2713 if (exiting(tcp)) {
2714 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002715 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002716 else if (syserror(tcp)
2717 || umove(tcp, tcp->u_arg[0], &res) < 0)
2718 tprintf("%#lx", tcp->u_arg[0]);
2719 else
2720 tprintf("{aio_return %d aio_errno %d}",
2721 res.aio_return, res.aio_errno);
2722 }
2723 return 0;
2724}
2725
2726#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002727
Roland McGratha4d48532005-06-08 20:45:28 +00002728static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002729#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002730 { XATTR_CREATE, "XATTR_CREATE" },
2731 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002732#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002733 { 0, NULL }
2734};
2735
Roland McGrath3292e222004-08-31 06:30:48 +00002736static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002737print_xattr_val(struct tcb *tcp, int failed,
2738 unsigned long arg,
2739 unsigned long insize,
2740 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002741{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002742 if (!failed) {
2743 unsigned long capacity = 4 * size + 1;
2744 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2745 if (buf == NULL || /* probably a bogus size argument */
2746 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2747 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002748 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002749 else {
2750 unsigned char *out = buf;
2751 unsigned char *in = &buf[3 * size];
2752 size_t i;
2753 for (i = 0; i < size; ++i) {
2754 if (isprint(in[i]))
2755 *out++ = in[i];
2756 else {
2757#define tohex(n) "0123456789abcdef"[n]
2758 *out++ = '\\';
2759 *out++ = 'x';
2760 *out++ = tohex(in[i] / 16);
2761 *out++ = tohex(in[i] % 16);
2762 }
2763 }
2764 /* Don't print terminating NUL if there is one. */
2765 if (i > 0 && in[i - 1] == '\0')
2766 out -= 4;
2767 *out = '\0';
2768 tprintf(", \"%s\", %ld", buf, insize);
2769 }
2770 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002771 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002772 if (failed)
2773 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002774}
2775
Roland McGrath186c5ac2002-12-15 23:58:23 +00002776int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002777sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002778{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002779 if (entering(tcp)) {
2780 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002781 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002782 printstr(tcp, tcp->u_arg[1], -1);
2783 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002784 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002785 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2786 }
2787 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002788}
2789
2790int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002791sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002792{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002793 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002794 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002795 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002796 printstr(tcp, tcp->u_arg[1], -1);
2797 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002798 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002799 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2800 }
2801 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002802}
2803
2804int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002805sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002806{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002807 if (entering(tcp)) {
2808 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002809 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002810 printstr(tcp, tcp->u_arg[1], -1);
2811 } else {
2812 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2813 tcp->u_rval);
2814 }
2815 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002816}
2817
2818int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002819sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002820{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002821 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002822 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002823 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002824 printstr(tcp, tcp->u_arg[1], -1);
2825 } else {
2826 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2827 tcp->u_rval);
2828 }
2829 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002830}
2831
2832int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002833sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002834{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002835 if (entering(tcp)) {
2836 printpath(tcp, tcp->u_arg[0]);
2837 } else {
2838 /* XXX Print value in format */
2839 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2840 }
2841 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002842}
2843
2844int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002845sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002846{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002847 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002848 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002849 } else {
2850 /* XXX Print value in format */
2851 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2852 }
2853 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002854}
2855
2856int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002857sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002858{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002859 if (entering(tcp)) {
2860 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002861 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002862 printstr(tcp, tcp->u_arg[1], -1);
2863 }
2864 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002865}
2866
2867int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002868sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002869{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002870 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002871 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002872 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002873 printstr(tcp, tcp->u_arg[1], -1);
2874 }
2875 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002876}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002877
2878
2879static const struct xlat advise[] = {
2880 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2881 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2882 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2883 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2884 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2885 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2886 { 0, NULL }
2887};
2888
2889
Roland McGrathe27ed342004-10-20 02:24:19 +00002890#ifdef LINUX
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002891int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002892sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002893{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002894 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002895 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002896 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002897 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002898 argn = printllval(tcp, "%lld", 1);
2899 tprintf(", %ld, ", tcp->u_arg[argn++]);
2900 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002901 }
2902 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002903}
2904#endif
2905
2906
2907int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002908sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002909{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002910 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002911 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002912 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002913 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002914#if defined ARM || defined POWERPC
2915 argn = printllval(tcp, "%lld, ", 2);
2916#else
2917 argn = printllval(tcp, "%lld, ", 1);
2918#endif
2919 argn = printllval(tcp, "%lld, ", argn);
2920#if defined ARM || defined POWERPC
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002921 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002922#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002923 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002924#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002925 }
2926 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002927}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002928
2929#ifdef LINUX
2930static const struct xlat inotify_modes[] = {
Dmitry V. Levind475c062011-03-03 01:02:41 +00002931 { 0x00000001, "IN_ACCESS" },
2932 { 0x00000002, "IN_MODIFY" },
2933 { 0x00000004, "IN_ATTRIB" },
2934 { 0x00000008, "IN_CLOSE_WRITE"},
2935 { 0x00000010, "IN_CLOSE_NOWRITE"},
2936 { 0x00000020, "IN_OPEN" },
2937 { 0x00000040, "IN_MOVED_FROM" },
2938 { 0x00000080, "IN_MOVED_TO" },
2939 { 0x00000100, "IN_CREATE" },
2940 { 0x00000200, "IN_DELETE" },
2941 { 0x00000400, "IN_DELETE_SELF"},
2942 { 0x00000800, "IN_MOVE_SELF" },
2943 { 0x00002000, "IN_UNMOUNT" },
2944 { 0x00004000, "IN_Q_OVERFLOW" },
2945 { 0x00008000, "IN_IGNORED" },
2946 { 0x01000000, "IN_ONLYDIR" },
2947 { 0x02000000, "IN_DONT_FOLLOW"},
2948 { 0x20000000, "IN_MASK_ADD" },
2949 { 0x40000000, "IN_ISDIR" },
2950 { 0x80000000, "IN_ONESHOT" },
2951 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002952};
2953
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002954static const struct xlat inotify_init_flags[] = {
2955 { 0x00000800, "IN_NONBLOCK" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002956 { 0x00080000, "IN_CLOEXEC" },
2957 { 0, NULL }
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002958};
2959
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002960int
2961sys_inotify_add_watch(struct tcb *tcp)
2962{
2963 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002964 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002965 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002966 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002967 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002968 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2969 }
2970 return 0;
2971}
2972
2973int
2974sys_inotify_rm_watch(struct tcb *tcp)
2975{
2976 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002977 printfd(tcp, tcp->u_arg[0]);
2978 tprintf(", %ld", tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002979 }
2980 return 0;
2981}
Roland McGrath96a96612008-05-20 04:56:18 +00002982
2983int
Mark Wielaardbab89402010-03-21 14:41:26 +01002984sys_inotify_init1(struct tcb *tcp)
2985{
2986 if (entering(tcp))
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002987 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
Mark Wielaardbab89402010-03-21 14:41:26 +01002988 return 0;
2989}
2990
2991int
Roland McGrath96a96612008-05-20 04:56:18 +00002992sys_fallocate(struct tcb *tcp)
2993{
2994 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002995 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002996 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002997 tprints(", ");
Roland McGrath96a96612008-05-20 04:56:18 +00002998 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002999 argn = printllval(tcp, "%llu, ", 2); /* offset */
3000 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00003001 }
3002 return 0;
3003}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00003004#endif