blob: 1c830f6d83214a936e5428a77c863e2e2728597b [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>
Dmitry V. Levin88293652012-03-09 21:02:19 +000036#include <sys/swap.h>
Roland McGrathc531e572008-08-01 01:13:10 +000037
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 Akkerman76baf7c1999-02-19 00:21:36 +000044
Denys Vlasenko84703742012-02-25 02:38:52 +010045#ifdef LINUXSPARC
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000046struct stat {
47 unsigned short st_dev;
48 unsigned int st_ino;
49 unsigned short st_mode;
50 short st_nlink;
51 unsigned short st_uid;
52 unsigned short st_gid;
53 unsigned short st_rdev;
54 unsigned int st_size;
55 int st_atime;
56 unsigned int __unused1;
57 int st_mtime;
58 unsigned int __unused2;
59 int st_ctime;
60 unsigned int __unused3;
61 int st_blksize;
62 int st_blocks;
63 unsigned int __unused4[2];
64};
Denys Vlasenko84703742012-02-25 02:38:52 +010065# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +000066struct stat_sparc64 {
67 unsigned int st_dev;
68 unsigned long st_ino;
69 unsigned int st_mode;
70 unsigned int st_nlink;
71 unsigned int st_uid;
72 unsigned int st_gid;
73 unsigned int st_rdev;
74 long st_size;
75 long st_atime;
76 long st_mtime;
77 long st_ctime;
78 long st_blksize;
79 long st_blocks;
80 unsigned long __unused4[2];
81};
Denys Vlasenko84703742012-02-25 02:38:52 +010082# endif /* SPARC64 */
83# define stat kernel_stat
84# include <asm/stat.h>
85# undef stat
86#else
87# undef dev_t
88# undef ino_t
89# undef mode_t
90# undef nlink_t
91# undef uid_t
92# undef gid_t
93# undef off_t
94# undef loff_t
Wichert Akkerman5b4d1281999-07-09 00:32:54 +000095
Denys Vlasenko84703742012-02-25 02:38:52 +010096# define dev_t __kernel_dev_t
97# define ino_t __kernel_ino_t
98# define mode_t __kernel_mode_t
99# define nlink_t __kernel_nlink_t
100# define uid_t __kernel_uid_t
101# define gid_t __kernel_gid_t
102# define off_t __kernel_off_t
103# define loff_t __kernel_loff_t
Wichert Akkermana6013701999-07-08 14:00:58 +0000104
Denys Vlasenko84703742012-02-25 02:38:52 +0100105# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +0000106
Denys Vlasenko84703742012-02-25 02:38:52 +0100107# undef dev_t
108# undef ino_t
109# undef mode_t
110# undef nlink_t
111# undef uid_t
112# undef gid_t
113# undef off_t
114# undef loff_t
Wichert Akkerman5b4d1281999-07-09 00:32:54 +0000115
Denys Vlasenko84703742012-02-25 02:38:52 +0100116# define dev_t dev_t
117# define ino_t ino_t
118# define mode_t mode_t
119# define nlink_t nlink_t
120# define uid_t uid_t
121# define gid_t gid_t
122# define off_t off_t
123# define loff_t loff_t
124#endif
125
126#ifdef HPPA /* asm-parisc/stat.h defines stat64 */
127# undef stat64
128#endif
129#define stat libc_stat
130#define stat64 libc_stat64
131#include <sys/stat.h>
132#undef stat
133#undef stat64
134 /* These might be macros. */
135#undef st_atime
136#undef st_mtime
137#undef st_ctime
138#ifdef HPPA
139# define stat64 hpux_stat64
140#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000141
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000142#include <fcntl.h>
143
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000144#ifdef HAVE_SYS_VFS_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100145# include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000146#endif
147
Roland McGrath186c5ac2002-12-15 23:58:23 +0000148#ifdef HAVE_LINUX_XATTR_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100149# include <linux/xattr.h>
Denys Vlasenkoed720fd2012-02-25 02:24:03 +0100150#else
Denys Vlasenko84703742012-02-25 02:38:52 +0100151# define XATTR_CREATE 1
152# define XATTR_REPLACE 2
Roland McGrath186c5ac2002-12-15 23:58:23 +0000153#endif
154
Denys Vlasenko84703742012-02-25 02:38:52 +0100155#if _LFS64_LARGEFILE
Dmitry V. Levin1f336e52006-10-14 20:20:46 +0000156# ifdef HAVE_INTTYPES_H
157# include <inttypes.h>
158# else
159# define PRId64 "lld"
160# define PRIu64 "llu"
161# endif
162#endif
163
John Hughes70623be2001-03-08 13:59:00 +0000164#if HAVE_LONG_LONG_OFF_T
165/*
166 * Ugly hacks for systems that have typedef long long off_t
167 */
John Hughesb8c9f772001-03-07 16:53:07 +0000168
Denys Vlasenko84703742012-02-25 02:38:52 +0100169# define stat64 stat
170# define HAVE_STAT64 1 /* Ugly hack */
John Hughes70623be2001-03-08 13:59:00 +0000171
Denys Vlasenko84703742012-02-25 02:38:52 +0100172# define sys_stat64 sys_stat
173# define sys_fstat64 sys_fstat
174# define sys_lstat64 sys_lstat
175# define sys_lseek64 sys_lseek
176# define sys_truncate64 sys_truncate
177# define sys_ftruncate64 sys_ftruncate
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000178#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000179
180#ifdef MAJOR_IN_SYSMACROS
Denys Vlasenko84703742012-02-25 02:38:52 +0100181# include <sys/sysmacros.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000182#endif
183
184#ifdef MAJOR_IN_MKDEV
Denys Vlasenko84703742012-02-25 02:38:52 +0100185# include <sys/mkdev.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186#endif
187
188#ifdef HAVE_SYS_ASYNCH_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100189# include <sys/asynch.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000190#endif
191
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000192const struct xlat open_access_modes[] = {
193 { O_RDONLY, "O_RDONLY" },
194 { O_WRONLY, "O_WRONLY" },
195 { O_RDWR, "O_RDWR" },
196#ifdef O_ACCMODE
197 { O_ACCMODE, "O_ACCMODE" },
198#endif
199 { 0, NULL },
200};
201
202const struct xlat open_mode_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000203 { O_CREAT, "O_CREAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000204 { O_EXCL, "O_EXCL" },
205 { O_NOCTTY, "O_NOCTTY" },
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000206 { O_TRUNC, "O_TRUNC" },
207 { O_APPEND, "O_APPEND" },
208 { O_NONBLOCK, "O_NONBLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000209#ifdef O_SYNC
210 { O_SYNC, "O_SYNC" },
211#endif
212#ifdef O_ASYNC
213 { O_ASYNC, "O_ASYNC" },
214#endif
215#ifdef O_DSYNC
216 { O_DSYNC, "O_DSYNC" },
217#endif
218#ifdef O_RSYNC
219 { O_RSYNC, "O_RSYNC" },
220#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000221#if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000222 { O_NDELAY, "O_NDELAY" },
223#endif
224#ifdef O_PRIV
225 { O_PRIV, "O_PRIV" },
226#endif
227#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000228 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000229#endif
230#ifdef O_LARGEFILE
Roland McGrathfee836e2005-02-02 22:11:32 +0000231# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
232# undef O_LARGEFILE
233# ifdef SPARC64
234# define O_LARGEFILE 0x40000
235# elif defined X86_64 || defined S390X
236# define O_LARGEFILE 0100000
237# endif
238# endif
Roland McGrath663a8a02005-02-04 09:49:56 +0000239# ifdef O_LARGEFILE
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200240 { O_LARGEFILE, "O_LARGEFILE" },
Roland McGrath663a8a02005-02-04 09:49:56 +0000241# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000242#endif
243#ifdef O_DIRECTORY
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200244 { O_DIRECTORY, "O_DIRECTORY" },
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000245#endif
246#ifdef O_NOFOLLOW
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200247 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000248#endif
Roland McGrath1025c3e2005-05-09 07:40:35 +0000249#ifdef O_NOATIME
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200250 { O_NOATIME, "O_NOATIME" },
Roland McGrath1025c3e2005-05-09 07:40:35 +0000251#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000252#ifdef O_CLOEXEC
253 { O_CLOEXEC, "O_CLOEXEC" },
254#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000255#ifdef FNDELAY
256 { FNDELAY, "FNDELAY" },
257#endif
258#ifdef FAPPEND
259 { FAPPEND, "FAPPEND" },
260#endif
261#ifdef FMARK
262 { FMARK, "FMARK" },
263#endif
264#ifdef FDEFER
265 { FDEFER, "FDEFER" },
266#endif
267#ifdef FASYNC
268 { FASYNC, "FASYNC" },
269#endif
270#ifdef FSHLOCK
271 { FSHLOCK, "FSHLOCK" },
272#endif
273#ifdef FEXLOCK
274 { FEXLOCK, "FEXLOCK" },
275#endif
276#ifdef FCREAT
277 { FCREAT, "FCREAT" },
278#endif
279#ifdef FTRUNC
280 { FTRUNC, "FTRUNC" },
281#endif
282#ifdef FEXCL
283 { FEXCL, "FEXCL" },
284#endif
285#ifdef FNBIO
286 { FNBIO, "FNBIO" },
287#endif
288#ifdef FSYNC
289 { FSYNC, "FSYNC" },
290#endif
291#ifdef FNOCTTY
292 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000293#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000294#ifdef O_SHLOCK
295 { O_SHLOCK, "O_SHLOCK" },
296#endif
297#ifdef O_EXLOCK
298 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000299#endif
300 { 0, NULL },
301};
302
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000303#ifndef AT_FDCWD
304# define AT_FDCWD -100
305#endif
306
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000307/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
308 * extension to get the right value. We do this by declaring fd as int here.
309 */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000310static void
Dmitry V. Levin31382132011-03-04 05:08:02 +0300311print_dirfd(struct tcb *tcp, int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000312{
313 if (fd == AT_FDCWD)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200314 tprints("AT_FDCWD, ");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200315 else {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300316 printfd(tcp, fd);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200317 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300318 }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000319}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000320
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000321/*
322 * low bits of the open(2) flags define access mode,
323 * other bits are real flags.
324 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000325const char *
326sprint_open_modes(mode_t flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000327{
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100328 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000329 char *p;
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100330 char sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000331 const char *str;
332 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000333
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100334 sep = ' ';
335 p = stpcpy(outstr, "flags");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000336 str = xlookup(open_access_modes, flags & 3);
337 if (str) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100338 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200339 p = stpcpy(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000340 flags &= ~3;
341 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000342 return outstr;
343 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000344 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000345
346 for (x = open_mode_flags; x->str; x++) {
347 if ((flags & x->val) == x->val) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100348 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200349 p = stpcpy(p, x->str);
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000350 flags &= ~x->val;
351 if (!flags)
352 return outstr;
353 sep = '|';
354 }
355 }
356 /* flags is still nonzero */
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100357 *p++ = sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000358 sprintf(p, "%#x", flags);
359 return outstr;
360}
361
362void
363tprint_open_modes(mode_t flags)
364{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200365 tprints(sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000366}
367
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000368static int
369decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000370{
371 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000372 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200373 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000374 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000375 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000376 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000377 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000378 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000379 }
380 }
381 return 0;
382}
383
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000384int
385sys_open(struct tcb *tcp)
386{
387 return decode_open(tcp, 0);
388}
389
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000390int
391sys_openat(struct tcb *tcp)
392{
393 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300394 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000395 return decode_open(tcp, 1);
396}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000397
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000398#ifdef LINUXSPARC
Roland McGratha4d48532005-06-08 20:45:28 +0000399static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000400 { 0, "O_RDWR" },
401 { 1, "O_RDONLY" },
402 { 2, "O_WRONLY" },
403 { 0x80, "O_NONBLOCK" },
404 { 8, "O_APPEND" },
405 { 0x100, "O_CREAT" },
406 { 0x200, "O_TRUNC" },
407 { 0x400, "O_EXCL" },
408 { 0x800, "O_NOCTTY" },
409 { 0x10, "O_SYNC" },
410 { 0x40, "O_DSYNC" },
411 { 0x8000, "O_RSYNC" },
412 { 4, "O_NDELAY" },
413 { 0x1000, "O_PRIV" },
414 { 0, NULL },
415};
416
417int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000418solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000419{
420 if (entering(tcp)) {
421 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200422 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000423 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000424 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000425 if (tcp->u_arg[1] & 0x100) {
426 /* mode */
427 tprintf(", %#lo", tcp->u_arg[2]);
428 }
429 }
430 return 0;
431}
432
433#endif
434
435int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000436sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000437{
438 if (entering(tcp)) {
439 printpath(tcp, tcp->u_arg[0]);
440 tprintf(", %#lo", tcp->u_arg[1]);
441 }
442 return 0;
443}
444
Roland McGrathd9f816f2004-09-04 03:39:20 +0000445static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000446 { F_OK, "F_OK", },
447 { R_OK, "R_OK" },
448 { W_OK, "W_OK" },
449 { X_OK, "X_OK" },
450#ifdef EFF_ONLY_OK
451 { EFF_ONLY_OK, "EFF_ONLY_OK" },
452#endif
453#ifdef EX_OK
454 { EX_OK, "EX_OK" },
455#endif
456 { 0, NULL },
457};
458
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000459static int
460decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000461{
462 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000463 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200464 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000465 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000466 }
467 return 0;
468}
469
470int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000471sys_access(struct tcb *tcp)
472{
473 return decode_access(tcp, 0);
474}
475
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000476int
477sys_faccessat(struct tcb *tcp)
478{
479 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300480 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000481 return decode_access(tcp, 1);
482}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000483
484int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000485sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000486{
487 if (entering(tcp)) {
488 tprintf("%#lo", tcp->u_arg[0]);
489 }
490 return RVAL_OCTAL;
491}
492
Roland McGrathd9f816f2004-09-04 03:39:20 +0000493static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000494 { SEEK_SET, "SEEK_SET" },
495 { SEEK_CUR, "SEEK_CUR" },
496 { SEEK_END, "SEEK_END" },
497 { 0, NULL },
498};
499
John Hughes70623be2001-03-08 13:59:00 +0000500#ifndef HAVE_LONG_LONG_OFF_T
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100501#if defined(LINUX_MIPSN32)
Roland McGrath542c2c62008-05-20 01:11:56 +0000502int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000503sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000504{
505 long long offset;
506 int _whence;
507
508 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300509 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200510 tprints(", ");
Roland McGrath542c2c62008-05-20 01:11:56 +0000511 offset = tcp->ext_arg[1];
512 _whence = tcp->u_arg[2];
513 if (_whence == SEEK_SET)
514 tprintf("%llu, ", offset);
515 else
516 tprintf("%lld, ", offset);
517 printxval(whence, _whence, "SEEK_???");
518 }
519 return RVAL_UDECIMAL;
520}
521#else /* !LINUX_MIPSN32 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000523sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000524{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000525 off_t offset;
526 int _whence;
527
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000528 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300529 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200530 tprints(", ");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000531 offset = tcp->u_arg[1];
532 _whence = tcp->u_arg[2];
533 if (_whence == SEEK_SET)
534 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000535 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000536 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000537 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000538 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000539 return RVAL_UDECIMAL;
540}
Roland McGrath542c2c62008-05-20 01:11:56 +0000541#endif /* LINUX_MIPSN32 */
John Hughes5a826b82001-03-07 13:21:24 +0000542#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000543
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000544int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000545sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000546{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000547 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300548 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000549 /*
550 * This one call takes explicitly two 32-bit arguments hi, lo,
551 * rather than one 64-bit argument for which LONG_LONG works
552 * appropriate for the native byte order.
553 */
554 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300555 tprintf(", %llu, ",
556 ((long long int) tcp->u_arg[1]) << 32 |
557 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000558 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300559 tprintf(", %lld, ",
560 ((long long int) tcp->u_arg[1]) << 32 |
561 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000562 }
563 else {
564 long long int off;
565 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
566 tprintf("%#lx, ", tcp->u_arg[3]);
567 else
568 tprintf("[%llu], ", off);
569 printxval(whence, tcp->u_arg[4], "SEEK_???");
570 }
571 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000572}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000573
574int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000575sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000576{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000577 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100578 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300579 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200580 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100581 argn = printllval(tcp, "%lld", 1);
582 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000583 }
584 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000585}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000586
John Hughes70623be2001-03-08 13:59:00 +0000587#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000588int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000589sys_lseek64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +0000590{
591 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100592 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300593 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200594 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000595 if (tcp->u_arg[3] == SEEK_SET)
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100596 argn = printllval(tcp, "%llu, ", 1);
John Hughesbdf48f52001-03-06 15:08:09 +0000597 else
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100598 argn = printllval(tcp, "%lld, ", 1);
599 printxval(whence, tcp->u_arg[argn], "SEEK_???");
John Hughesbdf48f52001-03-06 15:08:09 +0000600 }
601 return RVAL_LUDECIMAL;
602}
603#endif
604
John Hughes70623be2001-03-08 13:59:00 +0000605#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000606int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000607sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000608{
609 if (entering(tcp)) {
610 printpath(tcp, tcp->u_arg[0]);
611 tprintf(", %lu", tcp->u_arg[1]);
612 }
613 return 0;
614}
John Hughes5a826b82001-03-07 13:21:24 +0000615#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000616
John Hughes70623be2001-03-08 13:59:00 +0000617#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000618int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000619sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000620{
621 if (entering(tcp)) {
622 printpath(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100623 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000624 }
625 return 0;
626}
627#endif
628
John Hughes70623be2001-03-08 13:59:00 +0000629#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000630int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000631sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000632{
633 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300634 printfd(tcp, tcp->u_arg[0]);
635 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000636 }
637 return 0;
638}
John Hughes5a826b82001-03-07 13:21:24 +0000639#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000640
John Hughes70623be2001-03-08 13:59:00 +0000641#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000642int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000643sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000644{
645 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300646 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200647 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100648 printllval(tcp, "%llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000649 }
650 return 0;
651}
652#endif
653
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000654/* several stats */
655
Roland McGrathd9f816f2004-09-04 03:39:20 +0000656static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000657 { S_IFREG, "S_IFREG" },
658 { S_IFSOCK, "S_IFSOCK" },
659 { S_IFIFO, "S_IFIFO" },
660 { S_IFLNK, "S_IFLNK" },
661 { S_IFDIR, "S_IFDIR" },
662 { S_IFBLK, "S_IFBLK" },
663 { S_IFCHR, "S_IFCHR" },
664 { 0, NULL },
665};
666
Roland McGrathf9c49b22004-10-06 22:11:54 +0000667static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000668sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000669{
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100670 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
671 + sizeof(int)*3
672 + /*paranoia:*/ 8];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000673 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000674
675 if ((mode & S_IFMT) == 0)
676 s = "";
677 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
678 sprintf(buf, "%#o", mode);
679 return buf;
680 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100681 s = buf + sprintf(buf, "%s%s%s%s", s,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000682 (mode & S_ISUID) ? "|S_ISUID" : "",
683 (mode & S_ISGID) ? "|S_ISGID" : "",
684 (mode & S_ISVTX) ? "|S_ISVTX" : "");
685 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
686 if (mode)
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100687 sprintf((char*)s, "|%#o", mode);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000688 s = (*buf == '|') ? buf + 1 : buf;
689 return *s ? s : "0";
690}
691
692static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000693sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000694{
695 struct tm *tmp;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100696 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000697
698 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000699 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000700 return buf;
701 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200702 tmp = localtime(&t);
703 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000704 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
705 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
706 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
707 else
708 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
709
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000710 return buf;
711}
712
713#ifdef LINUXSPARC
714typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000715 int tv_sec;
716 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000717} timestruct_t;
718
719struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000720 unsigned st_dev;
721 int st_pad1[3]; /* network id */
722 unsigned st_ino;
723 unsigned st_mode;
724 unsigned st_nlink;
725 unsigned st_uid;
726 unsigned st_gid;
727 unsigned st_rdev;
728 int st_pad2[2];
729 int st_size;
730 int st_pad3; /* st_size, off_t expansion */
731 timestruct_t st_atime;
732 timestruct_t st_mtime;
733 timestruct_t st_ctime;
734 int st_blksize;
735 int st_blocks;
736 char st_fstype[16];
737 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000738};
739
740static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000741printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000742{
743 struct solstat statbuf;
744
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000745 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200746 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000747 return;
748 }
749 if (!abbrev(tcp)) {
750 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
751 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
752 (unsigned long) (statbuf.st_dev & 0x3ffff),
753 (unsigned long) statbuf.st_ino,
754 sprintmode(statbuf.st_mode));
755 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
756 (unsigned long) statbuf.st_nlink,
757 (unsigned long) statbuf.st_uid,
758 (unsigned long) statbuf.st_gid);
759 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
760 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
761 }
762 else
763 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
764 switch (statbuf.st_mode & S_IFMT) {
765 case S_IFCHR: case S_IFBLK:
766 tprintf("st_rdev=makedev(%lu, %lu), ",
767 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
768 (unsigned long) (statbuf.st_rdev & 0x3ffff));
769 break;
770 default:
771 tprintf("st_size=%u, ", statbuf.st_size);
772 break;
773 }
774 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000775 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
776 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
777 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000778 }
779 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200780 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000781}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000782
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100783#if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000784static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000785printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000786{
787 struct stat_sparc64 statbuf;
788
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000789 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200790 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000791 return;
792 }
793
794 if (!abbrev(tcp)) {
795 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
796 (unsigned long) major(statbuf.st_dev),
797 (unsigned long) minor(statbuf.st_dev),
798 (unsigned long) statbuf.st_ino,
799 sprintmode(statbuf.st_mode));
800 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
801 (unsigned long) statbuf.st_nlink,
802 (unsigned long) statbuf.st_uid,
803 (unsigned long) statbuf.st_gid);
804 tprintf("st_blksize=%lu, ",
805 (unsigned long) statbuf.st_blksize);
806 tprintf("st_blocks=%lu, ",
807 (unsigned long) statbuf.st_blocks);
808 }
809 else
810 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
811 switch (statbuf.st_mode & S_IFMT) {
812 case S_IFCHR: case S_IFBLK:
813 tprintf("st_rdev=makedev(%lu, %lu), ",
814 (unsigned long) major(statbuf.st_rdev),
815 (unsigned long) minor(statbuf.st_rdev));
816 break;
817 default:
818 tprintf("st_size=%lu, ", statbuf.st_size);
819 break;
820 }
821 if (!abbrev(tcp)) {
822 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
823 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100824 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000825 }
826 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200827 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000828}
829#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000830#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000831
Denys Vlasenko84703742012-02-25 02:38:52 +0100832#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200833struct stat_powerpc32 {
834 unsigned int st_dev;
835 unsigned int st_ino;
836 unsigned int st_mode;
837 unsigned short st_nlink;
838 unsigned int st_uid;
839 unsigned int st_gid;
840 unsigned int st_rdev;
841 unsigned int st_size;
842 unsigned int st_blksize;
843 unsigned int st_blocks;
844 unsigned int st_atime;
845 unsigned int st_atime_nsec;
846 unsigned int st_mtime;
847 unsigned int st_mtime_nsec;
848 unsigned int st_ctime;
849 unsigned int st_ctime_nsec;
850 unsigned int __unused4;
851 unsigned int __unused5;
852};
853
854static void
855printstat_powerpc32(struct tcb *tcp, long addr)
856{
857 struct stat_powerpc32 statbuf;
858
859 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200860 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200861 return;
862 }
863
864 if (!abbrev(tcp)) {
865 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
866 major(statbuf.st_dev), minor(statbuf.st_dev),
867 statbuf.st_ino,
868 sprintmode(statbuf.st_mode));
869 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
870 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
871 tprintf("st_blksize=%u, ", statbuf.st_blksize);
872 tprintf("st_blocks=%u, ", statbuf.st_blocks);
873 }
874 else
875 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
876 switch (statbuf.st_mode & S_IFMT) {
877 case S_IFCHR: case S_IFBLK:
878 tprintf("st_rdev=makedev(%lu, %lu), ",
879 (unsigned long) major(statbuf.st_rdev),
880 (unsigned long) minor(statbuf.st_rdev));
881 break;
882 default:
883 tprintf("st_size=%u, ", statbuf.st_size);
884 break;
885 }
886 if (!abbrev(tcp)) {
887 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
888 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100889 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200890 }
891 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200892 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200893}
Denys Vlasenko84703742012-02-25 02:38:52 +0100894#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200895
Roland McGratha4d48532005-06-08 20:45:28 +0000896static const struct xlat fileflags[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000897 { 0, NULL },
898};
899
John Hughes70623be2001-03-08 13:59:00 +0000900#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000901static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000902realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000903{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000904 if (!abbrev(tcp)) {
905 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
906 (unsigned long) major(statbuf->st_dev),
907 (unsigned long) minor(statbuf->st_dev),
908 (unsigned long) statbuf->st_ino,
909 sprintmode(statbuf->st_mode));
910 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
911 (unsigned long) statbuf->st_nlink,
912 (unsigned long) statbuf->st_uid,
913 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000914#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000915 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
916#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000917#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000918 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
919#endif
920 }
921 else
922 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
923 switch (statbuf->st_mode & S_IFMT) {
924 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000925#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000926 tprintf("st_rdev=makedev(%lu, %lu), ",
927 (unsigned long) major(statbuf->st_rdev),
928 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000929#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000930 tprintf("st_size=makedev(%lu, %lu), ",
931 (unsigned long) major(statbuf->st_size),
932 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000933#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000934 break;
935 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000936 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000937 break;
938 }
939 if (!abbrev(tcp)) {
940 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
941 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
942 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000943#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200944 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000945 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000946#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000947#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000948 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
949#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000950#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000951 tprintf(", st_level=%ld", statbuf->st_level);
952#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000953#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000954 tprintf(", st_fstype=%.*s",
955 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
956#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000957#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000958 tprintf(", st_gen=%u", statbuf->st_gen);
959#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200960 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000961 }
962 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200963 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000964}
965
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000966static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000967printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000968{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000969 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000970
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000971 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200972 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000973 return;
974 }
975 if (syserror(tcp) || !verbose(tcp)) {
976 tprintf("%#lx", addr);
977 return;
978 }
979
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000980#ifdef LINUXSPARC
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000981 if (current_personality == 1) {
982 printstatsol(tcp, addr);
983 return;
984 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000985#ifdef SPARC64
986 else if (current_personality == 2) {
987 printstat_sparc64(tcp, addr);
988 return;
989 }
990#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000991#endif /* LINUXSPARC */
992
Denys Vlasenko84703742012-02-25 02:38:52 +0100993#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200994 if (current_personality == 1) {
995 printstat_powerpc32(tcp, addr);
996 return;
997 }
998#endif
999
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001000 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001001 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001002 return;
1003 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001004
1005 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001006}
John Hughes70623be2001-03-08 13:59:00 +00001007#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001008
Denys Vlasenko84703742012-02-25 02:38:52 +01001009#if !defined HAVE_STAT64 && defined X86_64
Roland McGrathe6d0f712007-08-07 01:22:49 +00001010/*
1011 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1012 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1013 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1014 * __GNUC__ is needed for the required __attribute__ below.
1015 */
1016struct stat64 {
1017 unsigned long long st_dev;
1018 unsigned char __pad0[4];
1019 unsigned int __st_ino;
1020 unsigned int st_mode;
1021 unsigned int st_nlink;
1022 unsigned int st_uid;
1023 unsigned int st_gid;
1024 unsigned long long st_rdev;
1025 unsigned char __pad3[4];
1026 long long st_size;
1027 unsigned int st_blksize;
1028 unsigned long long st_blocks;
1029 unsigned int st_atime;
1030 unsigned int st_atime_nsec;
1031 unsigned int st_mtime;
1032 unsigned int st_mtime_nsec;
1033 unsigned int st_ctime;
1034 unsigned int st_ctime_nsec;
1035 unsigned long long st_ino;
1036} __attribute__((packed));
1037# define HAVE_STAT64 1
1038# define STAT64_SIZE 96
1039#endif
1040
Wichert Akkermanc7926982000-04-10 22:22:31 +00001041#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001042static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001043printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001044{
1045 struct stat64 statbuf;
1046
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001047#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001048 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1049#endif
1050
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001051 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001052 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001053 return;
1054 }
1055 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001056 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001057 return;
1058 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001059
1060#ifdef LINUXSPARC
1061 if (current_personality == 1) {
1062 printstatsol(tcp, addr);
1063 return;
1064 }
1065# ifdef SPARC64
1066 else if (current_personality == 2) {
1067 printstat_sparc64(tcp, addr);
1068 return;
1069 }
1070# endif
1071#endif /* LINUXSPARC */
1072
Denys Vlasenko84703742012-02-25 02:38:52 +01001073#if defined X86_64
Andreas Schwab61b74352009-10-16 11:37:13 +02001074 if (current_personality == 0) {
1075 printstat(tcp, addr);
1076 return;
1077 }
1078#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +00001079
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001080 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001081 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001082 return;
1083 }
1084
1085 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001086#ifdef HAVE_LONG_LONG
1087 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1088#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001089 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001090#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001091 (unsigned long) major(statbuf.st_dev),
1092 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001093#ifdef HAVE_LONG_LONG
1094 (unsigned long long) statbuf.st_ino,
1095#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001096 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001097#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001098 sprintmode(statbuf.st_mode));
1099 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1100 (unsigned long) statbuf.st_nlink,
1101 (unsigned long) statbuf.st_uid,
1102 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001103#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001104 tprintf("st_blksize=%lu, ",
1105 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001106#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1107#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001108 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001109#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001110 }
1111 else
1112 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1113 switch (statbuf.st_mode & S_IFMT) {
1114 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001115#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001116 tprintf("st_rdev=makedev(%lu, %lu), ",
1117 (unsigned long) major(statbuf.st_rdev),
1118 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001119#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001120 tprintf("st_size=makedev(%lu, %lu), ",
1121 (unsigned long) major(statbuf.st_size),
1122 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001123#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001124 break;
1125 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001126#ifdef HAVE_LONG_LONG
1127 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1128#else
1129 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1130#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001131 break;
1132 }
1133 if (!abbrev(tcp)) {
1134 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1135 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001136 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001137#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001138 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001139 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001140#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001141#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001142 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1143#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001144#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001145 tprintf(", st_level=%ld", statbuf.st_level);
1146#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001147#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001148 tprintf(", st_fstype=%.*s",
1149 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1150#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001151#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001152 tprintf(", st_gen=%u", statbuf.st_gen);
1153#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001154 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001155 }
1156 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001157 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001158}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001159#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001160
Denys Vlasenko84703742012-02-25 02:38:52 +01001161#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001162static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001163convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001164{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001165 newbuf->st_dev = oldbuf->st_dev;
1166 newbuf->st_ino = oldbuf->st_ino;
1167 newbuf->st_mode = oldbuf->st_mode;
1168 newbuf->st_nlink = oldbuf->st_nlink;
1169 newbuf->st_uid = oldbuf->st_uid;
1170 newbuf->st_gid = oldbuf->st_gid;
1171 newbuf->st_rdev = oldbuf->st_rdev;
1172 newbuf->st_size = oldbuf->st_size;
1173 newbuf->st_atime = oldbuf->st_atime;
1174 newbuf->st_mtime = oldbuf->st_mtime;
1175 newbuf->st_ctime = oldbuf->st_ctime;
1176 newbuf->st_blksize = 0; /* not supported in old_stat */
1177 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001178}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001179
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001180static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001181printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001182{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001183 struct __old_kernel_stat statbuf;
1184 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001185
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001186 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001187 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001188 return;
1189 }
1190 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001191 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001192 return;
1193 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001194
Denys Vlasenko84703742012-02-25 02:38:52 +01001195# ifdef LINUXSPARC
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001196 if (current_personality == 1) {
1197 printstatsol(tcp, addr);
1198 return;
1199 }
Denys Vlasenko84703742012-02-25 02:38:52 +01001200# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001201
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001202 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001203 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001204 return;
1205 }
1206
1207 convertoldstat(&statbuf, &newstatbuf);
1208 realprintstat(tcp, &newstatbuf);
1209}
Denys Vlasenko84703742012-02-25 02:38:52 +01001210#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001211
John Hughes70623be2001-03-08 13:59:00 +00001212#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001213int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001214sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001215{
1216 if (entering(tcp)) {
1217 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001218 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001219 } else {
1220 printstat(tcp, tcp->u_arg[1]);
1221 }
1222 return 0;
1223}
John Hughesb8c9f772001-03-07 16:53:07 +00001224#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001225
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001226int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001227sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001228{
1229#ifdef HAVE_STAT64
1230 if (entering(tcp)) {
1231 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001232 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001233 } else {
1234 printstat64(tcp, tcp->u_arg[1]);
1235 }
1236 return 0;
1237#else
1238 return printargs(tcp);
1239#endif
1240}
1241
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001242static const struct xlat fstatatflags[] = {
1243#ifndef AT_SYMLINK_NOFOLLOW
1244# define AT_SYMLINK_NOFOLLOW 0x100
1245#endif
1246 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1247 { 0, NULL },
1248};
Roland McGrath6afc5652007-07-24 01:57:11 +00001249#define utimensatflags fstatatflags
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001250
1251int
1252sys_newfstatat(struct tcb *tcp)
1253{
1254 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001255 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001256 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001257 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001258 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001259#ifdef POWERPC64
1260 if (current_personality == 0)
1261 printstat(tcp, tcp->u_arg[2]);
1262 else
1263 printstat64(tcp, tcp->u_arg[2]);
1264#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001265 printstat64(tcp, tcp->u_arg[2]);
1266#else
1267 printstat(tcp, tcp->u_arg[2]);
1268#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001269 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001270 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1271 }
1272 return 0;
1273}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001274
Denys Vlasenko84703742012-02-25 02:38:52 +01001275#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001276int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001277sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001278{
1279 if (entering(tcp)) {
1280 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001281 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001282 } else {
1283 printoldstat(tcp, tcp->u_arg[1]);
1284 }
1285 return 0;
1286}
Denys Vlasenko84703742012-02-25 02:38:52 +01001287#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001288
John Hughes70623be2001-03-08 13:59:00 +00001289#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001290int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001291sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001293 if (entering(tcp)) {
1294 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001295 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001296 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001297 printstat(tcp, tcp->u_arg[1]);
1298 }
1299 return 0;
1300}
John Hughesb8c9f772001-03-07 16:53:07 +00001301#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001302
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001303int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001304sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001305{
1306#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001307 if (entering(tcp)) {
1308 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001309 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001310 } else {
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001311 printstat64(tcp, tcp->u_arg[1]);
1312 }
1313 return 0;
1314#else
1315 return printargs(tcp);
1316#endif
1317}
1318
Denys Vlasenko84703742012-02-25 02:38:52 +01001319#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001320int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001321sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001322{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001323 if (entering(tcp)) {
1324 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001325 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001326 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001327 printoldstat(tcp, tcp->u_arg[1]);
1328 }
1329 return 0;
1330}
Denys Vlasenko84703742012-02-25 02:38:52 +01001331#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001332
John Hughes70623be2001-03-08 13:59:00 +00001333#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001334int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001335sys_lstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001336{
1337 if (entering(tcp)) {
1338 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001339 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001340 } else {
1341 printstat(tcp, tcp->u_arg[1]);
1342 }
1343 return 0;
1344}
John Hughesb8c9f772001-03-07 16:53:07 +00001345#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001346
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001347int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001348sys_lstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001349{
1350#ifdef HAVE_STAT64
1351 if (entering(tcp)) {
1352 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001353 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001354 } else {
1355 printstat64(tcp, tcp->u_arg[1]);
1356 }
1357 return 0;
1358#else
1359 return printargs(tcp);
1360#endif
1361}
1362
Denys Vlasenko84703742012-02-25 02:38:52 +01001363#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001364int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001365sys_oldlstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001366{
1367 if (entering(tcp)) {
1368 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001369 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001370 } else {
1371 printoldstat(tcp, tcp->u_arg[1]);
1372 }
1373 return 0;
1374}
Denys Vlasenko84703742012-02-25 02:38:52 +01001375#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001376
Denys Vlasenko84703742012-02-25 02:38:52 +01001377#if defined(LINUXSPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001378
1379int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001380sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001381{
1382 if (entering(tcp)) {
1383 tprintf("%ld, ", tcp->u_arg[0]);
1384 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001385 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001386 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001387# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001388 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001389 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001390 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001391# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001392 printstat(tcp, tcp->u_arg[2]);
1393 }
1394 return 0;
1395}
1396
1397int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001398sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001399{
1400 if (entering(tcp))
1401 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1402 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001403# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001404 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001405 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001406 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001407# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001408 printstat(tcp, tcp->u_arg[2]);
1409 }
1410 return 0;
1411}
1412
1413int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001414sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001415{
1416 if (entering(tcp)) {
1417 tprintf("%ld, ", tcp->u_arg[0]);
1418 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001419 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001420 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001421# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001422 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001423 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001424 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001425# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001426 printstat(tcp, tcp->u_arg[2]);
1427 }
1428 return 0;
1429}
1430
1431int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001432sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001433{
1434 int mode = tcp->u_arg[2];
1435
1436 if (entering(tcp)) {
1437 tprintf("%ld, ", tcp->u_arg[0]);
1438 printpath(tcp, tcp->u_arg[1]);
1439 tprintf(", %s", sprintmode(mode));
1440 switch (mode & S_IFMT) {
1441 case S_IFCHR: case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001442 tprintf(", makedev(%lu, %lu)",
1443 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1444 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001445 break;
1446 default:
1447 break;
1448 }
1449 }
1450 return 0;
1451}
1452
Denys Vlasenko84703742012-02-25 02:38:52 +01001453# ifdef HAVE_SYS_ACL_H
Wichert Akkerman8829a551999-06-11 13:18:40 +00001454
Denys Vlasenko84703742012-02-25 02:38:52 +01001455# include <sys/acl.h>
Wichert Akkerman8829a551999-06-11 13:18:40 +00001456
Roland McGratha4d48532005-06-08 20:45:28 +00001457static const struct xlat aclcmds[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001458# ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001459 { SETACL, "SETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001460# endif
1461# ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001462 { GETACL, "GETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001463# endif
1464# ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001465 { GETACLCNT, "GETACLCNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001466# endif
1467# ifdef ACL_GET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001468 { ACL_GET, "ACL_GET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001469# endif
1470# ifdef ACL_SET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001471 { ACL_SET, "ACL_SET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001472# endif
1473# ifdef ACL_CNT
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001474 { ACL_CNT, "ACL_CNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001475# endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001476 { 0, NULL },
1477};
1478
1479int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001480sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001481{
1482 if (entering(tcp)) {
1483 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001484 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001485 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1486 tprintf(", %ld", tcp->u_arg[2]);
1487 /*
1488 * FIXME - dump out the list of aclent_t's pointed to
1489 * by "tcp->u_arg[3]" if it's not NULL.
1490 */
1491 if (tcp->u_arg[3])
1492 tprintf(", %#lx", tcp->u_arg[3]);
1493 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001494 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001495 }
1496 return 0;
1497}
1498
Wichert Akkerman8829a551999-06-11 13:18:40 +00001499int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001500sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001501{
1502 if (entering(tcp)) {
1503 tprintf("%ld, ", tcp->u_arg[0]);
1504 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1505 tprintf(", %ld", tcp->u_arg[2]);
1506 /*
1507 * FIXME - dump out the list of aclent_t's pointed to
1508 * by "tcp->u_arg[3]" if it's not NULL.
1509 */
1510 if (tcp->u_arg[3])
1511 tprintf(", %#lx", tcp->u_arg[3]);
1512 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001513 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001514 }
1515 return 0;
1516}
1517
Roland McGratha4d48532005-06-08 20:45:28 +00001518static const struct xlat aclipc[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001519# ifdef IPC_SHM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001520 { IPC_SHM, "IPC_SHM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001521# endif
1522# ifdef IPC_SEM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001523 { IPC_SEM, "IPC_SEM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001524# endif
1525# ifdef IPC_MSG
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001526 { IPC_MSG, "IPC_MSG" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001527# endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001528 { 0, NULL },
1529};
1530
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001531int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001532sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001533{
1534 if (entering(tcp)) {
1535 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1536 tprintf(", %#lx, ", tcp->u_arg[1]);
1537 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1538 tprintf(", %ld", tcp->u_arg[3]);
1539 /*
1540 * FIXME - dump out the list of aclent_t's pointed to
1541 * by "tcp->u_arg[4]" if it's not NULL.
1542 */
1543 if (tcp->u_arg[4])
1544 tprintf(", %#lx", tcp->u_arg[4]);
1545 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001546 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001547 }
1548 return 0;
1549}
1550
Denys Vlasenko84703742012-02-25 02:38:52 +01001551# endif /* HAVE_SYS_ACL_H */
Wichert Akkerman8829a551999-06-11 13:18:40 +00001552
Denys Vlasenko84703742012-02-25 02:38:52 +01001553#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001554
Roland McGrathd9f816f2004-09-04 03:39:20 +00001555static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001556 { 0x73757245, "CODA_SUPER_MAGIC" },
1557 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1558 { 0x1373, "DEVFS_SUPER_MAGIC" },
1559 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1560 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001561 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1562 { 0xef53, "EXT2_SUPER_MAGIC" },
1563 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001564 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001565 { 0x9660, "ISOFS_SUPER_MAGIC" },
1566 { 0x137f, "MINIX_SUPER_MAGIC" },
1567 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001568 { 0x2468, "MINIX2_SUPER_MAGIC" },
1569 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001570 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001571 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001572 { 0x6969, "NFS_SUPER_MAGIC" },
1573 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001574 { 0x002f, "QNX4_SUPER_MAGIC" },
1575 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1576 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1577 { 0x517b, "SMB_SUPER_MAGIC" },
1578 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1579 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1580 { 0x00011954, "UFS_MAGIC" },
1581 { 0x54190100, "UFS_CIGAM" },
1582 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001583 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001584 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001585 { 0, NULL },
1586};
1587
Roland McGrathf9c49b22004-10-06 22:11:54 +00001588static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001589sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001590{
1591 static char buf[32];
Roland McGrathf9c49b22004-10-06 22:11:54 +00001592 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001593
1594 s = xlookup(fsmagic, magic);
1595 if (s) {
1596 sprintf(buf, "\"%s\"", s);
1597 return buf;
1598 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001599 sprintf(buf, "%#x", magic);
1600 return buf;
1601}
1602
1603static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001604printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001605{
1606 struct statfs statbuf;
1607
1608 if (syserror(tcp) || !verbose(tcp)) {
1609 tprintf("%#lx", addr);
1610 return;
1611 }
1612 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001613 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001614 return;
1615 }
1616#ifdef ALPHA
1617
1618 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1619 sprintfstype(statbuf.f_type),
1620 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001621 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001622 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001623 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1624 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001625#else /* !ALPHA */
1626 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1627 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001628 (unsigned long)statbuf.f_bsize,
1629 (unsigned long)statbuf.f_blocks,
1630 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001631 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1632 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001633 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001634 (unsigned long)statbuf.f_ffree,
1635 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001636 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001637#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001638#ifdef _STATFS_F_FRSIZE
1639 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1640#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001641 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001642}
1643
1644int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001645sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001646{
1647 if (entering(tcp)) {
1648 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001649 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001650 } else {
1651 printstatfs(tcp, tcp->u_arg[1]);
1652 }
1653 return 0;
1654}
1655
1656int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001657sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001658{
1659 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001660 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001661 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001662 } else {
1663 printstatfs(tcp, tcp->u_arg[1]);
1664 }
1665 return 0;
1666}
1667
Denys Vlasenko84703742012-02-25 02:38:52 +01001668#if defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001669static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001670printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001671{
1672 struct statfs64 statbuf;
1673
1674 if (syserror(tcp) || !verbose(tcp)) {
1675 tprintf("%#lx", addr);
1676 return;
1677 }
1678 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001679 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001680 return;
1681 }
Roland McGrath08738432005-06-03 02:40:39 +00001682 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001683 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001684 (unsigned long long)statbuf.f_bsize,
1685 (unsigned long long)statbuf.f_blocks,
1686 (unsigned long long)statbuf.f_bfree);
1687 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1688 (unsigned long long)statbuf.f_bavail,
1689 (unsigned long long)statbuf.f_files,
1690 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001691 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1692 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001693#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001694 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001695#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001696#ifdef _STATFS_F_FLAGS
1697 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1698#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001699 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001700}
1701
Andreas Schwab7d558012012-01-17 18:14:22 +01001702struct compat_statfs64 {
1703 uint32_t f_type;
1704 uint32_t f_bsize;
1705 uint64_t f_blocks;
1706 uint64_t f_bfree;
1707 uint64_t f_bavail;
1708 uint64_t f_files;
1709 uint64_t f_ffree;
1710 fsid_t f_fsid;
1711 uint32_t f_namelen;
1712 uint32_t f_frsize;
1713 uint32_t f_flags;
1714 uint32_t f_spare[4];
1715}
1716#if defined(X86_64) || defined(IA64)
1717 __attribute__ ((packed, aligned(4)))
1718#endif
1719;
1720
1721static void
1722printcompat_statfs64(struct tcb *tcp, long addr)
1723{
1724 struct compat_statfs64 statbuf;
1725
1726 if (syserror(tcp) || !verbose(tcp)) {
1727 tprintf("%#lx", addr);
1728 return;
1729 }
1730 if (umove(tcp, addr, &statbuf) < 0) {
1731 tprints("{...}");
1732 return;
1733 }
1734 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1735 sprintfstype(statbuf.f_type),
1736 (unsigned long)statbuf.f_bsize,
1737 (unsigned long long)statbuf.f_blocks,
1738 (unsigned long long)statbuf.f_bfree);
1739 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1740 (unsigned long long)statbuf.f_bavail,
1741 (unsigned long long)statbuf.f_files,
1742 (unsigned long long)statbuf.f_ffree,
1743 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1744 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1745 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001746 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
Andreas Schwab7d558012012-01-17 18:14:22 +01001747}
1748
Roland McGrathab147c52003-07-17 09:03:02 +00001749int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001750sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001751{
1752 if (entering(tcp)) {
1753 printpath(tcp, tcp->u_arg[0]);
1754 tprintf(", %lu, ", tcp->u_arg[1]);
1755 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001756 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001757 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001758 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1759 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001760 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001761 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001762 }
1763 return 0;
1764}
1765
1766int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001767sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001768{
1769 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001770 printfd(tcp, tcp->u_arg[0]);
1771 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001772 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001773 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001774 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001775 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1776 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001777 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001778 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001779 }
1780 return 0;
1781}
1782#endif
1783
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001784#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001785int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001786osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001787{
1788 if (entering(tcp)) {
1789 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001790 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001791 } else {
1792 printstatfs(tcp, tcp->u_arg[1]);
1793 tprintf(", %lu", tcp->u_arg[2]);
1794 }
1795 return 0;
1796}
1797
1798int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001799osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001800{
1801 if (entering(tcp)) {
1802 tprintf("%lu, ", tcp->u_arg[0]);
1803 } else {
1804 printstatfs(tcp, tcp->u_arg[1]);
1805 tprintf(", %lu", tcp->u_arg[2]);
1806 }
1807 return 0;
1808}
Denys Vlasenko84703742012-02-25 02:38:52 +01001809#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001810
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001811/* directory */
1812int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001813sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001814{
1815 if (entering(tcp)) {
1816 printpath(tcp, tcp->u_arg[0]);
1817 }
1818 return 0;
1819}
1820
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001821static int
1822decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001823{
1824 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001825 printpath(tcp, tcp->u_arg[offset]);
1826 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001827 }
1828 return 0;
1829}
1830
1831int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001832sys_mkdir(struct tcb *tcp)
1833{
1834 return decode_mkdir(tcp, 0);
1835}
1836
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001837int
1838sys_mkdirat(struct tcb *tcp)
1839{
1840 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001841 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001842 return decode_mkdir(tcp, 1);
1843}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001844
1845int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001846sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001847{
1848 if (entering(tcp)) {
1849 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001850 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001851 printpath(tcp, tcp->u_arg[1]);
1852 }
1853 return 0;
1854}
1855
Dmitry V. Levin371e1532012-03-13 23:16:37 +00001856#ifndef AT_SYMLINK_FOLLOW
1857# define AT_SYMLINK_FOLLOW 0x400
1858#endif
1859#ifndef AT_EMPTY_PATH
1860# define AT_EMPTY_PATH 0x1000
1861#endif
1862
1863static const struct xlat linkat_flags[] = {
1864 { AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" },
1865 { AT_EMPTY_PATH, "AT_EMPTY_PATH" },
1866 { 0, NULL }
1867};
1868
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001869int
1870sys_linkat(struct tcb *tcp)
1871{
1872 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001873 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001874 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001875 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001876 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001877 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001878 tprints(", ");
Dmitry V. Levin371e1532012-03-13 23:16:37 +00001879 printflags(linkat_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001880 }
1881 return 0;
1882}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001883
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001884static const struct xlat unlinkatflags[] = {
1885#ifndef AT_REMOVEDIR
1886# define AT_REMOVEDIR 0x200
1887#endif
1888 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1889 { 0, NULL },
1890};
1891
1892int
1893sys_unlinkat(struct tcb *tcp)
1894{
1895 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001896 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001897 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001898 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001899 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1900 }
1901 return 0;
1902}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001903
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001904int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001905sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001906{
1907 if (entering(tcp)) {
1908 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001909 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001910 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001911 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001912 }
1913 return 0;
1914}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001915
1916static int
1917decode_readlink(struct tcb *tcp, int offset)
1918{
1919 if (entering(tcp)) {
1920 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001921 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001922 } else {
1923 if (syserror(tcp))
1924 tprintf("%#lx", tcp->u_arg[offset + 1]);
1925 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001926 /* Used to use printpathn(), but readlink
1927 * neither includes NUL in the returned count,
1928 * nor actually writes it into memory.
1929 * printpathn() would decide on printing
1930 * "..." continuation based on garbage
1931 * past return buffer's end.
1932 */
1933 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001934 tprintf(", %lu", tcp->u_arg[offset + 2]);
1935 }
1936 return 0;
1937}
1938
1939int
1940sys_readlink(struct tcb *tcp)
1941{
1942 return decode_readlink(tcp, 0);
1943}
1944
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001945int
1946sys_readlinkat(struct tcb *tcp)
1947{
1948 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001949 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001950 return decode_readlink(tcp, 1);
1951}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001952
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001953int
1954sys_renameat(struct tcb *tcp)
1955{
1956 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001957 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001958 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001959 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001960 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001961 printpath(tcp, tcp->u_arg[3]);
1962 }
1963 return 0;
1964}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001965
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001966int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001967sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001968{
1969 if (entering(tcp)) {
1970 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001971 printuid(", ", tcp->u_arg[1]);
1972 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001973 }
1974 return 0;
1975}
1976
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001977int
1978sys_fchownat(struct tcb *tcp)
1979{
1980 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001981 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001982 printpath(tcp, tcp->u_arg[1]);
1983 printuid(", ", tcp->u_arg[2]);
1984 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001985 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001986 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
1987 }
1988 return 0;
1989}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001990
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001991int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001992sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001993{
1994 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001995 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001996 printuid(", ", tcp->u_arg[1]);
1997 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001998 }
1999 return 0;
2000}
2001
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002002static int
2003decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002004{
2005 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002006 printpath(tcp, tcp->u_arg[offset]);
2007 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002008 }
2009 return 0;
2010}
2011
2012int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002013sys_chmod(struct tcb *tcp)
2014{
2015 return decode_chmod(tcp, 0);
2016}
2017
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002018int
2019sys_fchmodat(struct tcb *tcp)
2020{
2021 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002022 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002023 return decode_chmod(tcp, 1);
2024}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002025
2026int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002027sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002028{
2029 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002030 printfd(tcp, tcp->u_arg[0]);
2031 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002032 }
2033 return 0;
2034}
2035
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002036#ifdef ALPHA
2037int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002038sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002039{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002040 if (entering(tcp)) {
2041 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002042 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002043 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2044 }
2045 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002046}
2047#endif
2048
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002049static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002050decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002051{
2052 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002053 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002054 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002055 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002056 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00002057 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002058 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00002059 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2060 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002061 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002062 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002063 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00002064 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002065 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00002066 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002067 }
2068 return 0;
2069}
2070
2071int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002072sys_utimes(struct tcb *tcp)
2073{
Roland McGrath6afc5652007-07-24 01:57:11 +00002074 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002075}
2076
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002077int
2078sys_futimesat(struct tcb *tcp)
2079{
2080 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002081 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002082 return decode_utimes(tcp, 1, 0);
2083}
2084
2085int
2086sys_utimensat(struct tcb *tcp)
2087{
2088 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002089 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002090 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002091 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002092 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2093 }
2094 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002095}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002096
2097int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002098sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002099{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002100 union {
2101 long utl[2];
2102 int uti[2];
2103 } u;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002104 unsigned wordsize = personality_wordsize[current_personality];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002105
2106 if (entering(tcp)) {
2107 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002108 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002109 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002110 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002111 else if (!verbose(tcp))
2112 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002113 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002114 tprints("[?, ?]");
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002115 else if (wordsize == sizeof u.utl[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002116 tprintf("[%s,", sprinttime(u.utl[0]));
2117 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002118 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002119 else if (wordsize == sizeof u.uti[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002120 tprintf("[%s,", sprinttime(u.uti[0]));
2121 tprintf(" %s]", sprinttime(u.uti[1]));
2122 }
2123 else
2124 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002125 }
2126 return 0;
2127}
2128
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002129static int
2130decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002131{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002132 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002133
2134 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002135 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002136 tprintf(", %s", sprintmode(mode));
2137 switch (mode & S_IFMT) {
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002138 case S_IFCHR:
2139 case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002140#ifdef LINUXSPARC
2141 if (current_personality == 1)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002142 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002143 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2144 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002145 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002146#endif
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002147 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002148 (unsigned long) major(tcp->u_arg[offset + 2]),
2149 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002150 break;
2151 default:
2152 break;
2153 }
2154 }
2155 return 0;
2156}
2157
2158int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002159sys_mknod(struct tcb *tcp)
2160{
2161 return decode_mknod(tcp, 0);
2162}
2163
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002164int
2165sys_mknodat(struct tcb *tcp)
2166{
2167 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002168 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002169 return decode_mknod(tcp, 1);
2170}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002171
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002172static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002173printdir(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002174{
2175 struct dirent d;
2176
2177 if (!verbose(tcp)) {
2178 tprintf("%#lx", addr);
2179 return;
2180 }
2181 if (umove(tcp, addr, &d) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002182 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002183 return;
2184 }
2185 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002186 tprints("d_name=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002187 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002188 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002189}
2190
2191int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002192sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002193{
2194 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002195 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002196 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002197 } else {
2198 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2199 tprintf("%#lx", tcp->u_arg[1]);
2200 else
2201 printdir(tcp, tcp->u_arg[1]);
2202 /* Not much point in printing this out, it is always 1. */
2203 if (tcp->u_arg[2] != 1)
2204 tprintf(", %lu", tcp->u_arg[2]);
2205 }
2206 return 0;
2207}
2208
Roland McGratha4d48532005-06-08 20:45:28 +00002209static const struct xlat direnttypes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002210 { DT_UNKNOWN, "DT_UNKNOWN" },
2211 { DT_FIFO, "DT_FIFO" },
2212 { DT_CHR, "DT_CHR" },
2213 { DT_DIR, "DT_DIR" },
2214 { DT_BLK, "DT_BLK" },
2215 { DT_REG, "DT_REG" },
2216 { DT_LNK, "DT_LNK" },
2217 { DT_SOCK, "DT_SOCK" },
2218 { DT_WHT, "DT_WHT" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002219 { 0, NULL },
2220};
2221
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002222int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002223sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002224{
2225 int i, len, dents = 0;
2226 char *buf;
2227
2228 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002229 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002230 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002231 return 0;
2232 }
2233 if (syserror(tcp) || !verbose(tcp)) {
2234 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2235 return 0;
2236 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002237 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002238 /* Beware of insanely large or negative values in tcp->u_rval */
2239 if (tcp->u_rval > 1024*1024)
2240 len = 1024*1024;
2241 if (tcp->u_rval < 0)
2242 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002243 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002244 if (len && !buf)
2245 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002246 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002247 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002248 free(buf);
2249 return 0;
2250 }
2251 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002252 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002253 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002254 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002255 if (!abbrev(tcp)) {
2256 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2257 i ? " " : "", d->d_ino, d->d_off);
2258 tprintf("d_reclen=%u, d_name=\"%s\"}",
2259 d->d_reclen, d->d_name);
2260 }
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002261 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002262 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002263 break;
2264 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002265 i += d->d_reclen;
2266 dents++;
2267 }
2268 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002269 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002270 else
2271 tprintf("/* %u entries */", dents);
2272 tprintf(", %lu", tcp->u_arg[2]);
2273 free(buf);
2274 return 0;
2275}
2276
John Hughesbdf48f52001-03-06 15:08:09 +00002277#if _LFS64_LARGEFILE
2278int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002279sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002280{
2281 int i, len, dents = 0;
2282 char *buf;
2283
2284 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002285 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002286 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002287 return 0;
2288 }
2289 if (syserror(tcp) || !verbose(tcp)) {
2290 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2291 return 0;
2292 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002293
John Hughesbdf48f52001-03-06 15:08:09 +00002294 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002295 /* Beware of insanely large or negative tcp->u_rval */
2296 if (tcp->u_rval > 1024*1024)
2297 len = 1024*1024;
2298 if (tcp->u_rval < 0)
2299 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002300 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002301 if (len && !buf)
2302 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002303
John Hughesbdf48f52001-03-06 15:08:09 +00002304 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002305 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002306 free(buf);
2307 return 0;
2308 }
2309 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002310 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002311 for (i = 0; i < len;) {
2312 struct dirent64 *d = (struct dirent64 *) &buf[i];
John Hughesbdf48f52001-03-06 15:08:09 +00002313 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002314 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002315 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002316 d->d_ino,
2317 d->d_off);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002318 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002319 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002320 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002321 tprintf("d_reclen=%u, d_name=\"%s\"}",
2322 d->d_reclen, d->d_name);
2323 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002324 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002325 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002326 break;
2327 }
John Hughesbdf48f52001-03-06 15:08:09 +00002328 i += d->d_reclen;
2329 dents++;
2330 }
2331 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002332 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002333 else
2334 tprintf("/* %u entries */", dents);
2335 tprintf(", %lu", tcp->u_arg[2]);
2336 free(buf);
2337 return 0;
2338}
2339#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002340
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002341int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002342sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002343{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002344 if (exiting(tcp)) {
2345 if (syserror(tcp))
2346 tprintf("%#lx", tcp->u_arg[0]);
2347 else
2348 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2349 tprintf(", %lu", tcp->u_arg[1]);
2350 }
2351 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002352}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002353
2354#ifdef HAVE_SYS_ASYNCH_H
2355
2356int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002357sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002358{
2359 struct aio_result_t res;
2360
2361 if (entering(tcp)) {
2362 tprintf("%lu, ", tcp->u_arg[0]);
2363 } else {
2364 if (syserror(tcp))
2365 tprintf("%#lx", tcp->u_arg[1]);
2366 else
2367 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2368 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2369 printxval(whence, tcp->u_arg[4], "L_???");
2370 if (syserror(tcp) || tcp->u_arg[5] == 0
2371 || umove(tcp, tcp->u_arg[5], &res) < 0)
2372 tprintf(", %#lx", tcp->u_arg[5]);
2373 else
2374 tprintf(", {aio_return %d aio_errno %d}",
2375 res.aio_return, res.aio_errno);
2376 }
2377 return 0;
2378}
2379
2380int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002381sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002382{
2383 struct aio_result_t res;
2384
2385 if (entering(tcp)) {
2386 tprintf("%lu, ", tcp->u_arg[0]);
2387 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2388 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2389 printxval(whence, tcp->u_arg[4], "L_???");
2390 }
2391 else {
2392 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002393 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002394 else if (syserror(tcp)
2395 || umove(tcp, tcp->u_arg[5], &res) < 0)
2396 tprintf(", %#lx", tcp->u_arg[5]);
2397 else
2398 tprintf(", {aio_return %d aio_errno %d}",
2399 res.aio_return, res.aio_errno);
2400 }
2401 return 0;
2402}
2403
2404int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002405sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002406{
2407 if (entering(tcp))
2408 printtv(tcp, tcp->u_arg[0]);
2409 return 0;
2410}
2411
2412int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002413sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002414{
2415 struct aio_result_t res;
2416
2417 if (exiting(tcp)) {
2418 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002419 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002420 else if (syserror(tcp)
2421 || umove(tcp, tcp->u_arg[0], &res) < 0)
2422 tprintf("%#lx", tcp->u_arg[0]);
2423 else
2424 tprintf("{aio_return %d aio_errno %d}",
2425 res.aio_return, res.aio_errno);
2426 }
2427 return 0;
2428}
2429
2430#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002431
Roland McGratha4d48532005-06-08 20:45:28 +00002432static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002433#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002434 { XATTR_CREATE, "XATTR_CREATE" },
2435 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002436#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002437 { 0, NULL }
2438};
2439
Roland McGrath3292e222004-08-31 06:30:48 +00002440static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002441print_xattr_val(struct tcb *tcp, int failed,
2442 unsigned long arg,
2443 unsigned long insize,
2444 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002445{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002446 if (!failed) {
2447 unsigned long capacity = 4 * size + 1;
2448 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2449 if (buf == NULL || /* probably a bogus size argument */
2450 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2451 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002452 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002453 else {
2454 unsigned char *out = buf;
2455 unsigned char *in = &buf[3 * size];
2456 size_t i;
2457 for (i = 0; i < size; ++i) {
2458 if (isprint(in[i]))
2459 *out++ = in[i];
2460 else {
2461#define tohex(n) "0123456789abcdef"[n]
2462 *out++ = '\\';
2463 *out++ = 'x';
2464 *out++ = tohex(in[i] / 16);
2465 *out++ = tohex(in[i] % 16);
2466 }
2467 }
2468 /* Don't print terminating NUL if there is one. */
2469 if (i > 0 && in[i - 1] == '\0')
2470 out -= 4;
2471 *out = '\0';
2472 tprintf(", \"%s\", %ld", buf, insize);
2473 }
2474 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002475 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002476 if (failed)
2477 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002478}
2479
Roland McGrath186c5ac2002-12-15 23:58:23 +00002480int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002481sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002482{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002483 if (entering(tcp)) {
2484 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002485 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002486 printstr(tcp, tcp->u_arg[1], -1);
2487 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002488 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002489 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2490 }
2491 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002492}
2493
2494int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002495sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002496{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002497 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002498 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002499 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002500 printstr(tcp, tcp->u_arg[1], -1);
2501 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002502 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002503 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2504 }
2505 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002506}
2507
2508int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002509sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002510{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002511 if (entering(tcp)) {
2512 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002513 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002514 printstr(tcp, tcp->u_arg[1], -1);
2515 } else {
2516 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2517 tcp->u_rval);
2518 }
2519 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002520}
2521
2522int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002523sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002524{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002525 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002526 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002527 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002528 printstr(tcp, tcp->u_arg[1], -1);
2529 } else {
2530 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2531 tcp->u_rval);
2532 }
2533 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002534}
2535
2536int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002537sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002538{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002539 if (entering(tcp)) {
2540 printpath(tcp, tcp->u_arg[0]);
2541 } else {
2542 /* XXX Print value in format */
2543 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2544 }
2545 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002546}
2547
2548int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002549sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002550{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002551 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002552 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002553 } else {
2554 /* XXX Print value in format */
2555 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2556 }
2557 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002558}
2559
2560int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002561sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002562{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002563 if (entering(tcp)) {
2564 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002565 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002566 printstr(tcp, tcp->u_arg[1], -1);
2567 }
2568 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002569}
2570
2571int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002572sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002573{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002574 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002575 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002576 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002577 printstr(tcp, tcp->u_arg[1], -1);
2578 }
2579 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002580}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002581
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002582static const struct xlat advise[] = {
2583 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2584 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2585 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2586 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2587 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2588 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2589 { 0, NULL }
2590};
2591
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002592int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002593sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002594{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002595 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002596 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002597 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002598 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002599 argn = printllval(tcp, "%lld", 1);
2600 tprintf(", %ld, ", tcp->u_arg[argn++]);
2601 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002602 }
2603 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002604}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002605
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002606int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002607sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002608{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002609 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002610 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002611 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002612 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002613#if defined ARM || defined POWERPC
2614 argn = printllval(tcp, "%lld, ", 2);
2615#else
2616 argn = printllval(tcp, "%lld, ", 1);
2617#endif
2618 argn = printllval(tcp, "%lld, ", argn);
2619#if defined ARM || defined POWERPC
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002620 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002621#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002622 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002623#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002624 }
2625 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002626}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002627
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002628static const struct xlat inotify_modes[] = {
Dmitry V. Levind475c062011-03-03 01:02:41 +00002629 { 0x00000001, "IN_ACCESS" },
2630 { 0x00000002, "IN_MODIFY" },
2631 { 0x00000004, "IN_ATTRIB" },
2632 { 0x00000008, "IN_CLOSE_WRITE"},
2633 { 0x00000010, "IN_CLOSE_NOWRITE"},
2634 { 0x00000020, "IN_OPEN" },
2635 { 0x00000040, "IN_MOVED_FROM" },
2636 { 0x00000080, "IN_MOVED_TO" },
2637 { 0x00000100, "IN_CREATE" },
2638 { 0x00000200, "IN_DELETE" },
2639 { 0x00000400, "IN_DELETE_SELF"},
2640 { 0x00000800, "IN_MOVE_SELF" },
2641 { 0x00002000, "IN_UNMOUNT" },
2642 { 0x00004000, "IN_Q_OVERFLOW" },
2643 { 0x00008000, "IN_IGNORED" },
2644 { 0x01000000, "IN_ONLYDIR" },
2645 { 0x02000000, "IN_DONT_FOLLOW"},
2646 { 0x20000000, "IN_MASK_ADD" },
2647 { 0x40000000, "IN_ISDIR" },
2648 { 0x80000000, "IN_ONESHOT" },
2649 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002650};
2651
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002652static const struct xlat inotify_init_flags[] = {
2653 { 0x00000800, "IN_NONBLOCK" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002654 { 0x00080000, "IN_CLOEXEC" },
2655 { 0, NULL }
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002656};
2657
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002658int
2659sys_inotify_add_watch(struct tcb *tcp)
2660{
2661 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002662 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002663 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002664 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002665 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002666 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2667 }
2668 return 0;
2669}
2670
2671int
2672sys_inotify_rm_watch(struct tcb *tcp)
2673{
2674 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002675 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levinab1a70c2012-03-11 15:33:34 +00002676 tprintf(", %d", (int) tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002677 }
2678 return 0;
2679}
Roland McGrath96a96612008-05-20 04:56:18 +00002680
2681int
Mark Wielaardbab89402010-03-21 14:41:26 +01002682sys_inotify_init1(struct tcb *tcp)
2683{
2684 if (entering(tcp))
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002685 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
Mark Wielaardbab89402010-03-21 14:41:26 +01002686 return 0;
2687}
2688
2689int
Roland McGrath96a96612008-05-20 04:56:18 +00002690sys_fallocate(struct tcb *tcp)
2691{
2692 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002693 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002694 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002695 tprints(", ");
Roland McGrath96a96612008-05-20 04:56:18 +00002696 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002697 argn = printllval(tcp, "%llu, ", 2); /* offset */
2698 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002699 }
2700 return 0;
2701}
Dmitry V. Levin88293652012-03-09 21:02:19 +00002702
2703static const struct xlat swap_flags[] = {
2704 { SWAP_FLAG_PREFER, "SWAP_FLAG_PREFER" },
2705 { SWAP_FLAG_DISCARD, "SWAP_FLAG_DISCARD" },
2706 { 0, NULL }
2707};
2708
2709int
2710sys_swapon(struct tcb *tcp)
2711{
2712 if (entering(tcp)) {
2713 int flags = tcp->u_arg[1];
2714 printpath(tcp, tcp->u_arg[0]);
2715 tprints(", ");
2716 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2717 "SWAP_FLAG_???");
2718 if (flags & SWAP_FLAG_PREFER)
2719 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);
2720 }
2721 return 0;
2722}