blob: a92a7dcb1e85c03046e0876cd777df43406d5fb7 [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"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include <dirent.h>
Dmitry V. Levin88293652012-03-09 21:02:19 +000033#include <sys/swap.h>
Roland McGrathc531e572008-08-01 01:13:10 +000034
Denys Vlasenko9472a272013-02-12 11:43:46 +010035#if defined(SPARC) || defined(SPARC64)
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000036struct stat {
37 unsigned short st_dev;
38 unsigned int st_ino;
39 unsigned short st_mode;
40 short st_nlink;
41 unsigned short st_uid;
42 unsigned short st_gid;
43 unsigned short st_rdev;
44 unsigned int st_size;
45 int st_atime;
46 unsigned int __unused1;
47 int st_mtime;
48 unsigned int __unused2;
49 int st_ctime;
50 unsigned int __unused3;
51 int st_blksize;
52 int st_blocks;
53 unsigned int __unused4[2];
54};
Denys Vlasenko84703742012-02-25 02:38:52 +010055# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +000056struct stat_sparc64 {
57 unsigned int st_dev;
58 unsigned long st_ino;
59 unsigned int st_mode;
60 unsigned int st_nlink;
61 unsigned int st_uid;
62 unsigned int st_gid;
63 unsigned int st_rdev;
64 long st_size;
65 long st_atime;
66 long st_mtime;
67 long st_ctime;
68 long st_blksize;
69 long st_blocks;
70 unsigned long __unused4[2];
71};
Denys Vlasenko84703742012-02-25 02:38:52 +010072# endif /* SPARC64 */
73# define stat kernel_stat
74# include <asm/stat.h>
75# undef stat
H.J. Lu35be5812012-04-16 13:00:01 +020076#elif defined(X32)
77struct stat {
78 unsigned long long st_dev;
79 unsigned long long st_ino;
80 unsigned long long st_nlink;
81
82 unsigned int st_mode;
83 unsigned int st_uid;
84 unsigned int st_gid;
85 unsigned int __pad0;
86 unsigned long long st_rdev;
87 long long st_size;
88 long long st_blksize;
89 long long st_blocks;
90
91 unsigned long long st_atime;
92 unsigned long long st_atime_nsec;
93 unsigned long long st_mtime;
94 unsigned long long st_mtime_nsec;
95 unsigned long long st_ctime;
96 unsigned long long st_ctime_nsec;
97 long long __unused[3];
98};
H.J. Lu085e4282012-04-17 11:05:04 -070099
100struct stat64 {
101 unsigned long long st_dev;
102 unsigned char __pad0[4];
103 unsigned long __st_ino;
104 unsigned int st_mode;
105 unsigned int st_nlink;
106 unsigned long st_uid;
107 unsigned long st_gid;
108 unsigned long long st_rdev;
109 unsigned char __pad3[4];
110 long long st_size;
111 unsigned long st_blksize;
112 unsigned long long st_blocks;
113 unsigned long st_atime;
114 unsigned long st_atime_nsec;
115 unsigned long st_mtime;
116 unsigned int st_mtime_nsec;
117 unsigned long st_ctime;
118 unsigned long st_ctime_nsec;
119 unsigned long long st_ino;
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000120} __attribute__((packed));
121# define HAVE_STAT64 1
Dmitry V. Levinbd2e28a2013-05-01 15:14:25 +0000122
123struct __old_kernel_stat {
124 unsigned short st_dev;
125 unsigned short st_ino;
126 unsigned short st_mode;
127 unsigned short st_nlink;
128 unsigned short st_uid;
129 unsigned short st_gid;
130 unsigned short st_rdev;
131 unsigned int st_size;
132 unsigned int st_atime;
133 unsigned int st_mtime;
134 unsigned int st_ctime;
135};
Denys Vlasenko84703742012-02-25 02:38:52 +0100136#else
137# undef dev_t
138# undef ino_t
139# undef mode_t
140# undef nlink_t
141# undef uid_t
142# undef gid_t
143# undef off_t
144# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100145# define dev_t __kernel_dev_t
146# define ino_t __kernel_ino_t
147# define mode_t __kernel_mode_t
148# define nlink_t __kernel_nlink_t
149# define uid_t __kernel_uid_t
150# define gid_t __kernel_gid_t
151# define off_t __kernel_off_t
152# define loff_t __kernel_loff_t
Wichert Akkermana6013701999-07-08 14:00:58 +0000153
Denys Vlasenko84703742012-02-25 02:38:52 +0100154# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +0000155
Denys Vlasenko84703742012-02-25 02:38:52 +0100156# undef dev_t
157# undef ino_t
158# undef mode_t
159# undef nlink_t
160# undef uid_t
161# undef gid_t
162# undef off_t
163# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100164# define dev_t dev_t
165# define ino_t ino_t
166# define mode_t mode_t
167# define nlink_t nlink_t
168# define uid_t uid_t
169# define gid_t gid_t
170# define off_t off_t
171# define loff_t loff_t
172#endif
173
Denys Vlasenko84703742012-02-25 02:38:52 +0100174#define stat libc_stat
175#define stat64 libc_stat64
176#include <sys/stat.h>
177#undef stat
178#undef stat64
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100179/* These might be macros. */
Denys Vlasenko84703742012-02-25 02:38:52 +0100180#undef st_atime
181#undef st_mtime
182#undef st_ctime
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000183
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000184#include <fcntl.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000185#ifdef HAVE_SYS_VFS_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100186# include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000187#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +0000188#ifdef HAVE_LINUX_XATTR_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100189# include <linux/xattr.h>
Denys Vlasenkoed720fd2012-02-25 02:24:03 +0100190#else
Denys Vlasenko84703742012-02-25 02:38:52 +0100191# define XATTR_CREATE 1
192# define XATTR_REPLACE 2
Roland McGrath186c5ac2002-12-15 23:58:23 +0000193#endif
194
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000195#ifdef MAJOR_IN_SYSMACROS
Denys Vlasenko84703742012-02-25 02:38:52 +0100196# include <sys/sysmacros.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000197#endif
198
199#ifdef MAJOR_IN_MKDEV
Denys Vlasenko84703742012-02-25 02:38:52 +0100200# include <sys/mkdev.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000201#endif
202
203#ifdef HAVE_SYS_ASYNCH_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100204# include <sys/asynch.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205#endif
206
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100207struct kernel_dirent {
208 unsigned long d_ino;
209 unsigned long d_off;
210 unsigned short d_reclen;
211 char d_name[1];
212};
213
Dmitry V. Levin63ebcfc2014-04-26 15:35:02 +0000214#ifdef O_LARGEFILE
215# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
216# undef O_LARGEFILE
217# ifdef SPARC64
218# define O_LARGEFILE 0x40000
219# elif defined X86_64 || defined S390X
220# define O_LARGEFILE 0100000
221# endif
222# endif
223#endif
224
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000225#include "xlat/open_access_modes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000226#include "xlat/open_mode_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000227
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000228#ifndef AT_FDCWD
229# define AT_FDCWD -100
230#endif
231
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000232/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
233 * extension to get the right value. We do this by declaring fd as int here.
234 */
Dmitry V. Levin99db95d2014-02-05 04:13:18 +0000235void
Dmitry V. Levin31382132011-03-04 05:08:02 +0300236print_dirfd(struct tcb *tcp, int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000237{
238 if (fd == AT_FDCWD)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200239 tprints("AT_FDCWD, ");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200240 else {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300241 printfd(tcp, fd);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200242 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300243 }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000244}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000245
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000246/*
247 * low bits of the open(2) flags define access mode,
248 * other bits are real flags.
249 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000250const char *
251sprint_open_modes(mode_t flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000252{
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100253 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000254 char *p;
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100255 char sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000256 const char *str;
257 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000258
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100259 sep = ' ';
260 p = stpcpy(outstr, "flags");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000261 str = xlookup(open_access_modes, flags & 3);
262 if (str) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100263 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200264 p = stpcpy(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000265 flags &= ~3;
266 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000267 return outstr;
268 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000269 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000270
271 for (x = open_mode_flags; x->str; x++) {
272 if ((flags & x->val) == x->val) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100273 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200274 p = stpcpy(p, x->str);
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000275 flags &= ~x->val;
276 if (!flags)
277 return outstr;
278 sep = '|';
279 }
280 }
281 /* flags is still nonzero */
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100282 *p++ = sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000283 sprintf(p, "%#x", flags);
284 return outstr;
285}
286
287void
288tprint_open_modes(mode_t flags)
289{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200290 tprints(sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000291}
292
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000293static int
294decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000295{
296 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000297 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200298 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000299 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000300 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000301 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000302 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000303 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000304 }
305 }
Zubin Mithra64aa1b12014-06-04 08:30:41 +0530306 return RVAL_FD;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000307}
308
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000309int
310sys_open(struct tcb *tcp)
311{
312 return decode_open(tcp, 0);
313}
314
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000315int
316sys_openat(struct tcb *tcp)
317{
318 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300319 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000320 return decode_open(tcp, 1);
321}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000322
Denys Vlasenko9472a272013-02-12 11:43:46 +0100323#if defined(SPARC) || defined(SPARC64)
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000324#include "xlat/openmodessol.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000325
326int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000327solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000328{
329 if (entering(tcp)) {
330 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200331 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000332 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000333 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000334 if (tcp->u_arg[1] & 0x100) {
335 /* mode */
336 tprintf(", %#lo", tcp->u_arg[2]);
337 }
338 }
339 return 0;
340}
341
342#endif
343
344int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000345sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000346{
347 if (entering(tcp)) {
348 printpath(tcp, tcp->u_arg[0]);
349 tprintf(", %#lo", tcp->u_arg[1]);
350 }
Zubin Mithra64aa1b12014-06-04 08:30:41 +0530351 return RVAL_FD;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000352}
353
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000354#include "xlat/access_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000355
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000356static int
357decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000358{
359 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000360 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200361 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000362 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000363 }
364 return 0;
365}
366
367int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000368sys_access(struct tcb *tcp)
369{
370 return decode_access(tcp, 0);
371}
372
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000373int
374sys_faccessat(struct tcb *tcp)
375{
376 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300377 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000378 return decode_access(tcp, 1);
379}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000380
381int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000382sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000383{
384 if (entering(tcp)) {
385 tprintf("%#lo", tcp->u_arg[0]);
386 }
387 return RVAL_OCTAL;
388}
389
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000390#include "xlat/whence_codes.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000391
Denys Vlasenko386b8712013-02-17 01:38:14 +0100392/* Linux kernel has exactly one version of lseek:
393 * fs/read_write.c::SYSCALL_DEFINE3(lseek, unsigned, fd, off_t, offset, unsigned, origin)
394 * In kernel, off_t is always the same as (kernel's) long
395 * (see include/uapi/asm-generic/posix_types.h),
396 * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument.
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100397 * Use test/x32_lseek.c to test lseek decoding.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100398 */
H.J. Luc933f272012-04-16 17:41:13 +0200399#if defined(LINUX_MIPSN32) || defined(X32)
Roland McGrath542c2c62008-05-20 01:11:56 +0000400int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000401sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000402{
403 long long offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100404 int whence;
Roland McGrath542c2c62008-05-20 01:11:56 +0000405
406 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300407 printfd(tcp, tcp->u_arg[0]);
Roland McGrath542c2c62008-05-20 01:11:56 +0000408 offset = tcp->ext_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100409 whence = tcp->u_arg[2];
410 if (whence == SEEK_SET)
411 tprintf(", %llu, ", offset);
Roland McGrath542c2c62008-05-20 01:11:56 +0000412 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100413 tprintf(", %lld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100414 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath542c2c62008-05-20 01:11:56 +0000415 }
H.J. Ludd0130b2012-04-16 12:16:45 +0200416 return RVAL_LUDECIMAL;
Roland McGrath542c2c62008-05-20 01:11:56 +0000417}
H.J. Ludd0130b2012-04-16 12:16:45 +0200418#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000419int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000420sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000421{
Denys Vlasenko06121762013-02-17 20:08:50 +0100422 long offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100423 int whence;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000424
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000425 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300426 printfd(tcp, tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000427 offset = tcp->u_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100428 whence = tcp->u_arg[2];
429 if (whence == SEEK_SET)
430 tprintf(", %lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000431 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100432 tprintf(", %ld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100433 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000434 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000435 return RVAL_UDECIMAL;
436}
John Hughes5a826b82001-03-07 13:21:24 +0000437#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438
Denys Vlasenko386b8712013-02-17 01:38:14 +0100439/* llseek syscall takes explicitly two ulong arguments hi, lo,
440 * rather than one 64-bit argument for which LONG_LONG works
441 * appropriate for the native byte order.
442 *
443 * See kernel's fs/read_write.c::SYSCALL_DEFINE5(llseek, ...)
444 *
445 * hi,lo are "unsigned longs" and combined exactly this way in kernel:
446 * ((loff_t) hi << 32) | lo
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100447 * Note that for architectures with kernel's long wider than userspace long
Denys Vlasenko386b8712013-02-17 01:38:14 +0100448 * (such as x32), combining code will use *kernel's*, i.e. *wide* longs
Denys Vlasenko06121762013-02-17 20:08:50 +0100449 * for hi and lo. We would need to use tcp->ext_arg[N] on x32...
450 * ...however, x32 (and x86_64) does not _have_ llseek syscall as such.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100451 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000452int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000453sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000454{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000455 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300456 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000457 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300458 tprintf(", %llu, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100459 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300460 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000461 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300462 tprintf(", %lld, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100463 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300464 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000465 }
466 else {
Denys Vlasenko386b8712013-02-17 01:38:14 +0100467 long long off;
Denys Vlasenko1d632462009-04-14 12:51:00 +0000468 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
469 tprintf("%#lx, ", tcp->u_arg[3]);
470 else
471 tprintf("[%llu], ", off);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100472 printxval(whence_codes, tcp->u_arg[4], "SEEK_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000473 }
474 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000475}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000476
477int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000478sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000479{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000480 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100481 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300482 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin7845a422014-04-17 13:32:47 +0000483 argn = printllval_aligned(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100484 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000485 }
486 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000487}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000488
489int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000490sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000491{
492 if (entering(tcp)) {
493 printpath(tcp, tcp->u_arg[0]);
494 tprintf(", %lu", tcp->u_arg[1]);
495 }
496 return 0;
497}
498
John Hughes96f51472001-03-06 16:50:41 +0000499int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000500sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000501{
502 if (entering(tcp)) {
503 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin7845a422014-04-17 13:32:47 +0000504 printllval_aligned(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000505 }
506 return 0;
507}
John Hughes96f51472001-03-06 16:50:41 +0000508
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000509int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000510sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000511{
512 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300513 printfd(tcp, tcp->u_arg[0]);
514 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000515 }
516 return 0;
517}
518
John Hughes96f51472001-03-06 16:50:41 +0000519int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000520sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000521{
522 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300523 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin7845a422014-04-17 13:32:47 +0000524 printllval_aligned(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000525 }
526 return 0;
527}
John Hughes96f51472001-03-06 16:50:41 +0000528
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000529/* several stats */
530
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000531#include "xlat/modetypes.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000532
Roland McGrathf9c49b22004-10-06 22:11:54 +0000533static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000534sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000535{
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100536 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
537 + sizeof(int)*3
538 + /*paranoia:*/ 8];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000539 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000540
541 if ((mode & S_IFMT) == 0)
542 s = "";
543 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
544 sprintf(buf, "%#o", mode);
545 return buf;
546 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100547 s = buf + sprintf(buf, "%s%s%s%s", s,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000548 (mode & S_ISUID) ? "|S_ISUID" : "",
549 (mode & S_ISGID) ? "|S_ISGID" : "",
550 (mode & S_ISVTX) ? "|S_ISVTX" : "");
551 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
552 if (mode)
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100553 sprintf((char*)s, "|%#o", mode);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000554 s = (*buf == '|') ? buf + 1 : buf;
555 return *s ? s : "0";
556}
557
558static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000559sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000560{
561 struct tm *tmp;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100562 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000563
564 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000565 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000566 return buf;
567 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200568 tmp = localtime(&t);
569 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000570 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
571 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
572 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
573 else
574 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
575
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000576 return buf;
577}
578
Denys Vlasenko9472a272013-02-12 11:43:46 +0100579#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000580typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000581 int tv_sec;
582 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000583} timestruct_t;
584
585struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000586 unsigned st_dev;
587 int st_pad1[3]; /* network id */
588 unsigned st_ino;
589 unsigned st_mode;
590 unsigned st_nlink;
591 unsigned st_uid;
592 unsigned st_gid;
593 unsigned st_rdev;
594 int st_pad2[2];
595 int st_size;
596 int st_pad3; /* st_size, off_t expansion */
597 timestruct_t st_atime;
598 timestruct_t st_mtime;
599 timestruct_t st_ctime;
600 int st_blksize;
601 int st_blocks;
602 char st_fstype[16];
603 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000604};
605
606static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000607printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000608{
609 struct solstat statbuf;
610
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000611 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200612 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000613 return;
614 }
615 if (!abbrev(tcp)) {
616 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
617 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
618 (unsigned long) (statbuf.st_dev & 0x3ffff),
619 (unsigned long) statbuf.st_ino,
620 sprintmode(statbuf.st_mode));
621 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
622 (unsigned long) statbuf.st_nlink,
623 (unsigned long) statbuf.st_uid,
624 (unsigned long) statbuf.st_gid);
625 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
626 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
627 }
628 else
629 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
630 switch (statbuf.st_mode & S_IFMT) {
631 case S_IFCHR: case S_IFBLK:
632 tprintf("st_rdev=makedev(%lu, %lu), ",
633 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
634 (unsigned long) (statbuf.st_rdev & 0x3ffff));
635 break;
636 default:
637 tprintf("st_size=%u, ", statbuf.st_size);
638 break;
639 }
640 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000641 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
642 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
643 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000644 }
645 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200646 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000647}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000648
Denys Vlasenko9472a272013-02-12 11:43:46 +0100649# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000650static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000651printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000652{
653 struct stat_sparc64 statbuf;
654
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000655 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200656 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000657 return;
658 }
659
660 if (!abbrev(tcp)) {
661 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
662 (unsigned long) major(statbuf.st_dev),
663 (unsigned long) minor(statbuf.st_dev),
664 (unsigned long) statbuf.st_ino,
665 sprintmode(statbuf.st_mode));
666 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
667 (unsigned long) statbuf.st_nlink,
668 (unsigned long) statbuf.st_uid,
669 (unsigned long) statbuf.st_gid);
670 tprintf("st_blksize=%lu, ",
671 (unsigned long) statbuf.st_blksize);
672 tprintf("st_blocks=%lu, ",
673 (unsigned long) statbuf.st_blocks);
674 }
675 else
676 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
677 switch (statbuf.st_mode & S_IFMT) {
678 case S_IFCHR: case S_IFBLK:
679 tprintf("st_rdev=makedev(%lu, %lu), ",
680 (unsigned long) major(statbuf.st_rdev),
681 (unsigned long) minor(statbuf.st_rdev));
682 break;
683 default:
684 tprintf("st_size=%lu, ", statbuf.st_size);
685 break;
686 }
687 if (!abbrev(tcp)) {
688 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
689 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100690 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000691 }
692 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200693 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000694}
Denys Vlasenko9472a272013-02-12 11:43:46 +0100695# endif /* SPARC64 */
696#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000697
Denys Vlasenko84703742012-02-25 02:38:52 +0100698#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200699struct stat_powerpc32 {
700 unsigned int st_dev;
701 unsigned int st_ino;
702 unsigned int st_mode;
703 unsigned short st_nlink;
704 unsigned int st_uid;
705 unsigned int st_gid;
706 unsigned int st_rdev;
707 unsigned int st_size;
708 unsigned int st_blksize;
709 unsigned int st_blocks;
710 unsigned int st_atime;
711 unsigned int st_atime_nsec;
712 unsigned int st_mtime;
713 unsigned int st_mtime_nsec;
714 unsigned int st_ctime;
715 unsigned int st_ctime_nsec;
716 unsigned int __unused4;
717 unsigned int __unused5;
718};
719
720static void
721printstat_powerpc32(struct tcb *tcp, long addr)
722{
723 struct stat_powerpc32 statbuf;
724
725 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200726 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200727 return;
728 }
729
730 if (!abbrev(tcp)) {
731 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
732 major(statbuf.st_dev), minor(statbuf.st_dev),
733 statbuf.st_ino,
734 sprintmode(statbuf.st_mode));
735 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
736 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
737 tprintf("st_blksize=%u, ", statbuf.st_blksize);
738 tprintf("st_blocks=%u, ", statbuf.st_blocks);
739 }
740 else
741 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
742 switch (statbuf.st_mode & S_IFMT) {
743 case S_IFCHR: case S_IFBLK:
744 tprintf("st_rdev=makedev(%lu, %lu), ",
745 (unsigned long) major(statbuf.st_rdev),
746 (unsigned long) minor(statbuf.st_rdev));
747 break;
748 default:
749 tprintf("st_size=%u, ", statbuf.st_size);
750 break;
751 }
752 if (!abbrev(tcp)) {
753 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
754 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100755 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200756 }
757 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200758 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200759}
Denys Vlasenko84703742012-02-25 02:38:52 +0100760#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200761
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000762#include "xlat/fileflags.h"
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000763
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000764static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000765realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000766{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000767 if (!abbrev(tcp)) {
768 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
769 (unsigned long) major(statbuf->st_dev),
770 (unsigned long) minor(statbuf->st_dev),
771 (unsigned long) statbuf->st_ino,
772 sprintmode(statbuf->st_mode));
773 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
774 (unsigned long) statbuf->st_nlink,
775 (unsigned long) statbuf->st_uid,
776 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000777#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000778 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
779#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000780#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000781 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
782#endif
783 }
784 else
785 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
786 switch (statbuf->st_mode & S_IFMT) {
787 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000788#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000789 tprintf("st_rdev=makedev(%lu, %lu), ",
790 (unsigned long) major(statbuf->st_rdev),
791 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000792#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000793 tprintf("st_size=makedev(%lu, %lu), ",
794 (unsigned long) major(statbuf->st_size),
795 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000796#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000797 break;
798 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000799 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000800 break;
801 }
802 if (!abbrev(tcp)) {
803 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
804 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
805 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000806#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200807 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000808 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000809#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000810#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000811 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
812#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000813#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000814 tprintf(", st_level=%ld", statbuf->st_level);
815#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000816#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000817 tprintf(", st_fstype=%.*s",
818 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
819#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000820#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000821 tprintf(", st_gen=%u", statbuf->st_gen);
822#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200823 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000824 }
825 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200826 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000827}
828
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000829#ifndef X32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000830static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000831printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000832{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000833 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000834
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000835 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200836 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000837 return;
838 }
839 if (syserror(tcp) || !verbose(tcp)) {
840 tprintf("%#lx", addr);
841 return;
842 }
843
Denys Vlasenko9472a272013-02-12 11:43:46 +0100844#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000845 if (current_personality == 1) {
846 printstatsol(tcp, addr);
847 return;
848 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000849#ifdef SPARC64
850 else if (current_personality == 2) {
851 printstat_sparc64(tcp, addr);
852 return;
853 }
854#endif
Denys Vlasenko9472a272013-02-12 11:43:46 +0100855#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000856
Denys Vlasenko84703742012-02-25 02:38:52 +0100857#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200858 if (current_personality == 1) {
859 printstat_powerpc32(tcp, addr);
860 return;
861 }
862#endif
863
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000864 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200865 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000866 return;
867 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000868
869 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000870}
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000871#else /* X32 */
872# define printstat printstat64
873#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000874
Elliott Hughes391c0d82014-04-03 17:50:14 -0700875#if !defined HAVE_STAT64 && (defined AARCH64 || defined X86_64)
Roland McGrathe6d0f712007-08-07 01:22:49 +0000876/*
877 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
878 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
879 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
880 * __GNUC__ is needed for the required __attribute__ below.
Elliott Hughes391c0d82014-04-03 17:50:14 -0700881 *
882 * Similarly, aarch64 has a unified `struct stat' but its arm personality
883 * needs `struct stat64' (which also expects a 32-bit `long' but which
884 * shouldn't be packed).
Roland McGrathe6d0f712007-08-07 01:22:49 +0000885 */
886struct stat64 {
887 unsigned long long st_dev;
888 unsigned char __pad0[4];
889 unsigned int __st_ino;
890 unsigned int st_mode;
891 unsigned int st_nlink;
892 unsigned int st_uid;
893 unsigned int st_gid;
894 unsigned long long st_rdev;
895 unsigned char __pad3[4];
896 long long st_size;
897 unsigned int st_blksize;
898 unsigned long long st_blocks;
899 unsigned int st_atime;
900 unsigned int st_atime_nsec;
901 unsigned int st_mtime;
902 unsigned int st_mtime_nsec;
903 unsigned int st_ctime;
904 unsigned int st_ctime_nsec;
905 unsigned long long st_ino;
Elliott Hughes391c0d82014-04-03 17:50:14 -0700906}
907# if defined X86_64
908 __attribute__((packed))
909# define STAT64_SIZE 96
910#else
911# define STAT64_SIZE 104
912# endif
913;
Roland McGrathe6d0f712007-08-07 01:22:49 +0000914# define HAVE_STAT64 1
Roland McGrathe6d0f712007-08-07 01:22:49 +0000915#endif
916
Wichert Akkermanc7926982000-04-10 22:22:31 +0000917#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000918static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000919printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000920{
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000921#ifdef X32
922 struct stat statbuf;
923#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000924 struct stat64 statbuf;
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000925#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000926
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000927#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +0000928 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
929#endif
930
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000931 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200932 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000933 return;
934 }
935 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000936 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000937 return;
938 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000939
Denys Vlasenko9472a272013-02-12 11:43:46 +0100940#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000941 if (current_personality == 1) {
942 printstatsol(tcp, addr);
943 return;
944 }
945# ifdef SPARC64
946 else if (current_personality == 2) {
947 printstat_sparc64(tcp, addr);
948 return;
949 }
950# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +0100951#endif /* SPARC[64] */
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000952
Elliott Hughes391c0d82014-04-03 17:50:14 -0700953#if defined AARCH64
954 if (current_personality != 0) {
955 printstat(tcp, addr);
956 return;
957 }
958#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100959#if defined X86_64
H.J. Lu35be5812012-04-16 13:00:01 +0200960 if (current_personality != 1) {
Andreas Schwab61b74352009-10-16 11:37:13 +0200961 printstat(tcp, addr);
962 return;
963 }
964#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +0000965
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000966 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200967 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000968 return;
969 }
970
971 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +0000972 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000973 (unsigned long) major(statbuf.st_dev),
974 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +0000975 (unsigned long long) statbuf.st_ino,
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000976 sprintmode(statbuf.st_mode));
977 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
978 (unsigned long) statbuf.st_nlink,
979 (unsigned long) statbuf.st_uid,
980 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000981#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000982 tprintf("st_blksize=%lu, ",
983 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000984#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
985#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000986 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000987#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000988 }
989 else
990 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
991 switch (statbuf.st_mode & S_IFMT) {
992 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000993#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000994 tprintf("st_rdev=makedev(%lu, %lu), ",
995 (unsigned long) major(statbuf.st_rdev),
996 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000997#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000998 tprintf("st_size=makedev(%lu, %lu), ",
999 (unsigned long) major(statbuf.st_size),
1000 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001001#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001002 break;
1003 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001004 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001005 break;
1006 }
1007 if (!abbrev(tcp)) {
1008 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1009 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001010 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001011#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001012 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001013 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001014#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001015#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001016 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1017#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001018#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001019 tprintf(", st_level=%ld", statbuf.st_level);
1020#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001021#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001022 tprintf(", st_fstype=%.*s",
1023 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1024#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001025#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001026 tprintf(", st_gen=%u", statbuf.st_gen);
1027#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001028 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001029 }
1030 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001031 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001032}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001033#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001034
Denys Vlasenko8435d672013-02-18 15:47:57 +01001035#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001036static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001037convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001038{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001039 newbuf->st_dev = oldbuf->st_dev;
1040 newbuf->st_ino = oldbuf->st_ino;
1041 newbuf->st_mode = oldbuf->st_mode;
1042 newbuf->st_nlink = oldbuf->st_nlink;
1043 newbuf->st_uid = oldbuf->st_uid;
1044 newbuf->st_gid = oldbuf->st_gid;
1045 newbuf->st_rdev = oldbuf->st_rdev;
1046 newbuf->st_size = oldbuf->st_size;
1047 newbuf->st_atime = oldbuf->st_atime;
1048 newbuf->st_mtime = oldbuf->st_mtime;
1049 newbuf->st_ctime = oldbuf->st_ctime;
1050 newbuf->st_blksize = 0; /* not supported in old_stat */
1051 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001052}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001053
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001054static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001055printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001056{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001057 struct __old_kernel_stat statbuf;
1058 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001059
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001060 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001061 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001062 return;
1063 }
1064 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001065 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001066 return;
1067 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001068
Denys Vlasenko9472a272013-02-12 11:43:46 +01001069# if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001070 if (current_personality == 1) {
1071 printstatsol(tcp, addr);
1072 return;
1073 }
Denys Vlasenko84703742012-02-25 02:38:52 +01001074# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001075
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001076 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001077 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001078 return;
1079 }
1080
1081 convertoldstat(&statbuf, &newstatbuf);
1082 realprintstat(tcp, &newstatbuf);
1083}
Denys Vlasenko84703742012-02-25 02:38:52 +01001084#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001085
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001086int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001087sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001088{
1089 if (entering(tcp)) {
1090 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001091 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001092 } else {
1093 printstat(tcp, tcp->u_arg[1]);
1094 }
1095 return 0;
1096}
1097
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001098#ifdef X32
1099static void
1100printstat64_x32(struct tcb *tcp, long addr)
1101{
1102 struct stat64 statbuf;
1103
1104 if (!addr) {
1105 tprints("NULL");
1106 return;
1107 }
1108 if (syserror(tcp) || !verbose(tcp)) {
1109 tprintf("%#lx", addr);
1110 return;
1111 }
1112
1113 if (umove(tcp, addr, &statbuf) < 0) {
1114 tprints("{...}");
1115 return;
1116 }
1117
1118 if (!abbrev(tcp)) {
1119 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1120 (unsigned long) major(statbuf.st_dev),
1121 (unsigned long) minor(statbuf.st_dev),
1122 (unsigned long long) statbuf.st_ino,
1123 sprintmode(statbuf.st_mode));
1124 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1125 (unsigned long) statbuf.st_nlink,
1126 (unsigned long) statbuf.st_uid,
1127 (unsigned long) statbuf.st_gid);
1128 tprintf("st_blksize=%lu, ",
1129 (unsigned long) statbuf.st_blksize);
1130 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1131 }
1132 else
1133 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1134 switch (statbuf.st_mode & S_IFMT) {
1135 case S_IFCHR: case S_IFBLK:
1136 tprintf("st_rdev=makedev(%lu, %lu), ",
1137 (unsigned long) major(statbuf.st_rdev),
1138 (unsigned long) minor(statbuf.st_rdev));
1139 break;
1140 default:
1141 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1142 break;
1143 }
1144 if (!abbrev(tcp)) {
1145 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1146 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1147 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1148 tprints("}");
1149 }
1150 else
1151 tprints("...}");
1152}
1153#endif /* X32 */
1154
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001155int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001156sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001157{
1158#ifdef HAVE_STAT64
1159 if (entering(tcp)) {
1160 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001161 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001162 } else {
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001163# ifdef X32
1164 printstat64_x32(tcp, tcp->u_arg[1]);
1165# else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001166 printstat64(tcp, tcp->u_arg[1]);
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001167# endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001168 }
1169 return 0;
1170#else
1171 return printargs(tcp);
1172#endif
1173}
1174
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001175#ifndef AT_SYMLINK_NOFOLLOW
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001176# define AT_SYMLINK_NOFOLLOW 0x100
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001177#endif
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001178#ifndef AT_REMOVEDIR
1179# define AT_REMOVEDIR 0x200
1180#endif
1181#ifndef AT_SYMLINK_FOLLOW
1182# define AT_SYMLINK_FOLLOW 0x400
1183#endif
1184#ifndef AT_NO_AUTOMOUNT
1185# define AT_NO_AUTOMOUNT 0x800
1186#endif
1187#ifndef AT_EMPTY_PATH
1188# define AT_EMPTY_PATH 0x1000
1189#endif
1190
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001191#include "xlat/at_flags.h"
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001192
1193int
1194sys_newfstatat(struct tcb *tcp)
1195{
1196 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001197 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001198 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001199 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001200 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001201#ifdef POWERPC64
1202 if (current_personality == 0)
1203 printstat(tcp, tcp->u_arg[2]);
1204 else
1205 printstat64(tcp, tcp->u_arg[2]);
1206#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001207 printstat64(tcp, tcp->u_arg[2]);
1208#else
1209 printstat(tcp, tcp->u_arg[2]);
1210#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001211 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001212 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001213 }
1214 return 0;
1215}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001216
Denys Vlasenko8435d672013-02-18 15:47:57 +01001217#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001218int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001219sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001220{
1221 if (entering(tcp)) {
1222 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001223 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001224 } else {
1225 printoldstat(tcp, tcp->u_arg[1]);
1226 }
1227 return 0;
1228}
Denys Vlasenko84703742012-02-25 02:38:52 +01001229#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001230
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001231int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001232sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001233{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001234 if (entering(tcp)) {
1235 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001236 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001237 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001238 printstat(tcp, tcp->u_arg[1]);
1239 }
1240 return 0;
1241}
1242
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001243int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001244sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001245{
1246#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001247 if (entering(tcp)) {
1248 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001249 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001250 } else {
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001251# ifdef X32
1252 printstat64_x32(tcp, tcp->u_arg[1]);
1253# else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001254 printstat64(tcp, tcp->u_arg[1]);
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001255# endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001256 }
1257 return 0;
1258#else
1259 return printargs(tcp);
1260#endif
1261}
1262
Denys Vlasenko8435d672013-02-18 15:47:57 +01001263#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001264int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001265sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001266{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001267 if (entering(tcp)) {
1268 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001269 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001270 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001271 printoldstat(tcp, tcp->u_arg[1]);
1272 }
1273 return 0;
1274}
Denys Vlasenko84703742012-02-25 02:38:52 +01001275#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001276
Denys Vlasenko9472a272013-02-12 11:43:46 +01001277#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001278
1279int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001280sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001281{
1282 if (entering(tcp)) {
1283 tprintf("%ld, ", tcp->u_arg[0]);
1284 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001285 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001286 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001287# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001288 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001289 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001290 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001291# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292 printstat(tcp, tcp->u_arg[2]);
1293 }
1294 return 0;
1295}
1296
1297int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001298sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001299{
1300 if (entering(tcp))
1301 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1302 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001303# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001304 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001305 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001306 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001307# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001308 printstat(tcp, tcp->u_arg[2]);
1309 }
1310 return 0;
1311}
1312
1313int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001314sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001315{
1316 if (entering(tcp)) {
1317 tprintf("%ld, ", tcp->u_arg[0]);
1318 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001319 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001320 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001321# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001322 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001323 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001324 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001325# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001326 printstat(tcp, tcp->u_arg[2]);
1327 }
1328 return 0;
1329}
1330
1331int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001332sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001333{
1334 int mode = tcp->u_arg[2];
1335
1336 if (entering(tcp)) {
1337 tprintf("%ld, ", tcp->u_arg[0]);
1338 printpath(tcp, tcp->u_arg[1]);
1339 tprintf(", %s", sprintmode(mode));
1340 switch (mode & S_IFMT) {
1341 case S_IFCHR: case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001342 tprintf(", makedev(%lu, %lu)",
1343 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1344 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001345 break;
1346 default:
1347 break;
1348 }
1349 }
1350 return 0;
1351}
1352
Denys Vlasenko84703742012-02-25 02:38:52 +01001353# ifdef HAVE_SYS_ACL_H
Wichert Akkerman8829a551999-06-11 13:18:40 +00001354
Denys Vlasenko84703742012-02-25 02:38:52 +01001355# include <sys/acl.h>
Wichert Akkerman8829a551999-06-11 13:18:40 +00001356
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001357#include "xlat/aclcmds.h"
Wichert Akkerman8829a551999-06-11 13:18:40 +00001358
1359int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001360sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001361{
1362 if (entering(tcp)) {
1363 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001364 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001365 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1366 tprintf(", %ld", tcp->u_arg[2]);
1367 /*
1368 * FIXME - dump out the list of aclent_t's pointed to
1369 * by "tcp->u_arg[3]" if it's not NULL.
1370 */
1371 if (tcp->u_arg[3])
1372 tprintf(", %#lx", tcp->u_arg[3]);
1373 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001374 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001375 }
1376 return 0;
1377}
1378
Wichert Akkerman8829a551999-06-11 13:18:40 +00001379int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001380sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001381{
1382 if (entering(tcp)) {
1383 tprintf("%ld, ", tcp->u_arg[0]);
1384 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1385 tprintf(", %ld", tcp->u_arg[2]);
1386 /*
1387 * FIXME - dump out the list of aclent_t's pointed to
1388 * by "tcp->u_arg[3]" if it's not NULL.
1389 */
1390 if (tcp->u_arg[3])
1391 tprintf(", %#lx", tcp->u_arg[3]);
1392 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001393 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001394 }
1395 return 0;
1396}
1397
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001398#include "xlat/aclipc.h"
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001399
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001400int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001401sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001402{
1403 if (entering(tcp)) {
1404 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1405 tprintf(", %#lx, ", tcp->u_arg[1]);
1406 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1407 tprintf(", %ld", tcp->u_arg[3]);
1408 /*
1409 * FIXME - dump out the list of aclent_t's pointed to
1410 * by "tcp->u_arg[4]" if it's not NULL.
1411 */
1412 if (tcp->u_arg[4])
1413 tprintf(", %#lx", tcp->u_arg[4]);
1414 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001415 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001416 }
1417 return 0;
1418}
1419
Denys Vlasenko84703742012-02-25 02:38:52 +01001420# endif /* HAVE_SYS_ACL_H */
Wichert Akkerman8829a551999-06-11 13:18:40 +00001421
Denys Vlasenko9472a272013-02-12 11:43:46 +01001422#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001423
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001424#include "xlat/fsmagic.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001425
Roland McGrathf9c49b22004-10-06 22:11:54 +00001426static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001427sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001428{
1429 static char buf[32];
Roland McGrathf9c49b22004-10-06 22:11:54 +00001430 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001431
1432 s = xlookup(fsmagic, magic);
1433 if (s) {
1434 sprintf(buf, "\"%s\"", s);
1435 return buf;
1436 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001437 sprintf(buf, "%#x", magic);
1438 return buf;
1439}
1440
1441static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001442printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001443{
1444 struct statfs statbuf;
1445
1446 if (syserror(tcp) || !verbose(tcp)) {
1447 tprintf("%#lx", addr);
1448 return;
1449 }
1450 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001451 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001452 return;
1453 }
1454#ifdef ALPHA
1455
1456 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1457 sprintfstype(statbuf.f_type),
1458 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001459 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001460 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001461 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1462 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001463#else /* !ALPHA */
1464 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1465 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001466 (unsigned long)statbuf.f_bsize,
1467 (unsigned long)statbuf.f_blocks,
1468 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001469 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1470 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001471 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001472 (unsigned long)statbuf.f_ffree,
1473 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001474 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001475#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001476#ifdef _STATFS_F_FRSIZE
1477 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1478#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001479 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001480}
1481
1482int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001483sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001484{
1485 if (entering(tcp)) {
1486 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001487 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001488 } else {
1489 printstatfs(tcp, tcp->u_arg[1]);
1490 }
1491 return 0;
1492}
1493
1494int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001495sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001496{
1497 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001498 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001499 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001500 } else {
1501 printstatfs(tcp, tcp->u_arg[1]);
1502 }
1503 return 0;
1504}
1505
Denys Vlasenko84703742012-02-25 02:38:52 +01001506#if defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001507static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001508printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001509{
1510 struct statfs64 statbuf;
1511
1512 if (syserror(tcp) || !verbose(tcp)) {
1513 tprintf("%#lx", addr);
1514 return;
1515 }
1516 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001517 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001518 return;
1519 }
Roland McGrath08738432005-06-03 02:40:39 +00001520 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001521 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001522 (unsigned long long)statbuf.f_bsize,
1523 (unsigned long long)statbuf.f_blocks,
1524 (unsigned long long)statbuf.f_bfree);
1525 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1526 (unsigned long long)statbuf.f_bavail,
1527 (unsigned long long)statbuf.f_files,
1528 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001529 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1530 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001531#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001532 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001533#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001534#ifdef _STATFS_F_FLAGS
1535 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1536#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001537 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001538}
1539
Andreas Schwab7d558012012-01-17 18:14:22 +01001540struct compat_statfs64 {
1541 uint32_t f_type;
1542 uint32_t f_bsize;
1543 uint64_t f_blocks;
1544 uint64_t f_bfree;
1545 uint64_t f_bavail;
1546 uint64_t f_files;
1547 uint64_t f_ffree;
1548 fsid_t f_fsid;
1549 uint32_t f_namelen;
1550 uint32_t f_frsize;
1551 uint32_t f_flags;
1552 uint32_t f_spare[4];
1553}
1554#if defined(X86_64) || defined(IA64)
1555 __attribute__ ((packed, aligned(4)))
1556#endif
1557;
1558
1559static void
1560printcompat_statfs64(struct tcb *tcp, long addr)
1561{
1562 struct compat_statfs64 statbuf;
1563
1564 if (syserror(tcp) || !verbose(tcp)) {
1565 tprintf("%#lx", addr);
1566 return;
1567 }
1568 if (umove(tcp, addr, &statbuf) < 0) {
1569 tprints("{...}");
1570 return;
1571 }
1572 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1573 sprintfstype(statbuf.f_type),
1574 (unsigned long)statbuf.f_bsize,
1575 (unsigned long long)statbuf.f_blocks,
1576 (unsigned long long)statbuf.f_bfree);
1577 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1578 (unsigned long long)statbuf.f_bavail,
1579 (unsigned long long)statbuf.f_files,
1580 (unsigned long long)statbuf.f_ffree,
1581 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1582 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1583 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001584 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
Andreas Schwab7d558012012-01-17 18:14:22 +01001585}
1586
Roland McGrathab147c52003-07-17 09:03:02 +00001587int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001588sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001589{
1590 if (entering(tcp)) {
1591 printpath(tcp, tcp->u_arg[0]);
1592 tprintf(", %lu, ", tcp->u_arg[1]);
1593 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001594 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001595 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001596 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1597 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001598 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001599 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001600 }
1601 return 0;
1602}
1603
1604int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001605sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001606{
1607 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001608 printfd(tcp, tcp->u_arg[0]);
1609 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001610 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001611 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001612 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001613 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1614 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001615 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001616 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001617 }
1618 return 0;
1619}
1620#endif
1621
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001622#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001623int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001624osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001625{
1626 if (entering(tcp)) {
1627 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001628 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001629 } else {
1630 printstatfs(tcp, tcp->u_arg[1]);
1631 tprintf(", %lu", tcp->u_arg[2]);
1632 }
1633 return 0;
1634}
1635
1636int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001637osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001638{
1639 if (entering(tcp)) {
1640 tprintf("%lu, ", tcp->u_arg[0]);
1641 } else {
1642 printstatfs(tcp, tcp->u_arg[1]);
1643 tprintf(", %lu", tcp->u_arg[2]);
1644 }
1645 return 0;
1646}
Denys Vlasenko84703742012-02-25 02:38:52 +01001647#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001648
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001649/* directory */
1650int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001651sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001652{
1653 if (entering(tcp)) {
1654 printpath(tcp, tcp->u_arg[0]);
1655 }
1656 return 0;
1657}
1658
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001659static int
1660decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001661{
1662 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001663 printpath(tcp, tcp->u_arg[offset]);
1664 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001665 }
1666 return 0;
1667}
1668
1669int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001670sys_mkdir(struct tcb *tcp)
1671{
1672 return decode_mkdir(tcp, 0);
1673}
1674
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001675int
1676sys_mkdirat(struct tcb *tcp)
1677{
1678 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001679 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001680 return decode_mkdir(tcp, 1);
1681}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001682
1683int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001684sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001685{
1686 if (entering(tcp)) {
1687 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001688 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001689 printpath(tcp, tcp->u_arg[1]);
1690 }
1691 return 0;
1692}
1693
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001694int
1695sys_linkat(struct tcb *tcp)
1696{
1697 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001698 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001699 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001700 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001701 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001702 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001703 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001704 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001705 }
1706 return 0;
1707}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001708
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001709int
1710sys_unlinkat(struct tcb *tcp)
1711{
1712 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001713 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001714 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001715 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001716 printflags(at_flags, tcp->u_arg[2], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001717 }
1718 return 0;
1719}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001720
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001721int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001722sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001723{
1724 if (entering(tcp)) {
1725 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001726 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001727 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001728 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001729 }
1730 return 0;
1731}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001732
1733static int
1734decode_readlink(struct tcb *tcp, int offset)
1735{
1736 if (entering(tcp)) {
1737 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001738 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001739 } else {
1740 if (syserror(tcp))
1741 tprintf("%#lx", tcp->u_arg[offset + 1]);
1742 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001743 /* Used to use printpathn(), but readlink
1744 * neither includes NUL in the returned count,
1745 * nor actually writes it into memory.
1746 * printpathn() would decide on printing
1747 * "..." continuation based on garbage
1748 * past return buffer's end.
1749 */
1750 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001751 tprintf(", %lu", tcp->u_arg[offset + 2]);
1752 }
1753 return 0;
1754}
1755
1756int
1757sys_readlink(struct tcb *tcp)
1758{
1759 return decode_readlink(tcp, 0);
1760}
1761
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001762int
1763sys_readlinkat(struct tcb *tcp)
1764{
1765 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001766 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001767 return decode_readlink(tcp, 1);
1768}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001769
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001770int
1771sys_renameat(struct tcb *tcp)
1772{
1773 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001774 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001775 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001776 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001777 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001778 printpath(tcp, tcp->u_arg[3]);
1779 }
1780 return 0;
1781}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001782
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001783int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001784sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001785{
1786 if (entering(tcp)) {
1787 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001788 printuid(", ", tcp->u_arg[1]);
1789 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001790 }
1791 return 0;
1792}
1793
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001794int
1795sys_fchownat(struct tcb *tcp)
1796{
1797 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001798 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001799 printpath(tcp, tcp->u_arg[1]);
1800 printuid(", ", tcp->u_arg[2]);
1801 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001802 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001803 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001804 }
1805 return 0;
1806}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001807
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001808int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001809sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001810{
1811 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001812 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001813 printuid(", ", tcp->u_arg[1]);
1814 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001815 }
1816 return 0;
1817}
1818
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001819static int
1820decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001821{
1822 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001823 printpath(tcp, tcp->u_arg[offset]);
1824 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001825 }
1826 return 0;
1827}
1828
1829int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001830sys_chmod(struct tcb *tcp)
1831{
1832 return decode_chmod(tcp, 0);
1833}
1834
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001835int
1836sys_fchmodat(struct tcb *tcp)
1837{
1838 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001839 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001840 return decode_chmod(tcp, 1);
1841}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001842
1843int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001844sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001845{
1846 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001847 printfd(tcp, tcp->u_arg[0]);
1848 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001849 }
1850 return 0;
1851}
1852
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001853#ifdef ALPHA
1854int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001855sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001856{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001857 if (entering(tcp)) {
1858 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001859 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00001860 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
1861 }
1862 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001863}
1864#endif
1865
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001866static int
Roland McGrath6afc5652007-07-24 01:57:11 +00001867decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001868{
1869 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001870 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001871 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00001872 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001873 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00001874 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001875 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00001876 printtv_bitness(tcp, tcp->u_arg[offset + 1],
1877 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001878 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00001879 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001880 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00001881 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001882 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00001883 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001884 }
1885 return 0;
1886}
1887
1888int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001889sys_utimes(struct tcb *tcp)
1890{
Roland McGrath6afc5652007-07-24 01:57:11 +00001891 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001892}
1893
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001894int
1895sys_futimesat(struct tcb *tcp)
1896{
1897 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001898 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00001899 return decode_utimes(tcp, 1, 0);
1900}
1901
1902int
1903sys_utimensat(struct tcb *tcp)
1904{
1905 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001906 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00001907 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001908 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001909 printflags(at_flags, tcp->u_arg[3], "AT_???");
Roland McGrath6afc5652007-07-24 01:57:11 +00001910 }
1911 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001912}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001913
1914int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001915sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001916{
Roland McGrath7e9817c2007-07-05 20:31:58 +00001917 union {
1918 long utl[2];
1919 int uti[2];
Denys Vlasenko751acb32013-02-08 15:34:46 +01001920 long paranoia_for_huge_wordsize[4];
Roland McGrath7e9817c2007-07-05 20:31:58 +00001921 } u;
Denys Vlasenko751acb32013-02-08 15:34:46 +01001922 unsigned wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001923
1924 if (entering(tcp)) {
1925 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001926 tprints(", ");
Denys Vlasenko751acb32013-02-08 15:34:46 +01001927
1928 wordsize = current_wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001929 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001930 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001931 else if (!verbose(tcp))
1932 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001933 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001934 tprints("[?, ?]");
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001935 else if (wordsize == sizeof u.utl[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00001936 tprintf("[%s,", sprinttime(u.utl[0]));
1937 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001938 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001939 else if (wordsize == sizeof u.uti[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00001940 tprintf("[%s,", sprinttime(u.uti[0]));
1941 tprintf(" %s]", sprinttime(u.uti[1]));
1942 }
1943 else
Denys Vlasenko751acb32013-02-08 15:34:46 +01001944 tprintf("<decode error: unsupported wordsize %d>",
1945 wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001946 }
1947 return 0;
1948}
1949
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001950static int
1951decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001952{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001953 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001954
1955 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001956 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001957 tprintf(", %s", sprintmode(mode));
1958 switch (mode & S_IFMT) {
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001959 case S_IFCHR:
1960 case S_IFBLK:
Denys Vlasenko9472a272013-02-12 11:43:46 +01001961#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001962 if (current_personality == 1)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001963 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001964 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
1965 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001966 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00001967#endif
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001968 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001969 (unsigned long) major(tcp->u_arg[offset + 2]),
1970 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001971 break;
1972 default:
1973 break;
1974 }
1975 }
1976 return 0;
1977}
1978
1979int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001980sys_mknod(struct tcb *tcp)
1981{
1982 return decode_mknod(tcp, 0);
1983}
1984
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001985int
1986sys_mknodat(struct tcb *tcp)
1987{
1988 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001989 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001990 return decode_mknod(tcp, 1);
1991}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001992
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001993static void
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00001994print_old_dirent(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001995{
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00001996#ifdef SH64
1997 typedef struct kernel_dirent old_dirent_t;
1998#else
1999 typedef struct {
2000 uint32_t d_ino;
2001 uint32_t d_off;
2002 unsigned short d_reclen;
2003 char d_name[1];
2004 } old_dirent_t;
2005#endif
2006 old_dirent_t d;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002007
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002008 if (!verbose(tcp) || umove(tcp, addr, &d) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002009 tprintf("%#lx", addr);
2010 return;
2011 }
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002012
2013 tprintf("{d_ino=%lu, d_off=%lu, d_reclen=%u, d_name=\"",
2014 (unsigned long) d.d_ino, (unsigned long) d.d_off, d.d_reclen);
2015 if (d.d_reclen > 256)
2016 d.d_reclen = 256;
2017 printpathn(tcp, addr + offsetof(old_dirent_t, d_name), d.d_reclen);
2018 tprints("\"}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002019}
2020
2021int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002022sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002023{
2024 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002025 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002026 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002027 } else {
2028 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2029 tprintf("%#lx", tcp->u_arg[1]);
2030 else
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002031 print_old_dirent(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002032 /* Not much point in printing this out, it is always 1. */
2033 if (tcp->u_arg[2] != 1)
2034 tprintf(", %lu", tcp->u_arg[2]);
2035 }
2036 return 0;
2037}
2038
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00002039#include "xlat/direnttypes.h"
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002040
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002041int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002042sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002043{
2044 int i, len, dents = 0;
2045 char *buf;
2046
2047 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002048 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002049 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002050 return 0;
2051 }
2052 if (syserror(tcp) || !verbose(tcp)) {
2053 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2054 return 0;
2055 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002056 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002057 /* Beware of insanely large or negative values in tcp->u_rval */
2058 if (tcp->u_rval > 1024*1024)
2059 len = 1024*1024;
2060 if (tcp->u_rval < 0)
2061 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002062 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002063 if (len && !buf)
2064 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002065 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002066 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002067 free(buf);
2068 return 0;
2069 }
2070 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002071 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002072 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002073 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002074 if (!abbrev(tcp)) {
2075 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2076 i ? " " : "", d->d_ino, d->d_off);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002077 tprintf("d_reclen=%u, d_name=\"%s\", d_type=",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002078 d->d_reclen, d->d_name);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002079 printxval(direnttypes, buf[i + d->d_reclen - 1], "DT_???");
2080 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002081 }
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002082 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002083 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002084 break;
2085 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002086 i += d->d_reclen;
2087 dents++;
2088 }
2089 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002090 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002091 else
2092 tprintf("/* %u entries */", dents);
2093 tprintf(", %lu", tcp->u_arg[2]);
2094 free(buf);
2095 return 0;
2096}
2097
John Hughesbdf48f52001-03-06 15:08:09 +00002098int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002099sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002100{
2101 int i, len, dents = 0;
2102 char *buf;
2103
2104 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002105 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002106 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002107 return 0;
2108 }
2109 if (syserror(tcp) || !verbose(tcp)) {
2110 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2111 return 0;
2112 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002113
John Hughesbdf48f52001-03-06 15:08:09 +00002114 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002115 /* Beware of insanely large or negative tcp->u_rval */
2116 if (tcp->u_rval > 1024*1024)
2117 len = 1024*1024;
2118 if (tcp->u_rval < 0)
2119 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002120 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002121 if (len && !buf)
2122 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002123
John Hughesbdf48f52001-03-06 15:08:09 +00002124 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002125 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002126 free(buf);
2127 return 0;
2128 }
2129 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002130 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002131 for (i = 0; i < len;) {
2132 struct dirent64 *d = (struct dirent64 *) &buf[i];
John Hughesbdf48f52001-03-06 15:08:09 +00002133 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002134 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002135 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002136 d->d_ino,
2137 d->d_off);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002138 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002139 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002140 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002141 tprintf("d_reclen=%u, d_name=\"%s\"}",
2142 d->d_reclen, d->d_name);
2143 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002144 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002145 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002146 break;
2147 }
John Hughesbdf48f52001-03-06 15:08:09 +00002148 i += d->d_reclen;
2149 dents++;
2150 }
2151 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002152 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002153 else
2154 tprintf("/* %u entries */", dents);
2155 tprintf(", %lu", tcp->u_arg[2]);
2156 free(buf);
2157 return 0;
2158}
Roland McGrath186c5ac2002-12-15 23:58:23 +00002159
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002160int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002161sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002162{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002163 if (exiting(tcp)) {
2164 if (syserror(tcp))
2165 tprintf("%#lx", tcp->u_arg[0]);
2166 else
2167 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2168 tprintf(", %lu", tcp->u_arg[1]);
2169 }
2170 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002171}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002172
2173#ifdef HAVE_SYS_ASYNCH_H
2174
2175int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002176sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002177{
2178 struct aio_result_t res;
2179
2180 if (entering(tcp)) {
2181 tprintf("%lu, ", tcp->u_arg[0]);
2182 } else {
2183 if (syserror(tcp))
2184 tprintf("%#lx", tcp->u_arg[1]);
2185 else
2186 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2187 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2188 printxval(whence, tcp->u_arg[4], "L_???");
2189 if (syserror(tcp) || tcp->u_arg[5] == 0
2190 || umove(tcp, tcp->u_arg[5], &res) < 0)
2191 tprintf(", %#lx", tcp->u_arg[5]);
2192 else
2193 tprintf(", {aio_return %d aio_errno %d}",
2194 res.aio_return, res.aio_errno);
2195 }
2196 return 0;
2197}
2198
2199int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002200sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002201{
2202 struct aio_result_t res;
2203
2204 if (entering(tcp)) {
2205 tprintf("%lu, ", tcp->u_arg[0]);
2206 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2207 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2208 printxval(whence, tcp->u_arg[4], "L_???");
2209 }
2210 else {
2211 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002212 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002213 else if (syserror(tcp)
2214 || umove(tcp, tcp->u_arg[5], &res) < 0)
2215 tprintf(", %#lx", tcp->u_arg[5]);
2216 else
2217 tprintf(", {aio_return %d aio_errno %d}",
2218 res.aio_return, res.aio_errno);
2219 }
2220 return 0;
2221}
2222
2223int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002224sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002225{
2226 if (entering(tcp))
2227 printtv(tcp, tcp->u_arg[0]);
2228 return 0;
2229}
2230
2231int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002232sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002233{
2234 struct aio_result_t res;
2235
2236 if (exiting(tcp)) {
2237 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002238 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002239 else if (syserror(tcp)
2240 || umove(tcp, tcp->u_arg[0], &res) < 0)
2241 tprintf("%#lx", tcp->u_arg[0]);
2242 else
2243 tprintf("{aio_return %d aio_errno %d}",
2244 res.aio_return, res.aio_errno);
2245 }
2246 return 0;
2247}
2248
2249#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002250
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00002251#include "xlat/xattrflags.h"
Roland McGrath186c5ac2002-12-15 23:58:23 +00002252
Roland McGrath3292e222004-08-31 06:30:48 +00002253static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002254print_xattr_val(struct tcb *tcp, int failed,
2255 unsigned long arg,
2256 unsigned long insize,
2257 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002258{
Dmitry V. Levin1f215132012-12-07 21:38:52 +00002259 if (insize == 0)
2260 failed = 1;
Denys Vlasenko1d632462009-04-14 12:51:00 +00002261 if (!failed) {
2262 unsigned long capacity = 4 * size + 1;
2263 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2264 if (buf == NULL || /* probably a bogus size argument */
2265 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2266 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002267 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002268 else {
2269 unsigned char *out = buf;
2270 unsigned char *in = &buf[3 * size];
2271 size_t i;
2272 for (i = 0; i < size; ++i) {
Denys Vlasenko5198ed42013-03-06 23:44:23 +01002273 if (in[i] >= ' ' && in[i] <= 0x7e)
Denys Vlasenko1d632462009-04-14 12:51:00 +00002274 *out++ = in[i];
2275 else {
2276#define tohex(n) "0123456789abcdef"[n]
2277 *out++ = '\\';
2278 *out++ = 'x';
2279 *out++ = tohex(in[i] / 16);
2280 *out++ = tohex(in[i] % 16);
2281 }
2282 }
2283 /* Don't print terminating NUL if there is one. */
2284 if (i > 0 && in[i - 1] == '\0')
2285 out -= 4;
2286 *out = '\0';
2287 tprintf(", \"%s\", %ld", buf, insize);
2288 }
2289 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002290 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002291 if (failed)
2292 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002293}
2294
Roland McGrath186c5ac2002-12-15 23:58:23 +00002295int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002296sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002297{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002298 if (entering(tcp)) {
2299 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002300 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002301 printstr(tcp, tcp->u_arg[1], -1);
2302 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002303 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002304 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2305 }
2306 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002307}
2308
2309int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002310sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002311{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002312 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002313 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002314 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002315 printstr(tcp, tcp->u_arg[1], -1);
2316 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002317 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002318 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2319 }
2320 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002321}
2322
2323int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002324sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002325{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002326 if (entering(tcp)) {
2327 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002328 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002329 printstr(tcp, tcp->u_arg[1], -1);
2330 } else {
2331 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2332 tcp->u_rval);
2333 }
2334 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002335}
2336
2337int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002338sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002339{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002340 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002341 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002342 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002343 printstr(tcp, tcp->u_arg[1], -1);
2344 } else {
2345 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2346 tcp->u_rval);
2347 }
2348 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002349}
2350
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002351static void
2352print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2353{
2354 if (syserror(tcp)) {
2355 tprintf("%#lx", addr);
2356 } else {
2357 if (!addr) {
2358 tprints("NULL");
2359 } else {
2360 unsigned long len =
2361 (size < tcp->u_rval) ? size : tcp->u_rval;
2362 printstr(tcp, addr, len);
2363 }
2364 }
2365 tprintf(", %lu", size);
2366}
2367
Roland McGrath186c5ac2002-12-15 23:58:23 +00002368int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002369sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002370{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002371 if (entering(tcp)) {
2372 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002373 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002374 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002375 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002376 }
2377 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002378}
2379
2380int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002381sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002382{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002383 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002384 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002385 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002386 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002387 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002388 }
2389 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002390}
2391
2392int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002393sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002394{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002395 if (entering(tcp)) {
2396 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002397 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002398 printstr(tcp, tcp->u_arg[1], -1);
2399 }
2400 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002401}
2402
2403int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002404sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002405{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002406 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002407 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002408 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002409 printstr(tcp, tcp->u_arg[1], -1);
2410 }
2411 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002412}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002413
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00002414#include "xlat/advise.h"
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002415
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002416int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002417sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002418{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002419 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002420 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002421 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin7845a422014-04-17 13:32:47 +00002422 argn = printllval_aligned(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002423 tprintf(", %ld, ", tcp->u_arg[argn++]);
2424 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002425 }
2426 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002427}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002428
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002429int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002430sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002431{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002432 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002433 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002434 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin7845a422014-04-17 13:32:47 +00002435 argn = printllval_aligned(tcp, ", %lld, ", 1);
2436 argn = printllval_aligned(tcp, "%lld, ", argn);
Dmitry V. Levin8e096c42013-05-06 18:23:01 +00002437#if defined __ARM_EABI__ || defined AARCH64 || defined POWERPC || defined XTENSA
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002438 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002439#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002440 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002441#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002442 }
2443 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002444}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002445
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00002446#include "xlat/sync_file_range_flags.h"
William Manley16b9dcf2013-08-09 18:04:11 +01002447
2448int
2449sys_sync_file_range(struct tcb *tcp)
2450{
2451 if (entering(tcp)) {
2452 int argn;
2453 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin7845a422014-04-17 13:32:47 +00002454 argn = printllval_aligned(tcp, ", %lld, ", 1);
2455 argn = printllval_aligned(tcp, "%lld, ", argn);
William Manley16b9dcf2013-08-09 18:04:11 +01002456 printflags(sync_file_range_flags, tcp->u_arg[argn],
2457 "SYNC_FILE_RANGE_???");
2458 }
2459 return 0;
2460}
2461
2462int
2463sys_sync_file_range2(struct tcb *tcp)
2464{
2465 if (entering(tcp)) {
2466 int argn;
2467 printfd(tcp, tcp->u_arg[0]);
2468 printflags(sync_file_range_flags, 1,
2469 "SYNC_FILE_RANGE_???");
Dmitry V. Levin7845a422014-04-17 13:32:47 +00002470 argn = printllval_aligned(tcp, ", %lld, ", 2);
2471 argn = printllval_aligned(tcp, "%lld, ", argn);
William Manley16b9dcf2013-08-09 18:04:11 +01002472 }
2473 return 0;
2474}
2475
Mark Wielaardbab89402010-03-21 14:41:26 +01002476int
Roland McGrath96a96612008-05-20 04:56:18 +00002477sys_fallocate(struct tcb *tcp)
2478{
2479 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002480 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002481 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002482 tprintf(", %#lo, ", tcp->u_arg[1]); /* mode */
Dmitry V. Levin7845a422014-04-17 13:32:47 +00002483 argn = printllval_aligned(tcp, "%llu, ", 2); /* offset */
2484 printllval_aligned(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002485 }
2486 return 0;
2487}
Dmitry V. Levin88293652012-03-09 21:02:19 +00002488
Dmitry V. Levinad0c01e2012-03-15 00:52:22 +00002489#ifndef SWAP_FLAG_PREFER
2490# define SWAP_FLAG_PREFER 0x8000
2491#endif
2492#ifndef SWAP_FLAG_DISCARD
2493# define SWAP_FLAG_DISCARD 0x10000
2494#endif
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00002495#include "xlat/swap_flags.h"
Dmitry V. Levin88293652012-03-09 21:02:19 +00002496
2497int
2498sys_swapon(struct tcb *tcp)
2499{
2500 if (entering(tcp)) {
2501 int flags = tcp->u_arg[1];
2502 printpath(tcp, tcp->u_arg[0]);
2503 tprints(", ");
2504 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2505 "SWAP_FLAG_???");
2506 if (flags & SWAP_FLAG_PREFER)
2507 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);
2508 }
2509 return 0;
2510}