blob: 0ec1d4b6e6b1be43c487e93e2b7b6d5c9d555a9b [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.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Dmitry V. Levin88293652012-03-09 21:02:19 +000032#include <sys/swap.h>
Roland McGrathc531e572008-08-01 01:13:10 +000033
Denys Vlasenko9472a272013-02-12 11:43:46 +010034#if defined(SPARC) || defined(SPARC64)
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000035struct stat {
36 unsigned short st_dev;
37 unsigned int st_ino;
38 unsigned short st_mode;
39 short st_nlink;
40 unsigned short st_uid;
41 unsigned short st_gid;
42 unsigned short st_rdev;
43 unsigned int st_size;
44 int st_atime;
45 unsigned int __unused1;
46 int st_mtime;
47 unsigned int __unused2;
48 int st_ctime;
49 unsigned int __unused3;
50 int st_blksize;
51 int st_blocks;
52 unsigned int __unused4[2];
53};
Denys Vlasenko84703742012-02-25 02:38:52 +010054# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +000055struct stat_sparc64 {
56 unsigned int st_dev;
57 unsigned long st_ino;
58 unsigned int st_mode;
59 unsigned int st_nlink;
60 unsigned int st_uid;
61 unsigned int st_gid;
62 unsigned int st_rdev;
63 long st_size;
64 long st_atime;
65 long st_mtime;
66 long st_ctime;
67 long st_blksize;
68 long st_blocks;
69 unsigned long __unused4[2];
70};
Denys Vlasenko84703742012-02-25 02:38:52 +010071# endif /* SPARC64 */
72# define stat kernel_stat
73# include <asm/stat.h>
74# undef stat
H.J. Lu35be5812012-04-16 13:00:01 +020075#elif defined(X32)
76struct stat {
77 unsigned long long st_dev;
78 unsigned long long st_ino;
79 unsigned long long st_nlink;
80
81 unsigned int st_mode;
82 unsigned int st_uid;
83 unsigned int st_gid;
84 unsigned int __pad0;
85 unsigned long long st_rdev;
86 long long st_size;
87 long long st_blksize;
88 long long st_blocks;
89
90 unsigned long long st_atime;
91 unsigned long long st_atime_nsec;
92 unsigned long long st_mtime;
93 unsigned long long st_mtime_nsec;
94 unsigned long long st_ctime;
95 unsigned long long st_ctime_nsec;
96 long long __unused[3];
97};
H.J. Lu085e4282012-04-17 11:05:04 -070098
99struct stat64 {
100 unsigned long long st_dev;
101 unsigned char __pad0[4];
102 unsigned long __st_ino;
103 unsigned int st_mode;
104 unsigned int st_nlink;
105 unsigned long st_uid;
106 unsigned long st_gid;
107 unsigned long long st_rdev;
108 unsigned char __pad3[4];
109 long long st_size;
110 unsigned long st_blksize;
111 unsigned long long st_blocks;
112 unsigned long st_atime;
113 unsigned long st_atime_nsec;
114 unsigned long st_mtime;
115 unsigned int st_mtime_nsec;
116 unsigned long st_ctime;
117 unsigned long st_ctime_nsec;
118 unsigned long long st_ino;
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000119} __attribute__((packed));
120# define HAVE_STAT64 1
Dmitry V. Levinbd2e28a2013-05-01 15:14:25 +0000121
122struct __old_kernel_stat {
123 unsigned short st_dev;
124 unsigned short st_ino;
125 unsigned short st_mode;
126 unsigned short st_nlink;
127 unsigned short st_uid;
128 unsigned short st_gid;
129 unsigned short st_rdev;
130 unsigned int st_size;
131 unsigned int st_atime;
132 unsigned int st_mtime;
133 unsigned int st_ctime;
134};
Denys Vlasenko84703742012-02-25 02:38:52 +0100135#else
136# undef dev_t
137# undef ino_t
138# undef mode_t
139# undef nlink_t
140# undef uid_t
141# undef gid_t
142# undef off_t
143# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100144# define dev_t __kernel_dev_t
145# define ino_t __kernel_ino_t
146# define mode_t __kernel_mode_t
147# define nlink_t __kernel_nlink_t
148# define uid_t __kernel_uid_t
149# define gid_t __kernel_gid_t
150# define off_t __kernel_off_t
151# define loff_t __kernel_loff_t
Wichert Akkermana6013701999-07-08 14:00:58 +0000152
Denys Vlasenko84703742012-02-25 02:38:52 +0100153# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +0000154
Denys Vlasenko84703742012-02-25 02:38:52 +0100155# undef dev_t
156# undef ino_t
157# undef mode_t
158# undef nlink_t
159# undef uid_t
160# undef gid_t
161# undef off_t
162# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100163# define dev_t dev_t
164# define ino_t ino_t
165# define mode_t mode_t
166# define nlink_t nlink_t
167# define uid_t uid_t
168# define gid_t gid_t
169# define off_t off_t
170# define loff_t loff_t
171#endif
172
Denys Vlasenko84703742012-02-25 02:38:52 +0100173#define stat libc_stat
174#define stat64 libc_stat64
175#include <sys/stat.h>
176#undef stat
177#undef stat64
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100178/* These might be macros. */
Denys Vlasenko84703742012-02-25 02:38:52 +0100179#undef st_atime
180#undef st_mtime
181#undef st_ctime
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000182
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000183#include <fcntl.h>
Roland McGrath186c5ac2002-12-15 23:58:23 +0000184#ifdef HAVE_LINUX_XATTR_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100185# include <linux/xattr.h>
Denys Vlasenkoed720fd2012-02-25 02:24:03 +0100186#else
Denys Vlasenko84703742012-02-25 02:38:52 +0100187# define XATTR_CREATE 1
188# define XATTR_REPLACE 2
Roland McGrath186c5ac2002-12-15 23:58:23 +0000189#endif
190
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000191#ifdef MAJOR_IN_SYSMACROS
Denys Vlasenko84703742012-02-25 02:38:52 +0100192# include <sys/sysmacros.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000193#endif
194
195#ifdef MAJOR_IN_MKDEV
Denys Vlasenko84703742012-02-25 02:38:52 +0100196# include <sys/mkdev.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000197#endif
198
199#ifdef HAVE_SYS_ASYNCH_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100200# include <sys/asynch.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000201#endif
202
Dmitry V. Levin63ebcfc2014-04-26 15:35:02 +0000203#ifdef O_LARGEFILE
204# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
205# undef O_LARGEFILE
206# ifdef SPARC64
207# define O_LARGEFILE 0x40000
208# elif defined X86_64 || defined S390X
209# define O_LARGEFILE 0100000
210# endif
211# endif
212#endif
213
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000214#include "xlat/open_access_modes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000215#include "xlat/open_mode_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000216
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000217#ifndef AT_FDCWD
218# define AT_FDCWD -100
219#endif
220
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000221/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
222 * extension to get the right value. We do this by declaring fd as int here.
223 */
Dmitry V. Levin99db95d2014-02-05 04:13:18 +0000224void
Dmitry V. Levin31382132011-03-04 05:08:02 +0300225print_dirfd(struct tcb *tcp, int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000226{
227 if (fd == AT_FDCWD)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200228 tprints("AT_FDCWD, ");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200229 else {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300230 printfd(tcp, fd);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200231 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300232 }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000233}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000234
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000235/*
236 * low bits of the open(2) flags define access mode,
237 * other bits are real flags.
238 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000239const char *
Elliott Hughes22e34b92014-09-23 19:09:50 -0700240sprint_open_modes(int flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000241{
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100242 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000243 char *p;
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100244 char sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000245 const char *str;
246 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000247
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100248 sep = ' ';
249 p = stpcpy(outstr, "flags");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000250 str = xlookup(open_access_modes, flags & 3);
251 if (str) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100252 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200253 p = stpcpy(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000254 flags &= ~3;
255 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000256 return outstr;
257 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000258 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000259
260 for (x = open_mode_flags; x->str; x++) {
261 if ((flags & x->val) == x->val) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100262 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200263 p = stpcpy(p, x->str);
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000264 flags &= ~x->val;
265 if (!flags)
266 return outstr;
267 sep = '|';
268 }
269 }
270 /* flags is still nonzero */
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100271 *p++ = sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000272 sprintf(p, "%#x", flags);
273 return outstr;
274}
275
276void
Elliott Hughes22e34b92014-09-23 19:09:50 -0700277tprint_open_modes(int flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000278{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200279 tprints(sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000280}
281
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000282static int
283decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000284{
285 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000286 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200287 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000288 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000289 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000290 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000291 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000292 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000293 }
294 }
Zubin Mithra64aa1b12014-06-04 08:30:41 +0530295 return RVAL_FD;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000296}
297
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000298int
299sys_open(struct tcb *tcp)
300{
301 return decode_open(tcp, 0);
302}
303
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000304int
305sys_openat(struct tcb *tcp)
306{
307 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300308 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000309 return decode_open(tcp, 1);
310}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000311
Denys Vlasenko9472a272013-02-12 11:43:46 +0100312#if defined(SPARC) || defined(SPARC64)
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000313#include "xlat/openmodessol.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000314
315int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000316solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000317{
318 if (entering(tcp)) {
319 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200320 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000321 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000322 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000323 if (tcp->u_arg[1] & 0x100) {
324 /* mode */
325 tprintf(", %#lo", tcp->u_arg[2]);
326 }
327 }
328 return 0;
329}
330
331#endif
332
333int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000334sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000335{
336 if (entering(tcp)) {
337 printpath(tcp, tcp->u_arg[0]);
338 tprintf(", %#lo", tcp->u_arg[1]);
339 }
Zubin Mithra64aa1b12014-06-04 08:30:41 +0530340 return RVAL_FD;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000341}
342
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000343#include "xlat/access_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000344
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000345static int
346decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000347{
348 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000349 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200350 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000351 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000352 }
353 return 0;
354}
355
356int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000357sys_access(struct tcb *tcp)
358{
359 return decode_access(tcp, 0);
360}
361
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000362int
363sys_faccessat(struct tcb *tcp)
364{
365 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300366 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000367 return decode_access(tcp, 1);
368}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000369
370int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000371sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000372{
373 if (entering(tcp)) {
374 tprintf("%#lo", tcp->u_arg[0]);
375 }
376 return RVAL_OCTAL;
377}
378
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000379#include "xlat/whence_codes.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000380
Denys Vlasenko386b8712013-02-17 01:38:14 +0100381/* Linux kernel has exactly one version of lseek:
382 * fs/read_write.c::SYSCALL_DEFINE3(lseek, unsigned, fd, off_t, offset, unsigned, origin)
383 * In kernel, off_t is always the same as (kernel's) long
384 * (see include/uapi/asm-generic/posix_types.h),
385 * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument.
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100386 * Use test/x32_lseek.c to test lseek decoding.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100387 */
H.J. Luc933f272012-04-16 17:41:13 +0200388#if defined(LINUX_MIPSN32) || defined(X32)
Roland McGrath542c2c62008-05-20 01:11:56 +0000389int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000390sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000391{
392 long long offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100393 int whence;
Roland McGrath542c2c62008-05-20 01:11:56 +0000394
395 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300396 printfd(tcp, tcp->u_arg[0]);
Roland McGrath542c2c62008-05-20 01:11:56 +0000397 offset = tcp->ext_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100398 whence = tcp->u_arg[2];
399 if (whence == SEEK_SET)
400 tprintf(", %llu, ", offset);
Roland McGrath542c2c62008-05-20 01:11:56 +0000401 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100402 tprintf(", %lld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100403 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath542c2c62008-05-20 01:11:56 +0000404 }
H.J. Ludd0130b2012-04-16 12:16:45 +0200405 return RVAL_LUDECIMAL;
Roland McGrath542c2c62008-05-20 01:11:56 +0000406}
H.J. Ludd0130b2012-04-16 12:16:45 +0200407#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000408int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000409sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000410{
Denys Vlasenko06121762013-02-17 20:08:50 +0100411 long offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100412 int whence;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000413
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000414 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300415 printfd(tcp, tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000416 offset = tcp->u_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100417 whence = tcp->u_arg[2];
418 if (whence == SEEK_SET)
419 tprintf(", %lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000420 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100421 tprintf(", %ld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100422 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000423 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000424 return RVAL_UDECIMAL;
425}
John Hughes5a826b82001-03-07 13:21:24 +0000426#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000427
Denys Vlasenko386b8712013-02-17 01:38:14 +0100428/* llseek syscall takes explicitly two ulong arguments hi, lo,
429 * rather than one 64-bit argument for which LONG_LONG works
430 * appropriate for the native byte order.
431 *
432 * See kernel's fs/read_write.c::SYSCALL_DEFINE5(llseek, ...)
433 *
434 * hi,lo are "unsigned longs" and combined exactly this way in kernel:
435 * ((loff_t) hi << 32) | lo
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100436 * Note that for architectures with kernel's long wider than userspace long
Denys Vlasenko386b8712013-02-17 01:38:14 +0100437 * (such as x32), combining code will use *kernel's*, i.e. *wide* longs
Denys Vlasenko06121762013-02-17 20:08:50 +0100438 * for hi and lo. We would need to use tcp->ext_arg[N] on x32...
439 * ...however, x32 (and x86_64) does not _have_ llseek syscall as such.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100440 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000441int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000442sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000443{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000444 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300445 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000446 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300447 tprintf(", %llu, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100448 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300449 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000450 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300451 tprintf(", %lld, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100452 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300453 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000454 }
455 else {
Denys Vlasenko386b8712013-02-17 01:38:14 +0100456 long long off;
Denys Vlasenko1d632462009-04-14 12:51:00 +0000457 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
458 tprintf("%#lx, ", tcp->u_arg[3]);
459 else
460 tprintf("[%llu], ", off);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100461 printxval(whence_codes, tcp->u_arg[4], "SEEK_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000462 }
463 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000464}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000465
466int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000467sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000468{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000469 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100470 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300471 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin3c49b022014-08-07 00:07:28 +0000472 argn = printllval(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100473 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000474 }
475 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000476}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000477
478int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000479sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000480{
481 if (entering(tcp)) {
482 printpath(tcp, tcp->u_arg[0]);
483 tprintf(", %lu", tcp->u_arg[1]);
484 }
485 return 0;
486}
487
John Hughes96f51472001-03-06 16:50:41 +0000488int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000489sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000490{
491 if (entering(tcp)) {
492 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin3c49b022014-08-07 00:07:28 +0000493 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000494 }
495 return 0;
496}
John Hughes96f51472001-03-06 16:50:41 +0000497
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000498int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000499sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000500{
501 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300502 printfd(tcp, tcp->u_arg[0]);
503 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000504 }
505 return 0;
506}
507
John Hughes96f51472001-03-06 16:50:41 +0000508int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000509sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000510{
511 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300512 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin3c49b022014-08-07 00:07:28 +0000513 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000514 }
515 return 0;
516}
John Hughes96f51472001-03-06 16:50:41 +0000517
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000518/* several stats */
519
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000520#include "xlat/modetypes.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000521
Roland McGrathf9c49b22004-10-06 22:11:54 +0000522static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000523sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000524{
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100525 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
526 + sizeof(int)*3
527 + /*paranoia:*/ 8];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000528 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000529
530 if ((mode & S_IFMT) == 0)
531 s = "";
532 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
533 sprintf(buf, "%#o", mode);
534 return buf;
535 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100536 s = buf + sprintf(buf, "%s%s%s%s", s,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000537 (mode & S_ISUID) ? "|S_ISUID" : "",
538 (mode & S_ISGID) ? "|S_ISGID" : "",
539 (mode & S_ISVTX) ? "|S_ISVTX" : "");
540 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
541 if (mode)
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100542 sprintf((char*)s, "|%#o", mode);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000543 s = (*buf == '|') ? buf + 1 : buf;
544 return *s ? s : "0";
545}
546
547static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000548sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000549{
550 struct tm *tmp;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100551 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000552
553 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000554 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000555 return buf;
556 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200557 tmp = localtime(&t);
558 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000559 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
560 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
561 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
562 else
563 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
564
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000565 return buf;
566}
567
Denys Vlasenko9472a272013-02-12 11:43:46 +0100568#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000569typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000570 int tv_sec;
571 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000572} timestruct_t;
573
574struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000575 unsigned st_dev;
576 int st_pad1[3]; /* network id */
577 unsigned st_ino;
578 unsigned st_mode;
579 unsigned st_nlink;
580 unsigned st_uid;
581 unsigned st_gid;
582 unsigned st_rdev;
583 int st_pad2[2];
584 int st_size;
585 int st_pad3; /* st_size, off_t expansion */
586 timestruct_t st_atime;
587 timestruct_t st_mtime;
588 timestruct_t st_ctime;
589 int st_blksize;
590 int st_blocks;
591 char st_fstype[16];
592 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000593};
594
595static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000596printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000597{
598 struct solstat statbuf;
599
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000600 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200601 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000602 return;
603 }
604 if (!abbrev(tcp)) {
605 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
606 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
607 (unsigned long) (statbuf.st_dev & 0x3ffff),
608 (unsigned long) statbuf.st_ino,
609 sprintmode(statbuf.st_mode));
610 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
611 (unsigned long) statbuf.st_nlink,
612 (unsigned long) statbuf.st_uid,
613 (unsigned long) statbuf.st_gid);
614 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
615 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
616 }
617 else
618 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
619 switch (statbuf.st_mode & S_IFMT) {
620 case S_IFCHR: case S_IFBLK:
621 tprintf("st_rdev=makedev(%lu, %lu), ",
622 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
623 (unsigned long) (statbuf.st_rdev & 0x3ffff));
624 break;
625 default:
626 tprintf("st_size=%u, ", statbuf.st_size);
627 break;
628 }
629 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000630 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
631 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
632 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000633 }
634 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200635 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000636}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000637
Denys Vlasenko9472a272013-02-12 11:43:46 +0100638# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000639static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000640printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000641{
642 struct stat_sparc64 statbuf;
643
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000644 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200645 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000646 return;
647 }
648
649 if (!abbrev(tcp)) {
650 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
651 (unsigned long) major(statbuf.st_dev),
652 (unsigned long) minor(statbuf.st_dev),
653 (unsigned long) statbuf.st_ino,
654 sprintmode(statbuf.st_mode));
655 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
656 (unsigned long) statbuf.st_nlink,
657 (unsigned long) statbuf.st_uid,
658 (unsigned long) statbuf.st_gid);
659 tprintf("st_blksize=%lu, ",
660 (unsigned long) statbuf.st_blksize);
661 tprintf("st_blocks=%lu, ",
662 (unsigned long) statbuf.st_blocks);
663 }
664 else
665 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
666 switch (statbuf.st_mode & S_IFMT) {
667 case S_IFCHR: case S_IFBLK:
668 tprintf("st_rdev=makedev(%lu, %lu), ",
669 (unsigned long) major(statbuf.st_rdev),
670 (unsigned long) minor(statbuf.st_rdev));
671 break;
672 default:
673 tprintf("st_size=%lu, ", statbuf.st_size);
674 break;
675 }
676 if (!abbrev(tcp)) {
677 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
678 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100679 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000680 }
681 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200682 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000683}
Denys Vlasenko9472a272013-02-12 11:43:46 +0100684# endif /* SPARC64 */
685#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000686
Denys Vlasenko84703742012-02-25 02:38:52 +0100687#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200688struct stat_powerpc32 {
689 unsigned int st_dev;
690 unsigned int st_ino;
691 unsigned int st_mode;
692 unsigned short st_nlink;
693 unsigned int st_uid;
694 unsigned int st_gid;
695 unsigned int st_rdev;
696 unsigned int st_size;
697 unsigned int st_blksize;
698 unsigned int st_blocks;
699 unsigned int st_atime;
700 unsigned int st_atime_nsec;
701 unsigned int st_mtime;
702 unsigned int st_mtime_nsec;
703 unsigned int st_ctime;
704 unsigned int st_ctime_nsec;
705 unsigned int __unused4;
706 unsigned int __unused5;
707};
708
709static void
710printstat_powerpc32(struct tcb *tcp, long addr)
711{
712 struct stat_powerpc32 statbuf;
713
714 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200715 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200716 return;
717 }
718
719 if (!abbrev(tcp)) {
720 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
721 major(statbuf.st_dev), minor(statbuf.st_dev),
722 statbuf.st_ino,
723 sprintmode(statbuf.st_mode));
724 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
725 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
726 tprintf("st_blksize=%u, ", statbuf.st_blksize);
727 tprintf("st_blocks=%u, ", statbuf.st_blocks);
728 }
729 else
730 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
731 switch (statbuf.st_mode & S_IFMT) {
732 case S_IFCHR: case S_IFBLK:
733 tprintf("st_rdev=makedev(%lu, %lu), ",
734 (unsigned long) major(statbuf.st_rdev),
735 (unsigned long) minor(statbuf.st_rdev));
736 break;
737 default:
738 tprintf("st_size=%u, ", statbuf.st_size);
739 break;
740 }
741 if (!abbrev(tcp)) {
742 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
743 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100744 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200745 }
746 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200747 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200748}
Denys Vlasenko84703742012-02-25 02:38:52 +0100749#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200750
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000751#include "xlat/fileflags.h"
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000752
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000753static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000754realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000755{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000756 if (!abbrev(tcp)) {
757 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
758 (unsigned long) major(statbuf->st_dev),
759 (unsigned long) minor(statbuf->st_dev),
760 (unsigned long) statbuf->st_ino,
761 sprintmode(statbuf->st_mode));
762 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
763 (unsigned long) statbuf->st_nlink,
764 (unsigned long) statbuf->st_uid,
765 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000766#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000767 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
768#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000769#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000770 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
771#endif
772 }
773 else
774 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
775 switch (statbuf->st_mode & S_IFMT) {
776 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000777#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000778 tprintf("st_rdev=makedev(%lu, %lu), ",
779 (unsigned long) major(statbuf->st_rdev),
780 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000781#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000782 tprintf("st_size=makedev(%lu, %lu), ",
783 (unsigned long) major(statbuf->st_size),
784 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000785#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000786 break;
787 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000788 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000789 break;
790 }
791 if (!abbrev(tcp)) {
792 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
793 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
794 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000795#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200796 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000797 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000798#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000799#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000800 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
801#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000802#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000803 tprintf(", st_level=%ld", statbuf->st_level);
804#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000805#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000806 tprintf(", st_fstype=%.*s",
807 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
808#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000809#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000810 tprintf(", st_gen=%u", statbuf->st_gen);
811#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200812 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000813 }
814 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200815 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000816}
817
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000818#ifndef X32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000819static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000820printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000821{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000822 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000823
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000824 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200825 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000826 return;
827 }
828 if (syserror(tcp) || !verbose(tcp)) {
829 tprintf("%#lx", addr);
830 return;
831 }
832
Denys Vlasenko9472a272013-02-12 11:43:46 +0100833#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000834 if (current_personality == 1) {
835 printstatsol(tcp, addr);
836 return;
837 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000838#ifdef SPARC64
839 else if (current_personality == 2) {
840 printstat_sparc64(tcp, addr);
841 return;
842 }
843#endif
Denys Vlasenko9472a272013-02-12 11:43:46 +0100844#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000845
Denys Vlasenko84703742012-02-25 02:38:52 +0100846#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200847 if (current_personality == 1) {
848 printstat_powerpc32(tcp, addr);
849 return;
850 }
851#endif
852
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000853 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200854 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000855 return;
856 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000857
858 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000859}
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000860#else /* X32 */
861# define printstat printstat64
862#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000863
Elliott Hughes391c0d82014-04-03 17:50:14 -0700864#if !defined HAVE_STAT64 && (defined AARCH64 || defined X86_64)
Roland McGrathe6d0f712007-08-07 01:22:49 +0000865/*
866 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
867 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
868 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
869 * __GNUC__ is needed for the required __attribute__ below.
Elliott Hughes391c0d82014-04-03 17:50:14 -0700870 *
871 * Similarly, aarch64 has a unified `struct stat' but its arm personality
872 * needs `struct stat64' (which also expects a 32-bit `long' but which
873 * shouldn't be packed).
Roland McGrathe6d0f712007-08-07 01:22:49 +0000874 */
875struct stat64 {
876 unsigned long long st_dev;
877 unsigned char __pad0[4];
878 unsigned int __st_ino;
879 unsigned int st_mode;
880 unsigned int st_nlink;
881 unsigned int st_uid;
882 unsigned int st_gid;
883 unsigned long long st_rdev;
884 unsigned char __pad3[4];
885 long long st_size;
886 unsigned int st_blksize;
887 unsigned long long st_blocks;
888 unsigned int st_atime;
889 unsigned int st_atime_nsec;
890 unsigned int st_mtime;
891 unsigned int st_mtime_nsec;
892 unsigned int st_ctime;
893 unsigned int st_ctime_nsec;
894 unsigned long long st_ino;
Elliott Hughes391c0d82014-04-03 17:50:14 -0700895}
896# if defined X86_64
897 __attribute__((packed))
898# define STAT64_SIZE 96
899#else
900# define STAT64_SIZE 104
901# endif
902;
Roland McGrathe6d0f712007-08-07 01:22:49 +0000903# define HAVE_STAT64 1
Roland McGrathe6d0f712007-08-07 01:22:49 +0000904#endif
905
Wichert Akkermanc7926982000-04-10 22:22:31 +0000906#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000907static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000908printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000909{
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000910#ifdef X32
911 struct stat statbuf;
912#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000913 struct stat64 statbuf;
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000914#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000915
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000916#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +0000917 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
918#endif
919
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000920 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200921 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000922 return;
923 }
924 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000925 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000926 return;
927 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000928
Denys Vlasenko9472a272013-02-12 11:43:46 +0100929#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000930 if (current_personality == 1) {
931 printstatsol(tcp, addr);
932 return;
933 }
934# ifdef SPARC64
935 else if (current_personality == 2) {
936 printstat_sparc64(tcp, addr);
937 return;
938 }
939# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +0100940#endif /* SPARC[64] */
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000941
Elliott Hughes391c0d82014-04-03 17:50:14 -0700942#if defined AARCH64
943 if (current_personality != 0) {
944 printstat(tcp, addr);
945 return;
946 }
947#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100948#if defined X86_64
H.J. Lu35be5812012-04-16 13:00:01 +0200949 if (current_personality != 1) {
Andreas Schwab61b74352009-10-16 11:37:13 +0200950 printstat(tcp, addr);
951 return;
952 }
953#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +0000954
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000955 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200956 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000957 return;
958 }
959
960 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +0000961 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000962 (unsigned long) major(statbuf.st_dev),
963 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +0000964 (unsigned long long) statbuf.st_ino,
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000965 sprintmode(statbuf.st_mode));
966 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
967 (unsigned long) statbuf.st_nlink,
968 (unsigned long) statbuf.st_uid,
969 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000970#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000971 tprintf("st_blksize=%lu, ",
972 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000973#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
974#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000975 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000976#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000977 }
978 else
979 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
980 switch (statbuf.st_mode & S_IFMT) {
981 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000982#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000983 tprintf("st_rdev=makedev(%lu, %lu), ",
984 (unsigned long) major(statbuf.st_rdev),
985 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000986#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000987 tprintf("st_size=makedev(%lu, %lu), ",
988 (unsigned long) major(statbuf.st_size),
989 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000990#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000991 break;
992 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +0000993 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000994 break;
995 }
996 if (!abbrev(tcp)) {
997 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
998 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000999 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001000#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001001 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001002 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001003#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001004#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001005 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1006#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001007#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001008 tprintf(", st_level=%ld", statbuf.st_level);
1009#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001010#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001011 tprintf(", st_fstype=%.*s",
1012 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1013#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001014#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001015 tprintf(", st_gen=%u", statbuf.st_gen);
1016#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001017 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001018 }
1019 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001020 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001021}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001022#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001023
Denys Vlasenko8435d672013-02-18 15:47:57 +01001024#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001025static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001026convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001027{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001028 newbuf->st_dev = oldbuf->st_dev;
1029 newbuf->st_ino = oldbuf->st_ino;
1030 newbuf->st_mode = oldbuf->st_mode;
1031 newbuf->st_nlink = oldbuf->st_nlink;
1032 newbuf->st_uid = oldbuf->st_uid;
1033 newbuf->st_gid = oldbuf->st_gid;
1034 newbuf->st_rdev = oldbuf->st_rdev;
1035 newbuf->st_size = oldbuf->st_size;
1036 newbuf->st_atime = oldbuf->st_atime;
1037 newbuf->st_mtime = oldbuf->st_mtime;
1038 newbuf->st_ctime = oldbuf->st_ctime;
1039 newbuf->st_blksize = 0; /* not supported in old_stat */
1040 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001041}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001042
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001043static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001044printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001045{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001046 struct __old_kernel_stat statbuf;
1047 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001048
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001049 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001050 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001051 return;
1052 }
1053 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001054 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001055 return;
1056 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001057
Denys Vlasenko9472a272013-02-12 11:43:46 +01001058# if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001059 if (current_personality == 1) {
1060 printstatsol(tcp, addr);
1061 return;
1062 }
Denys Vlasenko84703742012-02-25 02:38:52 +01001063# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001064
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001065 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001066 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001067 return;
1068 }
1069
1070 convertoldstat(&statbuf, &newstatbuf);
1071 realprintstat(tcp, &newstatbuf);
1072}
Denys Vlasenko84703742012-02-25 02:38:52 +01001073#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001074
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001075int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001076sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001077{
1078 if (entering(tcp)) {
1079 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001080 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001081 } else {
1082 printstat(tcp, tcp->u_arg[1]);
1083 }
1084 return 0;
1085}
1086
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001087#ifdef X32
1088static void
1089printstat64_x32(struct tcb *tcp, long addr)
1090{
1091 struct stat64 statbuf;
1092
1093 if (!addr) {
1094 tprints("NULL");
1095 return;
1096 }
1097 if (syserror(tcp) || !verbose(tcp)) {
1098 tprintf("%#lx", addr);
1099 return;
1100 }
1101
1102 if (umove(tcp, addr, &statbuf) < 0) {
1103 tprints("{...}");
1104 return;
1105 }
1106
1107 if (!abbrev(tcp)) {
1108 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1109 (unsigned long) major(statbuf.st_dev),
1110 (unsigned long) minor(statbuf.st_dev),
1111 (unsigned long long) statbuf.st_ino,
1112 sprintmode(statbuf.st_mode));
1113 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1114 (unsigned long) statbuf.st_nlink,
1115 (unsigned long) statbuf.st_uid,
1116 (unsigned long) statbuf.st_gid);
1117 tprintf("st_blksize=%lu, ",
1118 (unsigned long) statbuf.st_blksize);
1119 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1120 }
1121 else
1122 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1123 switch (statbuf.st_mode & S_IFMT) {
1124 case S_IFCHR: case S_IFBLK:
1125 tprintf("st_rdev=makedev(%lu, %lu), ",
1126 (unsigned long) major(statbuf.st_rdev),
1127 (unsigned long) minor(statbuf.st_rdev));
1128 break;
1129 default:
1130 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1131 break;
1132 }
1133 if (!abbrev(tcp)) {
1134 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1135 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1136 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1137 tprints("}");
1138 }
1139 else
1140 tprints("...}");
1141}
1142#endif /* X32 */
1143
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001144int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001145sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001146{
1147#ifdef HAVE_STAT64
1148 if (entering(tcp)) {
1149 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001150 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001151 } else {
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001152# ifdef X32
1153 printstat64_x32(tcp, tcp->u_arg[1]);
1154# else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001155 printstat64(tcp, tcp->u_arg[1]);
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001156# endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001157 }
1158 return 0;
1159#else
1160 return printargs(tcp);
1161#endif
1162}
1163
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001164#ifndef AT_SYMLINK_NOFOLLOW
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001165# define AT_SYMLINK_NOFOLLOW 0x100
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001166#endif
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001167#ifndef AT_REMOVEDIR
1168# define AT_REMOVEDIR 0x200
1169#endif
1170#ifndef AT_SYMLINK_FOLLOW
1171# define AT_SYMLINK_FOLLOW 0x400
1172#endif
1173#ifndef AT_NO_AUTOMOUNT
1174# define AT_NO_AUTOMOUNT 0x800
1175#endif
1176#ifndef AT_EMPTY_PATH
1177# define AT_EMPTY_PATH 0x1000
1178#endif
1179
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001180#include "xlat/at_flags.h"
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001181
1182int
1183sys_newfstatat(struct tcb *tcp)
1184{
1185 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001186 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001187 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001188 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001189 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001190#ifdef POWERPC64
1191 if (current_personality == 0)
1192 printstat(tcp, tcp->u_arg[2]);
1193 else
1194 printstat64(tcp, tcp->u_arg[2]);
1195#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001196 printstat64(tcp, tcp->u_arg[2]);
1197#else
1198 printstat(tcp, tcp->u_arg[2]);
1199#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001200 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001201 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001202 }
1203 return 0;
1204}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001205
Denys Vlasenko8435d672013-02-18 15:47:57 +01001206#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001207int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001208sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001209{
1210 if (entering(tcp)) {
1211 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001212 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001213 } else {
1214 printoldstat(tcp, tcp->u_arg[1]);
1215 }
1216 return 0;
1217}
Denys Vlasenko84703742012-02-25 02:38:52 +01001218#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001219
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001220int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001221sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001222{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001223 if (entering(tcp)) {
1224 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001225 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001226 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001227 printstat(tcp, tcp->u_arg[1]);
1228 }
1229 return 0;
1230}
1231
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001232int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001233sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001234{
1235#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001236 if (entering(tcp)) {
1237 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001238 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001239 } else {
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001240# ifdef X32
1241 printstat64_x32(tcp, tcp->u_arg[1]);
1242# else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001243 printstat64(tcp, tcp->u_arg[1]);
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001244# endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001245 }
1246 return 0;
1247#else
1248 return printargs(tcp);
1249#endif
1250}
1251
Denys Vlasenko8435d672013-02-18 15:47:57 +01001252#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001253int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001254sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001255{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001256 if (entering(tcp)) {
1257 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001258 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001259 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001260 printoldstat(tcp, tcp->u_arg[1]);
1261 }
1262 return 0;
1263}
Denys Vlasenko84703742012-02-25 02:38:52 +01001264#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001265
Denys Vlasenko9472a272013-02-12 11:43:46 +01001266#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001267
1268int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001269sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001270{
1271 if (entering(tcp)) {
1272 tprintf("%ld, ", tcp->u_arg[0]);
1273 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001274 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001275 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001276# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001277 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001278 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001279 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001280# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001281 printstat(tcp, tcp->u_arg[2]);
1282 }
1283 return 0;
1284}
1285
1286int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001287sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001288{
1289 if (entering(tcp))
1290 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1291 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001292# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001293 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001294 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001295 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001296# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001297 printstat(tcp, tcp->u_arg[2]);
1298 }
1299 return 0;
1300}
1301
1302int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001303sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001304{
1305 if (entering(tcp)) {
1306 tprintf("%ld, ", tcp->u_arg[0]);
1307 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001308 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001309 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001310# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001311 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001312 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001313 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001314# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001315 printstat(tcp, tcp->u_arg[2]);
1316 }
1317 return 0;
1318}
1319
1320int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001321sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001322{
1323 int mode = tcp->u_arg[2];
1324
1325 if (entering(tcp)) {
1326 tprintf("%ld, ", tcp->u_arg[0]);
1327 printpath(tcp, tcp->u_arg[1]);
1328 tprintf(", %s", sprintmode(mode));
1329 switch (mode & S_IFMT) {
1330 case S_IFCHR: case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001331 tprintf(", makedev(%lu, %lu)",
1332 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1333 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001334 break;
1335 default:
1336 break;
1337 }
1338 }
1339 return 0;
1340}
1341
Denys Vlasenko84703742012-02-25 02:38:52 +01001342# ifdef HAVE_SYS_ACL_H
Wichert Akkerman8829a551999-06-11 13:18:40 +00001343
Denys Vlasenko84703742012-02-25 02:38:52 +01001344# include <sys/acl.h>
Wichert Akkerman8829a551999-06-11 13:18:40 +00001345
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001346#include "xlat/aclcmds.h"
Wichert Akkerman8829a551999-06-11 13:18:40 +00001347
1348int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001349sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001350{
1351 if (entering(tcp)) {
1352 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001353 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001354 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1355 tprintf(", %ld", tcp->u_arg[2]);
1356 /*
1357 * FIXME - dump out the list of aclent_t's pointed to
1358 * by "tcp->u_arg[3]" if it's not NULL.
1359 */
1360 if (tcp->u_arg[3])
1361 tprintf(", %#lx", tcp->u_arg[3]);
1362 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001363 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001364 }
1365 return 0;
1366}
1367
Wichert Akkerman8829a551999-06-11 13:18:40 +00001368int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001369sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001370{
1371 if (entering(tcp)) {
1372 tprintf("%ld, ", tcp->u_arg[0]);
1373 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1374 tprintf(", %ld", tcp->u_arg[2]);
1375 /*
1376 * FIXME - dump out the list of aclent_t's pointed to
1377 * by "tcp->u_arg[3]" if it's not NULL.
1378 */
1379 if (tcp->u_arg[3])
1380 tprintf(", %#lx", tcp->u_arg[3]);
1381 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001382 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001383 }
1384 return 0;
1385}
1386
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001387#include "xlat/aclipc.h"
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001388
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001389int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001390sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001391{
1392 if (entering(tcp)) {
1393 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1394 tprintf(", %#lx, ", tcp->u_arg[1]);
1395 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1396 tprintf(", %ld", tcp->u_arg[3]);
1397 /*
1398 * FIXME - dump out the list of aclent_t's pointed to
1399 * by "tcp->u_arg[4]" if it's not NULL.
1400 */
1401 if (tcp->u_arg[4])
1402 tprintf(", %#lx", tcp->u_arg[4]);
1403 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001404 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001405 }
1406 return 0;
1407}
1408
Denys Vlasenko84703742012-02-25 02:38:52 +01001409# endif /* HAVE_SYS_ACL_H */
Wichert Akkerman8829a551999-06-11 13:18:40 +00001410
Denys Vlasenko9472a272013-02-12 11:43:46 +01001411#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001412
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413/* directory */
1414int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001415sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001416{
1417 if (entering(tcp)) {
1418 printpath(tcp, tcp->u_arg[0]);
1419 }
1420 return 0;
1421}
1422
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001423static int
1424decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001425{
1426 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001427 printpath(tcp, tcp->u_arg[offset]);
1428 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001429 }
1430 return 0;
1431}
1432
1433int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001434sys_mkdir(struct tcb *tcp)
1435{
1436 return decode_mkdir(tcp, 0);
1437}
1438
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001439int
1440sys_mkdirat(struct tcb *tcp)
1441{
1442 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001443 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001444 return decode_mkdir(tcp, 1);
1445}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001446
1447int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001448sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001449{
1450 if (entering(tcp)) {
1451 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001452 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001453 printpath(tcp, tcp->u_arg[1]);
1454 }
1455 return 0;
1456}
1457
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001458int
1459sys_linkat(struct tcb *tcp)
1460{
1461 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001462 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001463 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001464 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001465 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001466 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001467 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001468 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001469 }
1470 return 0;
1471}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001472
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001473int
1474sys_unlinkat(struct tcb *tcp)
1475{
1476 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001477 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001478 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001479 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001480 printflags(at_flags, tcp->u_arg[2], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001481 }
1482 return 0;
1483}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001484
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001485int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001486sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001487{
1488 if (entering(tcp)) {
1489 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001490 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001491 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001492 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001493 }
1494 return 0;
1495}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001496
1497static int
1498decode_readlink(struct tcb *tcp, int offset)
1499{
1500 if (entering(tcp)) {
1501 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001502 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001503 } else {
1504 if (syserror(tcp))
1505 tprintf("%#lx", tcp->u_arg[offset + 1]);
1506 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001507 /* Used to use printpathn(), but readlink
1508 * neither includes NUL in the returned count,
1509 * nor actually writes it into memory.
1510 * printpathn() would decide on printing
1511 * "..." continuation based on garbage
1512 * past return buffer's end.
1513 */
1514 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001515 tprintf(", %lu", tcp->u_arg[offset + 2]);
1516 }
1517 return 0;
1518}
1519
1520int
1521sys_readlink(struct tcb *tcp)
1522{
1523 return decode_readlink(tcp, 0);
1524}
1525
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001526int
1527sys_readlinkat(struct tcb *tcp)
1528{
1529 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001530 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001531 return decode_readlink(tcp, 1);
1532}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001533
Mike Frysinger5b677ab2014-08-14 04:05:41 -04001534static void
1535decode_renameat(struct tcb *tcp)
1536{
1537 print_dirfd(tcp, tcp->u_arg[0]);
1538 printpath(tcp, tcp->u_arg[1]);
1539 tprints(", ");
1540 print_dirfd(tcp, tcp->u_arg[2]);
1541 printpath(tcp, tcp->u_arg[3]);
1542}
1543
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001544int
1545sys_renameat(struct tcb *tcp)
1546{
1547 if (entering(tcp)) {
Mike Frysinger5b677ab2014-08-14 04:05:41 -04001548 decode_renameat(tcp);
1549 }
1550 return 0;
1551}
1552
1553#include "xlat/rename_flags.h"
1554
1555int
1556sys_renameat2(struct tcb *tcp)
1557{
1558 if (entering(tcp)) {
1559 decode_renameat(tcp);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001560 tprints(", ");
Mike Frysinger5b677ab2014-08-14 04:05:41 -04001561 printflags(rename_flags, tcp->u_arg[4], "RENAME_??");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001562 }
1563 return 0;
1564}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001565
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001566int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001567sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001568{
1569 if (entering(tcp)) {
1570 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001571 printuid(", ", tcp->u_arg[1]);
1572 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001573 }
1574 return 0;
1575}
1576
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001577int
1578sys_fchownat(struct tcb *tcp)
1579{
1580 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001581 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001582 printpath(tcp, tcp->u_arg[1]);
1583 printuid(", ", tcp->u_arg[2]);
1584 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001585 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001586 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001587 }
1588 return 0;
1589}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001590
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001591int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001592sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001593{
1594 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001595 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001596 printuid(", ", tcp->u_arg[1]);
1597 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001598 }
1599 return 0;
1600}
1601
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001602static int
1603decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001604{
1605 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001606 printpath(tcp, tcp->u_arg[offset]);
1607 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001608 }
1609 return 0;
1610}
1611
1612int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001613sys_chmod(struct tcb *tcp)
1614{
1615 return decode_chmod(tcp, 0);
1616}
1617
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001618int
1619sys_fchmodat(struct tcb *tcp)
1620{
1621 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001622 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001623 return decode_chmod(tcp, 1);
1624}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001625
1626int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001627sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001628{
1629 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001630 printfd(tcp, tcp->u_arg[0]);
1631 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001632 }
1633 return 0;
1634}
1635
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001636#ifdef ALPHA
1637int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001638sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001639{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001640 if (entering(tcp)) {
1641 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001642 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00001643 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
1644 }
1645 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001646}
1647#endif
1648
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001649static int
Roland McGrath6afc5652007-07-24 01:57:11 +00001650decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001651{
1652 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001653 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001654 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00001655 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001656 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00001657 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001658 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00001659 printtv_bitness(tcp, tcp->u_arg[offset + 1],
1660 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001661 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00001662 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001663 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00001664 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001665 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00001666 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001667 }
1668 return 0;
1669}
1670
1671int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001672sys_utimes(struct tcb *tcp)
1673{
Roland McGrath6afc5652007-07-24 01:57:11 +00001674 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001675}
1676
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001677int
1678sys_futimesat(struct tcb *tcp)
1679{
1680 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001681 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00001682 return decode_utimes(tcp, 1, 0);
1683}
1684
1685int
1686sys_utimensat(struct tcb *tcp)
1687{
1688 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001689 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00001690 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001691 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001692 printflags(at_flags, tcp->u_arg[3], "AT_???");
Roland McGrath6afc5652007-07-24 01:57:11 +00001693 }
1694 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001695}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001696
1697int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001698sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001699{
Roland McGrath7e9817c2007-07-05 20:31:58 +00001700 union {
1701 long utl[2];
1702 int uti[2];
Denys Vlasenko751acb32013-02-08 15:34:46 +01001703 long paranoia_for_huge_wordsize[4];
Roland McGrath7e9817c2007-07-05 20:31:58 +00001704 } u;
Denys Vlasenko751acb32013-02-08 15:34:46 +01001705 unsigned wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001706
1707 if (entering(tcp)) {
1708 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001709 tprints(", ");
Denys Vlasenko751acb32013-02-08 15:34:46 +01001710
1711 wordsize = current_wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001712 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001713 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001714 else if (!verbose(tcp))
1715 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001716 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001717 tprints("[?, ?]");
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001718 else if (wordsize == sizeof u.utl[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00001719 tprintf("[%s,", sprinttime(u.utl[0]));
1720 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001721 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001722 else if (wordsize == sizeof u.uti[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00001723 tprintf("[%s,", sprinttime(u.uti[0]));
1724 tprintf(" %s]", sprinttime(u.uti[1]));
1725 }
1726 else
Denys Vlasenko751acb32013-02-08 15:34:46 +01001727 tprintf("<decode error: unsupported wordsize %d>",
1728 wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001729 }
1730 return 0;
1731}
1732
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001733static int
1734decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001735{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001736 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001737
1738 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001739 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001740 tprintf(", %s", sprintmode(mode));
1741 switch (mode & S_IFMT) {
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001742 case S_IFCHR:
1743 case S_IFBLK:
Denys Vlasenko9472a272013-02-12 11:43:46 +01001744#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001745 if (current_personality == 1)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001746 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001747 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
1748 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001749 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00001750#endif
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001751 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001752 (unsigned long) major(tcp->u_arg[offset + 2]),
1753 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001754 break;
1755 default:
1756 break;
1757 }
1758 }
1759 return 0;
1760}
1761
1762int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001763sys_mknod(struct tcb *tcp)
1764{
1765 return decode_mknod(tcp, 0);
1766}
1767
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001768int
1769sys_mknodat(struct tcb *tcp)
1770{
1771 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001772 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001773 return decode_mknod(tcp, 1);
1774}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001775
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001776int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001777sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001778{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001779 if (exiting(tcp)) {
1780 if (syserror(tcp))
1781 tprintf("%#lx", tcp->u_arg[0]);
1782 else
1783 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
1784 tprintf(", %lu", tcp->u_arg[1]);
1785 }
1786 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001787}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001788
1789#ifdef HAVE_SYS_ASYNCH_H
1790
1791int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001792sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001793{
1794 struct aio_result_t res;
1795
1796 if (entering(tcp)) {
1797 tprintf("%lu, ", tcp->u_arg[0]);
1798 } else {
1799 if (syserror(tcp))
1800 tprintf("%#lx", tcp->u_arg[1]);
1801 else
1802 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1803 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
1804 printxval(whence, tcp->u_arg[4], "L_???");
1805 if (syserror(tcp) || tcp->u_arg[5] == 0
1806 || umove(tcp, tcp->u_arg[5], &res) < 0)
1807 tprintf(", %#lx", tcp->u_arg[5]);
1808 else
1809 tprintf(", {aio_return %d aio_errno %d}",
1810 res.aio_return, res.aio_errno);
1811 }
1812 return 0;
1813}
1814
1815int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001816sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001817{
1818 struct aio_result_t res;
1819
1820 if (entering(tcp)) {
1821 tprintf("%lu, ", tcp->u_arg[0]);
1822 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1823 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
1824 printxval(whence, tcp->u_arg[4], "L_???");
1825 }
1826 else {
1827 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001828 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001829 else if (syserror(tcp)
1830 || umove(tcp, tcp->u_arg[5], &res) < 0)
1831 tprintf(", %#lx", tcp->u_arg[5]);
1832 else
1833 tprintf(", {aio_return %d aio_errno %d}",
1834 res.aio_return, res.aio_errno);
1835 }
1836 return 0;
1837}
1838
1839int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001840sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001841{
1842 if (entering(tcp))
1843 printtv(tcp, tcp->u_arg[0]);
1844 return 0;
1845}
1846
1847int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001848sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001849{
1850 struct aio_result_t res;
1851
1852 if (exiting(tcp)) {
1853 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001854 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001855 else if (syserror(tcp)
1856 || umove(tcp, tcp->u_arg[0], &res) < 0)
1857 tprintf("%#lx", tcp->u_arg[0]);
1858 else
1859 tprintf("{aio_return %d aio_errno %d}",
1860 res.aio_return, res.aio_errno);
1861 }
1862 return 0;
1863}
1864
1865#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00001866
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001867#include "xlat/xattrflags.h"
Roland McGrath186c5ac2002-12-15 23:58:23 +00001868
Roland McGrath3292e222004-08-31 06:30:48 +00001869static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001870print_xattr_val(struct tcb *tcp, int failed,
1871 unsigned long arg,
1872 unsigned long insize,
1873 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00001874{
Dmitry V. Levin1f215132012-12-07 21:38:52 +00001875 if (insize == 0)
1876 failed = 1;
Denys Vlasenko1d632462009-04-14 12:51:00 +00001877 if (!failed) {
1878 unsigned long capacity = 4 * size + 1;
1879 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
1880 if (buf == NULL || /* probably a bogus size argument */
1881 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
1882 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00001883 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00001884 else {
1885 unsigned char *out = buf;
1886 unsigned char *in = &buf[3 * size];
1887 size_t i;
1888 for (i = 0; i < size; ++i) {
Denys Vlasenko5198ed42013-03-06 23:44:23 +01001889 if (in[i] >= ' ' && in[i] <= 0x7e)
Denys Vlasenko1d632462009-04-14 12:51:00 +00001890 *out++ = in[i];
1891 else {
1892#define tohex(n) "0123456789abcdef"[n]
1893 *out++ = '\\';
1894 *out++ = 'x';
1895 *out++ = tohex(in[i] / 16);
1896 *out++ = tohex(in[i] % 16);
1897 }
1898 }
1899 /* Don't print terminating NUL if there is one. */
1900 if (i > 0 && in[i - 1] == '\0')
1901 out -= 4;
1902 *out = '\0';
1903 tprintf(", \"%s\", %ld", buf, insize);
1904 }
1905 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00001906 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00001907 if (failed)
1908 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00001909}
1910
Roland McGrath186c5ac2002-12-15 23:58:23 +00001911int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001912sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00001913{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001914 if (entering(tcp)) {
1915 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001916 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00001917 printstr(tcp, tcp->u_arg[1], -1);
1918 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001919 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00001920 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
1921 }
1922 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00001923}
1924
1925int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001926sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00001927{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001928 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001929 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001930 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00001931 printstr(tcp, tcp->u_arg[1], -1);
1932 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001933 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00001934 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
1935 }
1936 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00001937}
1938
1939int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001940sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00001941{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001942 if (entering(tcp)) {
1943 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001944 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00001945 printstr(tcp, tcp->u_arg[1], -1);
1946 } else {
1947 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
1948 tcp->u_rval);
1949 }
1950 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00001951}
1952
1953int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001954sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00001955{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001956 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001957 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001958 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00001959 printstr(tcp, tcp->u_arg[1], -1);
1960 } else {
1961 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
1962 tcp->u_rval);
1963 }
1964 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00001965}
1966
Dmitry V. Levin33d24762012-03-14 16:34:32 +00001967static void
1968print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
1969{
1970 if (syserror(tcp)) {
1971 tprintf("%#lx", addr);
1972 } else {
1973 if (!addr) {
1974 tprints("NULL");
1975 } else {
1976 unsigned long len =
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +00001977 (size < (unsigned long) tcp->u_rval) ?
1978 size : (unsigned long) tcp->u_rval;
Dmitry V. Levin33d24762012-03-14 16:34:32 +00001979 printstr(tcp, addr, len);
1980 }
1981 }
1982 tprintf(", %lu", size);
1983}
1984
Roland McGrath186c5ac2002-12-15 23:58:23 +00001985int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001986sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00001987{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001988 if (entering(tcp)) {
1989 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00001990 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00001991 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00001992 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00001993 }
1994 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00001995}
1996
1997int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001998sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00001999{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002000 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002001 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002002 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002003 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002004 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002005 }
2006 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002007}
2008
2009int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002010sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002011{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002012 if (entering(tcp)) {
2013 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002014 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002015 printstr(tcp, tcp->u_arg[1], -1);
2016 }
2017 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002018}
2019
2020int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002021sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002022{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002023 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002024 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002025 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002026 printstr(tcp, tcp->u_arg[1], -1);
2027 }
2028 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002029}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002030
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00002031#include "xlat/advise.h"
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002032
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002033int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002034sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002035{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002036 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002037 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002038 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin3c49b022014-08-07 00:07:28 +00002039 argn = printllval(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002040 tprintf(", %ld, ", tcp->u_arg[argn++]);
2041 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002042 }
2043 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002044}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002045
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002046int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002047sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002048{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002049 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002050 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002051 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin3c49b022014-08-07 00:07:28 +00002052 argn = printllval(tcp, ", %lld, ", 1);
2053 argn = printllval(tcp, "%lld, ", argn);
Dmitry V. Levin8e096c42013-05-06 18:23:01 +00002054#if defined __ARM_EABI__ || defined AARCH64 || defined POWERPC || defined XTENSA
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002055 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002056#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002057 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002058#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002059 }
2060 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002061}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002062
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00002063#include "xlat/sync_file_range_flags.h"
William Manley16b9dcf2013-08-09 18:04:11 +01002064
2065int
2066sys_sync_file_range(struct tcb *tcp)
2067{
2068 if (entering(tcp)) {
2069 int argn;
2070 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin3c49b022014-08-07 00:07:28 +00002071 argn = printllval(tcp, ", %lld, ", 1);
2072 argn = printllval(tcp, "%lld, ", argn);
William Manley16b9dcf2013-08-09 18:04:11 +01002073 printflags(sync_file_range_flags, tcp->u_arg[argn],
2074 "SYNC_FILE_RANGE_???");
2075 }
2076 return 0;
2077}
2078
2079int
2080sys_sync_file_range2(struct tcb *tcp)
2081{
2082 if (entering(tcp)) {
2083 int argn;
2084 printfd(tcp, tcp->u_arg[0]);
2085 printflags(sync_file_range_flags, 1,
2086 "SYNC_FILE_RANGE_???");
Dmitry V. Levin3c49b022014-08-07 00:07:28 +00002087 argn = printllval(tcp, ", %lld, ", 2);
2088 argn = printllval(tcp, "%lld, ", argn);
William Manley16b9dcf2013-08-09 18:04:11 +01002089 }
2090 return 0;
2091}
2092
Mark Wielaardbab89402010-03-21 14:41:26 +01002093int
Roland McGrath96a96612008-05-20 04:56:18 +00002094sys_fallocate(struct tcb *tcp)
2095{
2096 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002097 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002098 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002099 tprintf(", %#lo, ", tcp->u_arg[1]); /* mode */
Dmitry V. Levin3c49b022014-08-07 00:07:28 +00002100 argn = printllval(tcp, "%llu, ", 2); /* offset */
2101 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002102 }
2103 return 0;
2104}
Dmitry V. Levin88293652012-03-09 21:02:19 +00002105
Dmitry V. Levinad0c01e2012-03-15 00:52:22 +00002106#ifndef SWAP_FLAG_PREFER
2107# define SWAP_FLAG_PREFER 0x8000
2108#endif
2109#ifndef SWAP_FLAG_DISCARD
2110# define SWAP_FLAG_DISCARD 0x10000
2111#endif
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00002112#include "xlat/swap_flags.h"
Dmitry V. Levin88293652012-03-09 21:02:19 +00002113
2114int
2115sys_swapon(struct tcb *tcp)
2116{
2117 if (entering(tcp)) {
2118 int flags = tcp->u_arg[1];
2119 printpath(tcp, tcp->u_arg[0]);
2120 tprints(", ");
2121 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2122 "SWAP_FLAG_???");
2123 if (flags & SWAP_FLAG_PREFER)
2124 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);
2125 }
2126 return 0;
2127}