blob: f817182826a422abbaff121dce857a1d42a9393b [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
Zubin Mithra64aa1b12014-06-04 08:30:41 +0530315int sys_delete_module(struct tcb *tcp)
316{
317 decode_open(tcp, 0);
318 return RVAL_DECIMAL;
319}
320
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000321int
322sys_openat(struct tcb *tcp)
323{
324 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300325 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000326 return decode_open(tcp, 1);
327}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000328
Denys Vlasenko9472a272013-02-12 11:43:46 +0100329#if defined(SPARC) || defined(SPARC64)
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000330#include "xlat/openmodessol.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000331
332int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000333solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000334{
335 if (entering(tcp)) {
336 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200337 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000338 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000339 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000340 if (tcp->u_arg[1] & 0x100) {
341 /* mode */
342 tprintf(", %#lo", tcp->u_arg[2]);
343 }
344 }
345 return 0;
346}
347
348#endif
349
350int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000351sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000352{
353 if (entering(tcp)) {
354 printpath(tcp, tcp->u_arg[0]);
355 tprintf(", %#lo", tcp->u_arg[1]);
356 }
Zubin Mithra64aa1b12014-06-04 08:30:41 +0530357 return RVAL_FD;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000358}
359
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000360#include "xlat/access_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000361
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000362static int
363decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000364{
365 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000366 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200367 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000368 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000369 }
370 return 0;
371}
372
373int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000374sys_access(struct tcb *tcp)
375{
376 return decode_access(tcp, 0);
377}
378
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000379int
380sys_faccessat(struct tcb *tcp)
381{
382 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300383 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000384 return decode_access(tcp, 1);
385}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000386
387int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000388sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000389{
390 if (entering(tcp)) {
391 tprintf("%#lo", tcp->u_arg[0]);
392 }
393 return RVAL_OCTAL;
394}
395
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000396#include "xlat/whence_codes.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000397
Denys Vlasenko386b8712013-02-17 01:38:14 +0100398/* Linux kernel has exactly one version of lseek:
399 * fs/read_write.c::SYSCALL_DEFINE3(lseek, unsigned, fd, off_t, offset, unsigned, origin)
400 * In kernel, off_t is always the same as (kernel's) long
401 * (see include/uapi/asm-generic/posix_types.h),
402 * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument.
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100403 * Use test/x32_lseek.c to test lseek decoding.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100404 */
H.J. Luc933f272012-04-16 17:41:13 +0200405#if defined(LINUX_MIPSN32) || defined(X32)
Roland McGrath542c2c62008-05-20 01:11:56 +0000406int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000407sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000408{
409 long long offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100410 int whence;
Roland McGrath542c2c62008-05-20 01:11:56 +0000411
412 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300413 printfd(tcp, tcp->u_arg[0]);
Roland McGrath542c2c62008-05-20 01:11:56 +0000414 offset = tcp->ext_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100415 whence = tcp->u_arg[2];
416 if (whence == SEEK_SET)
417 tprintf(", %llu, ", offset);
Roland McGrath542c2c62008-05-20 01:11:56 +0000418 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100419 tprintf(", %lld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100420 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath542c2c62008-05-20 01:11:56 +0000421 }
H.J. Ludd0130b2012-04-16 12:16:45 +0200422 return RVAL_LUDECIMAL;
Roland McGrath542c2c62008-05-20 01:11:56 +0000423}
H.J. Ludd0130b2012-04-16 12:16:45 +0200424#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000425int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000426sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000427{
Denys Vlasenko06121762013-02-17 20:08:50 +0100428 long offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100429 int whence;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000430
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000431 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300432 printfd(tcp, tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000433 offset = tcp->u_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100434 whence = tcp->u_arg[2];
435 if (whence == SEEK_SET)
436 tprintf(", %lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000437 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100438 tprintf(", %ld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100439 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000440 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000441 return RVAL_UDECIMAL;
442}
John Hughes5a826b82001-03-07 13:21:24 +0000443#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000444
Denys Vlasenko386b8712013-02-17 01:38:14 +0100445/* llseek syscall takes explicitly two ulong arguments hi, lo,
446 * rather than one 64-bit argument for which LONG_LONG works
447 * appropriate for the native byte order.
448 *
449 * See kernel's fs/read_write.c::SYSCALL_DEFINE5(llseek, ...)
450 *
451 * hi,lo are "unsigned longs" and combined exactly this way in kernel:
452 * ((loff_t) hi << 32) | lo
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100453 * Note that for architectures with kernel's long wider than userspace long
Denys Vlasenko386b8712013-02-17 01:38:14 +0100454 * (such as x32), combining code will use *kernel's*, i.e. *wide* longs
Denys Vlasenko06121762013-02-17 20:08:50 +0100455 * for hi and lo. We would need to use tcp->ext_arg[N] on x32...
456 * ...however, x32 (and x86_64) does not _have_ llseek syscall as such.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100457 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000458int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000459sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000460{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000461 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300462 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000463 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300464 tprintf(", %llu, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100465 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300466 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000467 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300468 tprintf(", %lld, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100469 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300470 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000471 }
472 else {
Denys Vlasenko386b8712013-02-17 01:38:14 +0100473 long long off;
Denys Vlasenko1d632462009-04-14 12:51:00 +0000474 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
475 tprintf("%#lx, ", tcp->u_arg[3]);
476 else
477 tprintf("[%llu], ", off);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100478 printxval(whence_codes, tcp->u_arg[4], "SEEK_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000479 }
480 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000481}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000482
483int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000484sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000485{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000486 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100487 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300488 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin7845a422014-04-17 13:32:47 +0000489 argn = printllval_aligned(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100490 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000491 }
492 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000493}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000494
495int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000496sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000497{
498 if (entering(tcp)) {
499 printpath(tcp, tcp->u_arg[0]);
500 tprintf(", %lu", tcp->u_arg[1]);
501 }
502 return 0;
503}
504
John Hughes96f51472001-03-06 16:50:41 +0000505int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000506sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000507{
508 if (entering(tcp)) {
509 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin7845a422014-04-17 13:32:47 +0000510 printllval_aligned(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000511 }
512 return 0;
513}
John Hughes96f51472001-03-06 16:50:41 +0000514
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000515int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000516sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517{
518 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300519 printfd(tcp, tcp->u_arg[0]);
520 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000521 }
522 return 0;
523}
524
John Hughes96f51472001-03-06 16:50:41 +0000525int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000526sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000527{
528 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300529 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin7845a422014-04-17 13:32:47 +0000530 printllval_aligned(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000531 }
532 return 0;
533}
John Hughes96f51472001-03-06 16:50:41 +0000534
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000535/* several stats */
536
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000537#include "xlat/modetypes.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000538
Roland McGrathf9c49b22004-10-06 22:11:54 +0000539static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000540sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541{
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100542 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
543 + sizeof(int)*3
544 + /*paranoia:*/ 8];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000545 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000546
547 if ((mode & S_IFMT) == 0)
548 s = "";
549 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
550 sprintf(buf, "%#o", mode);
551 return buf;
552 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100553 s = buf + sprintf(buf, "%s%s%s%s", s,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000554 (mode & S_ISUID) ? "|S_ISUID" : "",
555 (mode & S_ISGID) ? "|S_ISGID" : "",
556 (mode & S_ISVTX) ? "|S_ISVTX" : "");
557 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
558 if (mode)
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100559 sprintf((char*)s, "|%#o", mode);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000560 s = (*buf == '|') ? buf + 1 : buf;
561 return *s ? s : "0";
562}
563
564static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000565sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000566{
567 struct tm *tmp;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100568 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000569
570 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000571 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000572 return buf;
573 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200574 tmp = localtime(&t);
575 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000576 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
577 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
578 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
579 else
580 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
581
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000582 return buf;
583}
584
Denys Vlasenko9472a272013-02-12 11:43:46 +0100585#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000586typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000587 int tv_sec;
588 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000589} timestruct_t;
590
591struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000592 unsigned st_dev;
593 int st_pad1[3]; /* network id */
594 unsigned st_ino;
595 unsigned st_mode;
596 unsigned st_nlink;
597 unsigned st_uid;
598 unsigned st_gid;
599 unsigned st_rdev;
600 int st_pad2[2];
601 int st_size;
602 int st_pad3; /* st_size, off_t expansion */
603 timestruct_t st_atime;
604 timestruct_t st_mtime;
605 timestruct_t st_ctime;
606 int st_blksize;
607 int st_blocks;
608 char st_fstype[16];
609 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000610};
611
612static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000613printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000614{
615 struct solstat statbuf;
616
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000617 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200618 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000619 return;
620 }
621 if (!abbrev(tcp)) {
622 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
623 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
624 (unsigned long) (statbuf.st_dev & 0x3ffff),
625 (unsigned long) statbuf.st_ino,
626 sprintmode(statbuf.st_mode));
627 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
628 (unsigned long) statbuf.st_nlink,
629 (unsigned long) statbuf.st_uid,
630 (unsigned long) statbuf.st_gid);
631 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
632 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
633 }
634 else
635 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
636 switch (statbuf.st_mode & S_IFMT) {
637 case S_IFCHR: case S_IFBLK:
638 tprintf("st_rdev=makedev(%lu, %lu), ",
639 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
640 (unsigned long) (statbuf.st_rdev & 0x3ffff));
641 break;
642 default:
643 tprintf("st_size=%u, ", statbuf.st_size);
644 break;
645 }
646 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000647 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
648 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
649 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000650 }
651 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200652 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000653}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000654
Denys Vlasenko9472a272013-02-12 11:43:46 +0100655# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000656static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000657printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000658{
659 struct stat_sparc64 statbuf;
660
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000661 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200662 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000663 return;
664 }
665
666 if (!abbrev(tcp)) {
667 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
668 (unsigned long) major(statbuf.st_dev),
669 (unsigned long) minor(statbuf.st_dev),
670 (unsigned long) statbuf.st_ino,
671 sprintmode(statbuf.st_mode));
672 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
673 (unsigned long) statbuf.st_nlink,
674 (unsigned long) statbuf.st_uid,
675 (unsigned long) statbuf.st_gid);
676 tprintf("st_blksize=%lu, ",
677 (unsigned long) statbuf.st_blksize);
678 tprintf("st_blocks=%lu, ",
679 (unsigned long) statbuf.st_blocks);
680 }
681 else
682 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
683 switch (statbuf.st_mode & S_IFMT) {
684 case S_IFCHR: case S_IFBLK:
685 tprintf("st_rdev=makedev(%lu, %lu), ",
686 (unsigned long) major(statbuf.st_rdev),
687 (unsigned long) minor(statbuf.st_rdev));
688 break;
689 default:
690 tprintf("st_size=%lu, ", statbuf.st_size);
691 break;
692 }
693 if (!abbrev(tcp)) {
694 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
695 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100696 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000697 }
698 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200699 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000700}
Denys Vlasenko9472a272013-02-12 11:43:46 +0100701# endif /* SPARC64 */
702#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000703
Denys Vlasenko84703742012-02-25 02:38:52 +0100704#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200705struct stat_powerpc32 {
706 unsigned int st_dev;
707 unsigned int st_ino;
708 unsigned int st_mode;
709 unsigned short st_nlink;
710 unsigned int st_uid;
711 unsigned int st_gid;
712 unsigned int st_rdev;
713 unsigned int st_size;
714 unsigned int st_blksize;
715 unsigned int st_blocks;
716 unsigned int st_atime;
717 unsigned int st_atime_nsec;
718 unsigned int st_mtime;
719 unsigned int st_mtime_nsec;
720 unsigned int st_ctime;
721 unsigned int st_ctime_nsec;
722 unsigned int __unused4;
723 unsigned int __unused5;
724};
725
726static void
727printstat_powerpc32(struct tcb *tcp, long addr)
728{
729 struct stat_powerpc32 statbuf;
730
731 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200732 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200733 return;
734 }
735
736 if (!abbrev(tcp)) {
737 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
738 major(statbuf.st_dev), minor(statbuf.st_dev),
739 statbuf.st_ino,
740 sprintmode(statbuf.st_mode));
741 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
742 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
743 tprintf("st_blksize=%u, ", statbuf.st_blksize);
744 tprintf("st_blocks=%u, ", statbuf.st_blocks);
745 }
746 else
747 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
748 switch (statbuf.st_mode & S_IFMT) {
749 case S_IFCHR: case S_IFBLK:
750 tprintf("st_rdev=makedev(%lu, %lu), ",
751 (unsigned long) major(statbuf.st_rdev),
752 (unsigned long) minor(statbuf.st_rdev));
753 break;
754 default:
755 tprintf("st_size=%u, ", statbuf.st_size);
756 break;
757 }
758 if (!abbrev(tcp)) {
759 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
760 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100761 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200762 }
763 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200764 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200765}
Denys Vlasenko84703742012-02-25 02:38:52 +0100766#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200767
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000768#include "xlat/fileflags.h"
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000769
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000770static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000771realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000772{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000773 if (!abbrev(tcp)) {
774 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
775 (unsigned long) major(statbuf->st_dev),
776 (unsigned long) minor(statbuf->st_dev),
777 (unsigned long) statbuf->st_ino,
778 sprintmode(statbuf->st_mode));
779 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
780 (unsigned long) statbuf->st_nlink,
781 (unsigned long) statbuf->st_uid,
782 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000783#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000784 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
785#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000786#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000787 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
788#endif
789 }
790 else
791 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
792 switch (statbuf->st_mode & S_IFMT) {
793 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000794#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000795 tprintf("st_rdev=makedev(%lu, %lu), ",
796 (unsigned long) major(statbuf->st_rdev),
797 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000798#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000799 tprintf("st_size=makedev(%lu, %lu), ",
800 (unsigned long) major(statbuf->st_size),
801 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000802#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000803 break;
804 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000805 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000806 break;
807 }
808 if (!abbrev(tcp)) {
809 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
810 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
811 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000812#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200813 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000814 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000815#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000816#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000817 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
818#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000819#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000820 tprintf(", st_level=%ld", statbuf->st_level);
821#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000822#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000823 tprintf(", st_fstype=%.*s",
824 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
825#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000826#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000827 tprintf(", st_gen=%u", statbuf->st_gen);
828#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200829 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000830 }
831 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200832 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000833}
834
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000835#ifndef X32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000836static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000837printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000838{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000839 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000840
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000841 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200842 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000843 return;
844 }
845 if (syserror(tcp) || !verbose(tcp)) {
846 tprintf("%#lx", addr);
847 return;
848 }
849
Denys Vlasenko9472a272013-02-12 11:43:46 +0100850#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000851 if (current_personality == 1) {
852 printstatsol(tcp, addr);
853 return;
854 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000855#ifdef SPARC64
856 else if (current_personality == 2) {
857 printstat_sparc64(tcp, addr);
858 return;
859 }
860#endif
Denys Vlasenko9472a272013-02-12 11:43:46 +0100861#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000862
Denys Vlasenko84703742012-02-25 02:38:52 +0100863#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200864 if (current_personality == 1) {
865 printstat_powerpc32(tcp, addr);
866 return;
867 }
868#endif
869
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000870 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200871 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000872 return;
873 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000874
875 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000876}
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000877#else /* X32 */
878# define printstat printstat64
879#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000880
Elliott Hughes391c0d82014-04-03 17:50:14 -0700881#if !defined HAVE_STAT64 && (defined AARCH64 || defined X86_64)
Roland McGrathe6d0f712007-08-07 01:22:49 +0000882/*
883 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
884 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
885 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
886 * __GNUC__ is needed for the required __attribute__ below.
Elliott Hughes391c0d82014-04-03 17:50:14 -0700887 *
888 * Similarly, aarch64 has a unified `struct stat' but its arm personality
889 * needs `struct stat64' (which also expects a 32-bit `long' but which
890 * shouldn't be packed).
Roland McGrathe6d0f712007-08-07 01:22:49 +0000891 */
892struct stat64 {
893 unsigned long long st_dev;
894 unsigned char __pad0[4];
895 unsigned int __st_ino;
896 unsigned int st_mode;
897 unsigned int st_nlink;
898 unsigned int st_uid;
899 unsigned int st_gid;
900 unsigned long long st_rdev;
901 unsigned char __pad3[4];
902 long long st_size;
903 unsigned int st_blksize;
904 unsigned long long st_blocks;
905 unsigned int st_atime;
906 unsigned int st_atime_nsec;
907 unsigned int st_mtime;
908 unsigned int st_mtime_nsec;
909 unsigned int st_ctime;
910 unsigned int st_ctime_nsec;
911 unsigned long long st_ino;
Elliott Hughes391c0d82014-04-03 17:50:14 -0700912}
913# if defined X86_64
914 __attribute__((packed))
915# define STAT64_SIZE 96
916#else
917# define STAT64_SIZE 104
918# endif
919;
Roland McGrathe6d0f712007-08-07 01:22:49 +0000920# define HAVE_STAT64 1
Roland McGrathe6d0f712007-08-07 01:22:49 +0000921#endif
922
Wichert Akkermanc7926982000-04-10 22:22:31 +0000923#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000924static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000925printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000926{
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000927#ifdef X32
928 struct stat statbuf;
929#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000930 struct stat64 statbuf;
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000931#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000932
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000933#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +0000934 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
935#endif
936
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000937 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200938 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000939 return;
940 }
941 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000942 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000943 return;
944 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000945
Denys Vlasenko9472a272013-02-12 11:43:46 +0100946#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000947 if (current_personality == 1) {
948 printstatsol(tcp, addr);
949 return;
950 }
951# ifdef SPARC64
952 else if (current_personality == 2) {
953 printstat_sparc64(tcp, addr);
954 return;
955 }
956# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +0100957#endif /* SPARC[64] */
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000958
Elliott Hughes391c0d82014-04-03 17:50:14 -0700959#if defined AARCH64
960 if (current_personality != 0) {
961 printstat(tcp, addr);
962 return;
963 }
964#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100965#if defined X86_64
H.J. Lu35be5812012-04-16 13:00:01 +0200966 if (current_personality != 1) {
Andreas Schwab61b74352009-10-16 11:37:13 +0200967 printstat(tcp, addr);
968 return;
969 }
970#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +0000971
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000972 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200973 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000974 return;
975 }
976
977 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +0000978 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000979 (unsigned long) major(statbuf.st_dev),
980 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +0000981 (unsigned long long) statbuf.st_ino,
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000982 sprintmode(statbuf.st_mode));
983 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
984 (unsigned long) statbuf.st_nlink,
985 (unsigned long) statbuf.st_uid,
986 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000987#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000988 tprintf("st_blksize=%lu, ",
989 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000990#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
991#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000992 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000993#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000994 }
995 else
996 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
997 switch (statbuf.st_mode & S_IFMT) {
998 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000999#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001000 tprintf("st_rdev=makedev(%lu, %lu), ",
1001 (unsigned long) major(statbuf.st_rdev),
1002 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001003#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001004 tprintf("st_size=makedev(%lu, %lu), ",
1005 (unsigned long) major(statbuf.st_size),
1006 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001007#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001008 break;
1009 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001010 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001011 break;
1012 }
1013 if (!abbrev(tcp)) {
1014 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1015 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001016 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001017#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001018 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001019 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001020#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001021#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001022 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1023#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001024#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001025 tprintf(", st_level=%ld", statbuf.st_level);
1026#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001027#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001028 tprintf(", st_fstype=%.*s",
1029 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1030#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001031#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001032 tprintf(", st_gen=%u", statbuf.st_gen);
1033#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001034 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001035 }
1036 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001037 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001038}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001039#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001040
Denys Vlasenko8435d672013-02-18 15:47:57 +01001041#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001042static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001043convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001044{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001045 newbuf->st_dev = oldbuf->st_dev;
1046 newbuf->st_ino = oldbuf->st_ino;
1047 newbuf->st_mode = oldbuf->st_mode;
1048 newbuf->st_nlink = oldbuf->st_nlink;
1049 newbuf->st_uid = oldbuf->st_uid;
1050 newbuf->st_gid = oldbuf->st_gid;
1051 newbuf->st_rdev = oldbuf->st_rdev;
1052 newbuf->st_size = oldbuf->st_size;
1053 newbuf->st_atime = oldbuf->st_atime;
1054 newbuf->st_mtime = oldbuf->st_mtime;
1055 newbuf->st_ctime = oldbuf->st_ctime;
1056 newbuf->st_blksize = 0; /* not supported in old_stat */
1057 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001058}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001059
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001060static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001061printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001062{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001063 struct __old_kernel_stat statbuf;
1064 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001065
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001066 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001067 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001068 return;
1069 }
1070 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001071 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001072 return;
1073 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001074
Denys Vlasenko9472a272013-02-12 11:43:46 +01001075# if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001076 if (current_personality == 1) {
1077 printstatsol(tcp, addr);
1078 return;
1079 }
Denys Vlasenko84703742012-02-25 02:38:52 +01001080# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001081
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001082 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001083 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001084 return;
1085 }
1086
1087 convertoldstat(&statbuf, &newstatbuf);
1088 realprintstat(tcp, &newstatbuf);
1089}
Denys Vlasenko84703742012-02-25 02:38:52 +01001090#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001091
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001092int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001093sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001094{
1095 if (entering(tcp)) {
1096 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001097 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001098 } else {
1099 printstat(tcp, tcp->u_arg[1]);
1100 }
1101 return 0;
1102}
1103
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001104#ifdef X32
1105static void
1106printstat64_x32(struct tcb *tcp, long addr)
1107{
1108 struct stat64 statbuf;
1109
1110 if (!addr) {
1111 tprints("NULL");
1112 return;
1113 }
1114 if (syserror(tcp) || !verbose(tcp)) {
1115 tprintf("%#lx", addr);
1116 return;
1117 }
1118
1119 if (umove(tcp, addr, &statbuf) < 0) {
1120 tprints("{...}");
1121 return;
1122 }
1123
1124 if (!abbrev(tcp)) {
1125 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1126 (unsigned long) major(statbuf.st_dev),
1127 (unsigned long) minor(statbuf.st_dev),
1128 (unsigned long long) statbuf.st_ino,
1129 sprintmode(statbuf.st_mode));
1130 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1131 (unsigned long) statbuf.st_nlink,
1132 (unsigned long) statbuf.st_uid,
1133 (unsigned long) statbuf.st_gid);
1134 tprintf("st_blksize=%lu, ",
1135 (unsigned long) statbuf.st_blksize);
1136 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1137 }
1138 else
1139 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1140 switch (statbuf.st_mode & S_IFMT) {
1141 case S_IFCHR: case S_IFBLK:
1142 tprintf("st_rdev=makedev(%lu, %lu), ",
1143 (unsigned long) major(statbuf.st_rdev),
1144 (unsigned long) minor(statbuf.st_rdev));
1145 break;
1146 default:
1147 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1148 break;
1149 }
1150 if (!abbrev(tcp)) {
1151 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1152 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1153 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1154 tprints("}");
1155 }
1156 else
1157 tprints("...}");
1158}
1159#endif /* X32 */
1160
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001161int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001162sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001163{
1164#ifdef HAVE_STAT64
1165 if (entering(tcp)) {
1166 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001167 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001168 } else {
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001169# ifdef X32
1170 printstat64_x32(tcp, tcp->u_arg[1]);
1171# else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001172 printstat64(tcp, tcp->u_arg[1]);
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001173# endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001174 }
1175 return 0;
1176#else
1177 return printargs(tcp);
1178#endif
1179}
1180
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001181#ifndef AT_SYMLINK_NOFOLLOW
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001182# define AT_SYMLINK_NOFOLLOW 0x100
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001183#endif
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001184#ifndef AT_REMOVEDIR
1185# define AT_REMOVEDIR 0x200
1186#endif
1187#ifndef AT_SYMLINK_FOLLOW
1188# define AT_SYMLINK_FOLLOW 0x400
1189#endif
1190#ifndef AT_NO_AUTOMOUNT
1191# define AT_NO_AUTOMOUNT 0x800
1192#endif
1193#ifndef AT_EMPTY_PATH
1194# define AT_EMPTY_PATH 0x1000
1195#endif
1196
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001197#include "xlat/at_flags.h"
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001198
1199int
1200sys_newfstatat(struct tcb *tcp)
1201{
1202 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001203 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001204 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001205 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001206 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001207#ifdef POWERPC64
1208 if (current_personality == 0)
1209 printstat(tcp, tcp->u_arg[2]);
1210 else
1211 printstat64(tcp, tcp->u_arg[2]);
1212#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001213 printstat64(tcp, tcp->u_arg[2]);
1214#else
1215 printstat(tcp, tcp->u_arg[2]);
1216#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001217 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001218 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001219 }
1220 return 0;
1221}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001222
Denys Vlasenko8435d672013-02-18 15:47:57 +01001223#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001224int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001225sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001226{
1227 if (entering(tcp)) {
1228 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001229 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001230 } else {
1231 printoldstat(tcp, tcp->u_arg[1]);
1232 }
1233 return 0;
1234}
Denys Vlasenko84703742012-02-25 02:38:52 +01001235#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001236
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001237int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001238sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001239{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001240 if (entering(tcp)) {
1241 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001242 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001243 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001244 printstat(tcp, tcp->u_arg[1]);
1245 }
1246 return 0;
1247}
1248
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001249int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001250sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001251{
1252#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001253 if (entering(tcp)) {
1254 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001255 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001256 } else {
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001257# ifdef X32
1258 printstat64_x32(tcp, tcp->u_arg[1]);
1259# else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001260 printstat64(tcp, tcp->u_arg[1]);
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001261# endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001262 }
1263 return 0;
1264#else
1265 return printargs(tcp);
1266#endif
1267}
1268
Denys Vlasenko8435d672013-02-18 15:47:57 +01001269#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001270int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001271sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001272{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001273 if (entering(tcp)) {
1274 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001275 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001276 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001277 printoldstat(tcp, tcp->u_arg[1]);
1278 }
1279 return 0;
1280}
Denys Vlasenko84703742012-02-25 02:38:52 +01001281#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001282
Denys Vlasenko9472a272013-02-12 11:43:46 +01001283#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001284
1285int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001286sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001287{
1288 if (entering(tcp)) {
1289 tprintf("%ld, ", tcp->u_arg[0]);
1290 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001291 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001293# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001294 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001295 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001296 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001297# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001298 printstat(tcp, tcp->u_arg[2]);
1299 }
1300 return 0;
1301}
1302
1303int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001304sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001305{
1306 if (entering(tcp))
1307 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1308 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001309# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001310 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001311 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001312 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001313# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001314 printstat(tcp, tcp->u_arg[2]);
1315 }
1316 return 0;
1317}
1318
1319int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001320sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001321{
1322 if (entering(tcp)) {
1323 tprintf("%ld, ", tcp->u_arg[0]);
1324 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001325 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001326 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001327# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001328 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001329 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001330 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001331# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001332 printstat(tcp, tcp->u_arg[2]);
1333 }
1334 return 0;
1335}
1336
1337int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001338sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001339{
1340 int mode = tcp->u_arg[2];
1341
1342 if (entering(tcp)) {
1343 tprintf("%ld, ", tcp->u_arg[0]);
1344 printpath(tcp, tcp->u_arg[1]);
1345 tprintf(", %s", sprintmode(mode));
1346 switch (mode & S_IFMT) {
1347 case S_IFCHR: case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001348 tprintf(", makedev(%lu, %lu)",
1349 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1350 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001351 break;
1352 default:
1353 break;
1354 }
1355 }
1356 return 0;
1357}
1358
Denys Vlasenko84703742012-02-25 02:38:52 +01001359# ifdef HAVE_SYS_ACL_H
Wichert Akkerman8829a551999-06-11 13:18:40 +00001360
Denys Vlasenko84703742012-02-25 02:38:52 +01001361# include <sys/acl.h>
Wichert Akkerman8829a551999-06-11 13:18:40 +00001362
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001363#include "xlat/aclcmds.h"
Wichert Akkerman8829a551999-06-11 13:18:40 +00001364
1365int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001366sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001367{
1368 if (entering(tcp)) {
1369 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001370 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001371 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1372 tprintf(", %ld", tcp->u_arg[2]);
1373 /*
1374 * FIXME - dump out the list of aclent_t's pointed to
1375 * by "tcp->u_arg[3]" if it's not NULL.
1376 */
1377 if (tcp->u_arg[3])
1378 tprintf(", %#lx", tcp->u_arg[3]);
1379 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001380 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001381 }
1382 return 0;
1383}
1384
Wichert Akkerman8829a551999-06-11 13:18:40 +00001385int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001386sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001387{
1388 if (entering(tcp)) {
1389 tprintf("%ld, ", tcp->u_arg[0]);
1390 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1391 tprintf(", %ld", tcp->u_arg[2]);
1392 /*
1393 * FIXME - dump out the list of aclent_t's pointed to
1394 * by "tcp->u_arg[3]" if it's not NULL.
1395 */
1396 if (tcp->u_arg[3])
1397 tprintf(", %#lx", tcp->u_arg[3]);
1398 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001399 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001400 }
1401 return 0;
1402}
1403
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001404#include "xlat/aclipc.h"
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001405
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001406int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001407sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001408{
1409 if (entering(tcp)) {
1410 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1411 tprintf(", %#lx, ", tcp->u_arg[1]);
1412 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1413 tprintf(", %ld", tcp->u_arg[3]);
1414 /*
1415 * FIXME - dump out the list of aclent_t's pointed to
1416 * by "tcp->u_arg[4]" if it's not NULL.
1417 */
1418 if (tcp->u_arg[4])
1419 tprintf(", %#lx", tcp->u_arg[4]);
1420 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001421 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001422 }
1423 return 0;
1424}
1425
Denys Vlasenko84703742012-02-25 02:38:52 +01001426# endif /* HAVE_SYS_ACL_H */
Wichert Akkerman8829a551999-06-11 13:18:40 +00001427
Denys Vlasenko9472a272013-02-12 11:43:46 +01001428#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001429
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001430#include "xlat/fsmagic.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001431
Roland McGrathf9c49b22004-10-06 22:11:54 +00001432static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001433sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001434{
1435 static char buf[32];
Roland McGrathf9c49b22004-10-06 22:11:54 +00001436 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001437
1438 s = xlookup(fsmagic, magic);
1439 if (s) {
1440 sprintf(buf, "\"%s\"", s);
1441 return buf;
1442 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001443 sprintf(buf, "%#x", magic);
1444 return buf;
1445}
1446
1447static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001448printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001449{
1450 struct statfs statbuf;
1451
1452 if (syserror(tcp) || !verbose(tcp)) {
1453 tprintf("%#lx", addr);
1454 return;
1455 }
1456 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001457 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001458 return;
1459 }
1460#ifdef ALPHA
1461
1462 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1463 sprintfstype(statbuf.f_type),
1464 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001465 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001466 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001467 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1468 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001469#else /* !ALPHA */
1470 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1471 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001472 (unsigned long)statbuf.f_bsize,
1473 (unsigned long)statbuf.f_blocks,
1474 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001475 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1476 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001477 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001478 (unsigned long)statbuf.f_ffree,
1479 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001480 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001481#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001482#ifdef _STATFS_F_FRSIZE
1483 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1484#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001485 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001486}
1487
1488int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001489sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001490{
1491 if (entering(tcp)) {
1492 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001493 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001494 } else {
1495 printstatfs(tcp, tcp->u_arg[1]);
1496 }
1497 return 0;
1498}
1499
1500int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001501sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001502{
1503 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001504 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001505 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001506 } else {
1507 printstatfs(tcp, tcp->u_arg[1]);
1508 }
1509 return 0;
1510}
1511
Denys Vlasenko84703742012-02-25 02:38:52 +01001512#if defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001513static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001514printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001515{
1516 struct statfs64 statbuf;
1517
1518 if (syserror(tcp) || !verbose(tcp)) {
1519 tprintf("%#lx", addr);
1520 return;
1521 }
1522 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001523 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001524 return;
1525 }
Roland McGrath08738432005-06-03 02:40:39 +00001526 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001527 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001528 (unsigned long long)statbuf.f_bsize,
1529 (unsigned long long)statbuf.f_blocks,
1530 (unsigned long long)statbuf.f_bfree);
1531 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1532 (unsigned long long)statbuf.f_bavail,
1533 (unsigned long long)statbuf.f_files,
1534 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001535 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1536 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001537#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001538 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001539#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001540#ifdef _STATFS_F_FLAGS
1541 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1542#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001543 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001544}
1545
Andreas Schwab7d558012012-01-17 18:14:22 +01001546struct compat_statfs64 {
1547 uint32_t f_type;
1548 uint32_t f_bsize;
1549 uint64_t f_blocks;
1550 uint64_t f_bfree;
1551 uint64_t f_bavail;
1552 uint64_t f_files;
1553 uint64_t f_ffree;
1554 fsid_t f_fsid;
1555 uint32_t f_namelen;
1556 uint32_t f_frsize;
1557 uint32_t f_flags;
1558 uint32_t f_spare[4];
1559}
1560#if defined(X86_64) || defined(IA64)
1561 __attribute__ ((packed, aligned(4)))
1562#endif
1563;
1564
1565static void
1566printcompat_statfs64(struct tcb *tcp, long addr)
1567{
1568 struct compat_statfs64 statbuf;
1569
1570 if (syserror(tcp) || !verbose(tcp)) {
1571 tprintf("%#lx", addr);
1572 return;
1573 }
1574 if (umove(tcp, addr, &statbuf) < 0) {
1575 tprints("{...}");
1576 return;
1577 }
1578 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1579 sprintfstype(statbuf.f_type),
1580 (unsigned long)statbuf.f_bsize,
1581 (unsigned long long)statbuf.f_blocks,
1582 (unsigned long long)statbuf.f_bfree);
1583 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1584 (unsigned long long)statbuf.f_bavail,
1585 (unsigned long long)statbuf.f_files,
1586 (unsigned long long)statbuf.f_ffree,
1587 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1588 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1589 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001590 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
Andreas Schwab7d558012012-01-17 18:14:22 +01001591}
1592
Roland McGrathab147c52003-07-17 09:03:02 +00001593int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001594sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001595{
1596 if (entering(tcp)) {
1597 printpath(tcp, tcp->u_arg[0]);
1598 tprintf(", %lu, ", tcp->u_arg[1]);
1599 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001600 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001601 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001602 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1603 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001604 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001605 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001606 }
1607 return 0;
1608}
1609
1610int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001611sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001612{
1613 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001614 printfd(tcp, tcp->u_arg[0]);
1615 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001616 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001617 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001618 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001619 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1620 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001621 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001622 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001623 }
1624 return 0;
1625}
1626#endif
1627
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001628#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001629int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001630osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001631{
1632 if (entering(tcp)) {
1633 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001634 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001635 } else {
1636 printstatfs(tcp, tcp->u_arg[1]);
1637 tprintf(", %lu", tcp->u_arg[2]);
1638 }
1639 return 0;
1640}
1641
1642int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001643osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001644{
1645 if (entering(tcp)) {
1646 tprintf("%lu, ", tcp->u_arg[0]);
1647 } else {
1648 printstatfs(tcp, tcp->u_arg[1]);
1649 tprintf(", %lu", tcp->u_arg[2]);
1650 }
1651 return 0;
1652}
Denys Vlasenko84703742012-02-25 02:38:52 +01001653#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001654
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001655/* directory */
1656int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001657sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001658{
1659 if (entering(tcp)) {
1660 printpath(tcp, tcp->u_arg[0]);
1661 }
1662 return 0;
1663}
1664
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001665static int
1666decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001667{
1668 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001669 printpath(tcp, tcp->u_arg[offset]);
1670 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001671 }
1672 return 0;
1673}
1674
1675int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001676sys_mkdir(struct tcb *tcp)
1677{
1678 return decode_mkdir(tcp, 0);
1679}
1680
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001681int
1682sys_mkdirat(struct tcb *tcp)
1683{
1684 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001685 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001686 return decode_mkdir(tcp, 1);
1687}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001688
1689int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001690sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001691{
1692 if (entering(tcp)) {
1693 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001694 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001695 printpath(tcp, tcp->u_arg[1]);
1696 }
1697 return 0;
1698}
1699
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001700int
1701sys_linkat(struct tcb *tcp)
1702{
1703 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001704 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001705 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001706 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001707 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001708 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001709 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001710 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001711 }
1712 return 0;
1713}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001714
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001715int
1716sys_unlinkat(struct tcb *tcp)
1717{
1718 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001719 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001720 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001721 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001722 printflags(at_flags, tcp->u_arg[2], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001723 }
1724 return 0;
1725}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001726
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001727int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001728sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001729{
1730 if (entering(tcp)) {
1731 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001732 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001733 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001734 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001735 }
1736 return 0;
1737}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001738
1739static int
1740decode_readlink(struct tcb *tcp, int offset)
1741{
1742 if (entering(tcp)) {
1743 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001744 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001745 } else {
1746 if (syserror(tcp))
1747 tprintf("%#lx", tcp->u_arg[offset + 1]);
1748 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001749 /* Used to use printpathn(), but readlink
1750 * neither includes NUL in the returned count,
1751 * nor actually writes it into memory.
1752 * printpathn() would decide on printing
1753 * "..." continuation based on garbage
1754 * past return buffer's end.
1755 */
1756 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001757 tprintf(", %lu", tcp->u_arg[offset + 2]);
1758 }
1759 return 0;
1760}
1761
1762int
1763sys_readlink(struct tcb *tcp)
1764{
1765 return decode_readlink(tcp, 0);
1766}
1767
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001768int
1769sys_readlinkat(struct tcb *tcp)
1770{
1771 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001772 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001773 return decode_readlink(tcp, 1);
1774}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001775
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001776int
1777sys_renameat(struct tcb *tcp)
1778{
1779 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001780 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001781 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001782 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001783 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001784 printpath(tcp, tcp->u_arg[3]);
1785 }
1786 return 0;
1787}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001788
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001789int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001790sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001791{
1792 if (entering(tcp)) {
1793 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001794 printuid(", ", tcp->u_arg[1]);
1795 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001796 }
1797 return 0;
1798}
1799
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001800int
1801sys_fchownat(struct tcb *tcp)
1802{
1803 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001804 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001805 printpath(tcp, tcp->u_arg[1]);
1806 printuid(", ", tcp->u_arg[2]);
1807 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001808 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001809 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001810 }
1811 return 0;
1812}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001813
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001814int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001815sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001816{
1817 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001818 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001819 printuid(", ", tcp->u_arg[1]);
1820 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001821 }
1822 return 0;
1823}
1824
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001825static int
1826decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001827{
1828 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001829 printpath(tcp, tcp->u_arg[offset]);
1830 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001831 }
1832 return 0;
1833}
1834
1835int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001836sys_chmod(struct tcb *tcp)
1837{
1838 return decode_chmod(tcp, 0);
1839}
1840
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001841int
1842sys_fchmodat(struct tcb *tcp)
1843{
1844 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001845 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001846 return decode_chmod(tcp, 1);
1847}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001848
1849int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001850sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001851{
1852 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001853 printfd(tcp, tcp->u_arg[0]);
1854 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001855 }
1856 return 0;
1857}
1858
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001859#ifdef ALPHA
1860int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001861sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001862{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001863 if (entering(tcp)) {
1864 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001865 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00001866 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
1867 }
1868 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001869}
1870#endif
1871
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001872static int
Roland McGrath6afc5652007-07-24 01:57:11 +00001873decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001874{
1875 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001876 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001877 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00001878 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001879 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00001880 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001881 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00001882 printtv_bitness(tcp, tcp->u_arg[offset + 1],
1883 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001884 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00001885 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001886 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00001887 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001888 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00001889 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001890 }
1891 return 0;
1892}
1893
1894int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001895sys_utimes(struct tcb *tcp)
1896{
Roland McGrath6afc5652007-07-24 01:57:11 +00001897 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001898}
1899
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001900int
1901sys_futimesat(struct tcb *tcp)
1902{
1903 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001904 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00001905 return decode_utimes(tcp, 1, 0);
1906}
1907
1908int
1909sys_utimensat(struct tcb *tcp)
1910{
1911 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001912 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00001913 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001914 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001915 printflags(at_flags, tcp->u_arg[3], "AT_???");
Roland McGrath6afc5652007-07-24 01:57:11 +00001916 }
1917 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001918}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001919
1920int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001921sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001922{
Roland McGrath7e9817c2007-07-05 20:31:58 +00001923 union {
1924 long utl[2];
1925 int uti[2];
Denys Vlasenko751acb32013-02-08 15:34:46 +01001926 long paranoia_for_huge_wordsize[4];
Roland McGrath7e9817c2007-07-05 20:31:58 +00001927 } u;
Denys Vlasenko751acb32013-02-08 15:34:46 +01001928 unsigned wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001929
1930 if (entering(tcp)) {
1931 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001932 tprints(", ");
Denys Vlasenko751acb32013-02-08 15:34:46 +01001933
1934 wordsize = current_wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001935 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001936 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001937 else if (!verbose(tcp))
1938 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001939 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001940 tprints("[?, ?]");
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001941 else if (wordsize == sizeof u.utl[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00001942 tprintf("[%s,", sprinttime(u.utl[0]));
1943 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001944 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001945 else if (wordsize == sizeof u.uti[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00001946 tprintf("[%s,", sprinttime(u.uti[0]));
1947 tprintf(" %s]", sprinttime(u.uti[1]));
1948 }
1949 else
Denys Vlasenko751acb32013-02-08 15:34:46 +01001950 tprintf("<decode error: unsupported wordsize %d>",
1951 wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001952 }
1953 return 0;
1954}
1955
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001956static int
1957decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001958{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001959 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001960
1961 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001962 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001963 tprintf(", %s", sprintmode(mode));
1964 switch (mode & S_IFMT) {
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001965 case S_IFCHR:
1966 case S_IFBLK:
Denys Vlasenko9472a272013-02-12 11:43:46 +01001967#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001968 if (current_personality == 1)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001969 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001970 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
1971 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001972 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00001973#endif
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001974 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001975 (unsigned long) major(tcp->u_arg[offset + 2]),
1976 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001977 break;
1978 default:
1979 break;
1980 }
1981 }
1982 return 0;
1983}
1984
1985int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001986sys_mknod(struct tcb *tcp)
1987{
1988 return decode_mknod(tcp, 0);
1989}
1990
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001991int
1992sys_mknodat(struct tcb *tcp)
1993{
1994 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001995 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001996 return decode_mknod(tcp, 1);
1997}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001998
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001999static void
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002000print_old_dirent(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002001{
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002002#ifdef SH64
2003 typedef struct kernel_dirent old_dirent_t;
2004#else
2005 typedef struct {
2006 uint32_t d_ino;
2007 uint32_t d_off;
2008 unsigned short d_reclen;
2009 char d_name[1];
2010 } old_dirent_t;
2011#endif
2012 old_dirent_t d;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002013
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002014 if (!verbose(tcp) || umove(tcp, addr, &d) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002015 tprintf("%#lx", addr);
2016 return;
2017 }
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002018
2019 tprintf("{d_ino=%lu, d_off=%lu, d_reclen=%u, d_name=\"",
2020 (unsigned long) d.d_ino, (unsigned long) d.d_off, d.d_reclen);
2021 if (d.d_reclen > 256)
2022 d.d_reclen = 256;
2023 printpathn(tcp, addr + offsetof(old_dirent_t, d_name), d.d_reclen);
2024 tprints("\"}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002025}
2026
2027int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002028sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002029{
2030 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002031 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002032 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002033 } else {
2034 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2035 tprintf("%#lx", tcp->u_arg[1]);
2036 else
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002037 print_old_dirent(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002038 /* Not much point in printing this out, it is always 1. */
2039 if (tcp->u_arg[2] != 1)
2040 tprintf(", %lu", tcp->u_arg[2]);
2041 }
2042 return 0;
2043}
2044
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00002045#include "xlat/direnttypes.h"
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002046
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002047int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002048sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002049{
2050 int i, len, dents = 0;
2051 char *buf;
2052
2053 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002054 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002055 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002056 return 0;
2057 }
2058 if (syserror(tcp) || !verbose(tcp)) {
2059 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2060 return 0;
2061 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002062 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002063 /* Beware of insanely large or negative values in tcp->u_rval */
2064 if (tcp->u_rval > 1024*1024)
2065 len = 1024*1024;
2066 if (tcp->u_rval < 0)
2067 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002068 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002069 if (len && !buf)
2070 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002071 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002072 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002073 free(buf);
2074 return 0;
2075 }
2076 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002077 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002078 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002079 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002080 if (!abbrev(tcp)) {
2081 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2082 i ? " " : "", d->d_ino, d->d_off);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002083 tprintf("d_reclen=%u, d_name=\"%s\", d_type=",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002084 d->d_reclen, d->d_name);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002085 printxval(direnttypes, buf[i + d->d_reclen - 1], "DT_???");
2086 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002087 }
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002088 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002089 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002090 break;
2091 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002092 i += d->d_reclen;
2093 dents++;
2094 }
2095 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002096 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002097 else
2098 tprintf("/* %u entries */", dents);
2099 tprintf(", %lu", tcp->u_arg[2]);
2100 free(buf);
2101 return 0;
2102}
2103
John Hughesbdf48f52001-03-06 15:08:09 +00002104int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002105sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002106{
2107 int i, len, dents = 0;
2108 char *buf;
2109
2110 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002111 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002112 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002113 return 0;
2114 }
2115 if (syserror(tcp) || !verbose(tcp)) {
2116 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2117 return 0;
2118 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002119
John Hughesbdf48f52001-03-06 15:08:09 +00002120 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002121 /* Beware of insanely large or negative tcp->u_rval */
2122 if (tcp->u_rval > 1024*1024)
2123 len = 1024*1024;
2124 if (tcp->u_rval < 0)
2125 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002126 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002127 if (len && !buf)
2128 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002129
John Hughesbdf48f52001-03-06 15:08:09 +00002130 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002131 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002132 free(buf);
2133 return 0;
2134 }
2135 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002136 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002137 for (i = 0; i < len;) {
2138 struct dirent64 *d = (struct dirent64 *) &buf[i];
John Hughesbdf48f52001-03-06 15:08:09 +00002139 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002140 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002141 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002142 d->d_ino,
2143 d->d_off);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002144 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002145 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002146 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002147 tprintf("d_reclen=%u, d_name=\"%s\"}",
2148 d->d_reclen, d->d_name);
2149 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002150 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002151 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002152 break;
2153 }
John Hughesbdf48f52001-03-06 15:08:09 +00002154 i += d->d_reclen;
2155 dents++;
2156 }
2157 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002158 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002159 else
2160 tprintf("/* %u entries */", dents);
2161 tprintf(", %lu", tcp->u_arg[2]);
2162 free(buf);
2163 return 0;
2164}
Roland McGrath186c5ac2002-12-15 23:58:23 +00002165
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002166int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002167sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002168{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002169 if (exiting(tcp)) {
2170 if (syserror(tcp))
2171 tprintf("%#lx", tcp->u_arg[0]);
2172 else
2173 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2174 tprintf(", %lu", tcp->u_arg[1]);
2175 }
2176 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002177}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002178
2179#ifdef HAVE_SYS_ASYNCH_H
2180
2181int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002182sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002183{
2184 struct aio_result_t res;
2185
2186 if (entering(tcp)) {
2187 tprintf("%lu, ", tcp->u_arg[0]);
2188 } else {
2189 if (syserror(tcp))
2190 tprintf("%#lx", tcp->u_arg[1]);
2191 else
2192 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2193 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2194 printxval(whence, tcp->u_arg[4], "L_???");
2195 if (syserror(tcp) || tcp->u_arg[5] == 0
2196 || umove(tcp, tcp->u_arg[5], &res) < 0)
2197 tprintf(", %#lx", tcp->u_arg[5]);
2198 else
2199 tprintf(", {aio_return %d aio_errno %d}",
2200 res.aio_return, res.aio_errno);
2201 }
2202 return 0;
2203}
2204
2205int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002206sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002207{
2208 struct aio_result_t res;
2209
2210 if (entering(tcp)) {
2211 tprintf("%lu, ", tcp->u_arg[0]);
2212 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2213 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2214 printxval(whence, tcp->u_arg[4], "L_???");
2215 }
2216 else {
2217 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002218 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002219 else if (syserror(tcp)
2220 || umove(tcp, tcp->u_arg[5], &res) < 0)
2221 tprintf(", %#lx", tcp->u_arg[5]);
2222 else
2223 tprintf(", {aio_return %d aio_errno %d}",
2224 res.aio_return, res.aio_errno);
2225 }
2226 return 0;
2227}
2228
2229int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002230sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002231{
2232 if (entering(tcp))
2233 printtv(tcp, tcp->u_arg[0]);
2234 return 0;
2235}
2236
2237int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002238sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002239{
2240 struct aio_result_t res;
2241
2242 if (exiting(tcp)) {
2243 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002244 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002245 else if (syserror(tcp)
2246 || umove(tcp, tcp->u_arg[0], &res) < 0)
2247 tprintf("%#lx", tcp->u_arg[0]);
2248 else
2249 tprintf("{aio_return %d aio_errno %d}",
2250 res.aio_return, res.aio_errno);
2251 }
2252 return 0;
2253}
2254
2255#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002256
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00002257#include "xlat/xattrflags.h"
Roland McGrath186c5ac2002-12-15 23:58:23 +00002258
Roland McGrath3292e222004-08-31 06:30:48 +00002259static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002260print_xattr_val(struct tcb *tcp, int failed,
2261 unsigned long arg,
2262 unsigned long insize,
2263 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002264{
Dmitry V. Levin1f215132012-12-07 21:38:52 +00002265 if (insize == 0)
2266 failed = 1;
Denys Vlasenko1d632462009-04-14 12:51:00 +00002267 if (!failed) {
2268 unsigned long capacity = 4 * size + 1;
2269 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2270 if (buf == NULL || /* probably a bogus size argument */
2271 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2272 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002273 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002274 else {
2275 unsigned char *out = buf;
2276 unsigned char *in = &buf[3 * size];
2277 size_t i;
2278 for (i = 0; i < size; ++i) {
Denys Vlasenko5198ed42013-03-06 23:44:23 +01002279 if (in[i] >= ' ' && in[i] <= 0x7e)
Denys Vlasenko1d632462009-04-14 12:51:00 +00002280 *out++ = in[i];
2281 else {
2282#define tohex(n) "0123456789abcdef"[n]
2283 *out++ = '\\';
2284 *out++ = 'x';
2285 *out++ = tohex(in[i] / 16);
2286 *out++ = tohex(in[i] % 16);
2287 }
2288 }
2289 /* Don't print terminating NUL if there is one. */
2290 if (i > 0 && in[i - 1] == '\0')
2291 out -= 4;
2292 *out = '\0';
2293 tprintf(", \"%s\", %ld", buf, insize);
2294 }
2295 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002296 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002297 if (failed)
2298 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002299}
2300
Roland McGrath186c5ac2002-12-15 23:58:23 +00002301int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002302sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002303{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002304 if (entering(tcp)) {
2305 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002306 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002307 printstr(tcp, tcp->u_arg[1], -1);
2308 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002309 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002310 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2311 }
2312 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002313}
2314
2315int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002316sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002317{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002318 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002319 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002320 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002321 printstr(tcp, tcp->u_arg[1], -1);
2322 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002323 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002324 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2325 }
2326 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002327}
2328
2329int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002330sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002331{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002332 if (entering(tcp)) {
2333 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002334 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002335 printstr(tcp, tcp->u_arg[1], -1);
2336 } else {
2337 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2338 tcp->u_rval);
2339 }
2340 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002341}
2342
2343int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002344sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002345{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002346 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002347 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002348 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002349 printstr(tcp, tcp->u_arg[1], -1);
2350 } else {
2351 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2352 tcp->u_rval);
2353 }
2354 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002355}
2356
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002357static void
2358print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2359{
2360 if (syserror(tcp)) {
2361 tprintf("%#lx", addr);
2362 } else {
2363 if (!addr) {
2364 tprints("NULL");
2365 } else {
2366 unsigned long len =
2367 (size < tcp->u_rval) ? size : tcp->u_rval;
2368 printstr(tcp, addr, len);
2369 }
2370 }
2371 tprintf(", %lu", size);
2372}
2373
Roland McGrath186c5ac2002-12-15 23:58:23 +00002374int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002375sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002376{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002377 if (entering(tcp)) {
2378 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002379 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002380 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002381 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002382 }
2383 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002384}
2385
2386int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002387sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002388{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002389 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002390 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002391 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002392 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002393 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002394 }
2395 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002396}
2397
2398int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002399sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002400{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002401 if (entering(tcp)) {
2402 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002403 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002404 printstr(tcp, tcp->u_arg[1], -1);
2405 }
2406 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002407}
2408
2409int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002410sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002411{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002412 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002413 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002414 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002415 printstr(tcp, tcp->u_arg[1], -1);
2416 }
2417 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002418}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002419
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00002420#include "xlat/advise.h"
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002421
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002422int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002423sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002424{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002425 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002426 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002427 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin7845a422014-04-17 13:32:47 +00002428 argn = printllval_aligned(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002429 tprintf(", %ld, ", tcp->u_arg[argn++]);
2430 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002431 }
2432 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002433}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002434
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002435int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002436sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002437{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002438 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002439 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002440 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin7845a422014-04-17 13:32:47 +00002441 argn = printllval_aligned(tcp, ", %lld, ", 1);
2442 argn = printllval_aligned(tcp, "%lld, ", argn);
Dmitry V. Levin8e096c42013-05-06 18:23:01 +00002443#if defined __ARM_EABI__ || defined AARCH64 || defined POWERPC || defined XTENSA
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002444 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002445#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002446 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002447#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002448 }
2449 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002450}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002451
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00002452#include "xlat/sync_file_range_flags.h"
William Manley16b9dcf2013-08-09 18:04:11 +01002453
2454int
2455sys_sync_file_range(struct tcb *tcp)
2456{
2457 if (entering(tcp)) {
2458 int argn;
2459 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin7845a422014-04-17 13:32:47 +00002460 argn = printllval_aligned(tcp, ", %lld, ", 1);
2461 argn = printllval_aligned(tcp, "%lld, ", argn);
William Manley16b9dcf2013-08-09 18:04:11 +01002462 printflags(sync_file_range_flags, tcp->u_arg[argn],
2463 "SYNC_FILE_RANGE_???");
2464 }
2465 return 0;
2466}
2467
2468int
2469sys_sync_file_range2(struct tcb *tcp)
2470{
2471 if (entering(tcp)) {
2472 int argn;
2473 printfd(tcp, tcp->u_arg[0]);
2474 printflags(sync_file_range_flags, 1,
2475 "SYNC_FILE_RANGE_???");
Dmitry V. Levin7845a422014-04-17 13:32:47 +00002476 argn = printllval_aligned(tcp, ", %lld, ", 2);
2477 argn = printllval_aligned(tcp, "%lld, ", argn);
William Manley16b9dcf2013-08-09 18:04:11 +01002478 }
2479 return 0;
2480}
2481
Mark Wielaardbab89402010-03-21 14:41:26 +01002482int
Roland McGrath96a96612008-05-20 04:56:18 +00002483sys_fallocate(struct tcb *tcp)
2484{
2485 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002486 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002487 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002488 tprintf(", %#lo, ", tcp->u_arg[1]); /* mode */
Dmitry V. Levin7845a422014-04-17 13:32:47 +00002489 argn = printllval_aligned(tcp, "%llu, ", 2); /* offset */
2490 printllval_aligned(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002491 }
2492 return 0;
2493}
Dmitry V. Levin88293652012-03-09 21:02:19 +00002494
Dmitry V. Levinad0c01e2012-03-15 00:52:22 +00002495#ifndef SWAP_FLAG_PREFER
2496# define SWAP_FLAG_PREFER 0x8000
2497#endif
2498#ifndef SWAP_FLAG_DISCARD
2499# define SWAP_FLAG_DISCARD 0x10000
2500#endif
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00002501#include "xlat/swap_flags.h"
Dmitry V. Levin88293652012-03-09 21:02:19 +00002502
2503int
2504sys_swapon(struct tcb *tcp)
2505{
2506 if (entering(tcp)) {
2507 int flags = tcp->u_arg[1];
2508 printpath(tcp, tcp->u_arg[0]);
2509 tprints(", ");
2510 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2511 "SWAP_FLAG_???");
2512 if (flags & SWAP_FLAG_PREFER)
2513 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);
2514 }
2515 return 0;
2516}