blob: a1d30b3fcf276a681e7395231e843d437fac5fc7 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * $Id$
31 */
32
33#include "defs.h"
34
35#include <dirent.h>
Roland McGrathc531e572008-08-01 01:13:10 +000036
Roland McGrathc531e572008-08-01 01:13:10 +000037struct kernel_dirent {
38 unsigned long d_ino;
39 unsigned long d_off;
40 unsigned short d_reclen;
41 char d_name[1];
42};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000043
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000044# ifdef LINUXSPARC
45struct stat {
46 unsigned short st_dev;
47 unsigned int st_ino;
48 unsigned short st_mode;
49 short st_nlink;
50 unsigned short st_uid;
51 unsigned short st_gid;
52 unsigned short st_rdev;
53 unsigned int st_size;
54 int st_atime;
55 unsigned int __unused1;
56 int st_mtime;
57 unsigned int __unused2;
58 int st_ctime;
59 unsigned int __unused3;
60 int st_blksize;
61 int st_blocks;
62 unsigned int __unused4[2];
63};
Roland McGrath6d1a65c2004-07-12 07:44:08 +000064#if defined(SPARC64)
65struct stat_sparc64 {
66 unsigned int st_dev;
67 unsigned long st_ino;
68 unsigned int st_mode;
69 unsigned int st_nlink;
70 unsigned int st_uid;
71 unsigned int st_gid;
72 unsigned int st_rdev;
73 long st_size;
74 long st_atime;
75 long st_mtime;
76 long st_ctime;
77 long st_blksize;
78 long st_blocks;
79 unsigned long __unused4[2];
80};
81#endif /* SPARC64 */
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000082# define stat kernel_stat
83# include <asm/stat.h>
84# undef stat
85# else
Wichert Akkerman5b4d1281999-07-09 00:32:54 +000086# undef dev_t
87# undef ino_t
88# undef mode_t
89# undef nlink_t
90# undef uid_t
91# undef gid_t
92# undef off_t
93# undef loff_t
94
Wichert Akkermana6013701999-07-08 14:00:58 +000095# define dev_t __kernel_dev_t
96# define ino_t __kernel_ino_t
97# define mode_t __kernel_mode_t
98# define nlink_t __kernel_nlink_t
99# define uid_t __kernel_uid_t
100# define gid_t __kernel_gid_t
101# define off_t __kernel_off_t
102# define loff_t __kernel_loff_t
103
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000104# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +0000105
106# undef dev_t
107# undef ino_t
108# undef mode_t
109# undef nlink_t
110# undef uid_t
111# undef gid_t
112# undef off_t
113# undef loff_t
Wichert Akkerman5b4d1281999-07-09 00:32:54 +0000114
115# define dev_t dev_t
116# define ino_t ino_t
117# define mode_t mode_t
118# define nlink_t nlink_t
119# define uid_t uid_t
120# define gid_t gid_t
121# define off_t off_t
122# define loff_t loff_t
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000123# endif
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000124# ifdef HPPA /* asm-parisc/stat.h defines stat64 */
125# undef stat64
126# endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000127# define stat libc_stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000128# define stat64 libc_stat64
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000129# include <sys/stat.h>
130# undef stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000131# undef stat64
Roland McGrathca16a402003-01-09 06:53:22 +0000132 /* These might be macros. */
133# undef st_atime
134# undef st_mtime
135# undef st_ctime
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000136# ifdef HPPA
137# define stat64 hpux_stat64
138# endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000139
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000140#include <fcntl.h>
141
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000142
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000143#ifdef HAVE_SYS_VFS_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000144#include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000145#endif
146
Roland McGrath186c5ac2002-12-15 23:58:23 +0000147#ifdef HAVE_LINUX_XATTR_H
148#include <linux/xattr.h>
Denys Vlasenkoed720fd2012-02-25 02:24:03 +0100149#else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000150#define XATTR_CREATE 1
151#define XATTR_REPLACE 2
152#endif
153
John Hughes70623be2001-03-08 13:59:00 +0000154
Dmitry V. Levin1f336e52006-10-14 20:20:46 +0000155#if _LFS64_LARGEFILE && (defined(LINUX) || defined(SVR4))
156# ifdef HAVE_INTTYPES_H
157# include <inttypes.h>
158# else
159# define PRId64 "lld"
160# define PRIu64 "llu"
161# endif
162#endif
163
John Hughes70623be2001-03-08 13:59:00 +0000164#if HAVE_LONG_LONG_OFF_T
165/*
166 * Ugly hacks for systems that have typedef long long off_t
167 */
John Hughesb8c9f772001-03-07 16:53:07 +0000168
169#define stat64 stat
170#define HAVE_STAT64 1 /* Ugly hack */
John Hughes70623be2001-03-08 13:59:00 +0000171
172#define sys_stat64 sys_stat
173#define sys_fstat64 sys_fstat
174#define sys_lstat64 sys_lstat
175#define sys_lseek64 sys_lseek
176#define sys_truncate64 sys_truncate
177#define sys_ftruncate64 sys_ftruncate
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000178#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000179
180#ifdef MAJOR_IN_SYSMACROS
181#include <sys/sysmacros.h>
182#endif
183
184#ifdef MAJOR_IN_MKDEV
185#include <sys/mkdev.h>
186#endif
187
188#ifdef HAVE_SYS_ASYNCH_H
189#include <sys/asynch.h>
190#endif
191
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000192
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000193const struct xlat open_access_modes[] = {
194 { O_RDONLY, "O_RDONLY" },
195 { O_WRONLY, "O_WRONLY" },
196 { O_RDWR, "O_RDWR" },
197#ifdef O_ACCMODE
198 { O_ACCMODE, "O_ACCMODE" },
199#endif
200 { 0, NULL },
201};
202
203const struct xlat open_mode_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000204 { O_CREAT, "O_CREAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205 { O_EXCL, "O_EXCL" },
206 { O_NOCTTY, "O_NOCTTY" },
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000207 { O_TRUNC, "O_TRUNC" },
208 { O_APPEND, "O_APPEND" },
209 { O_NONBLOCK, "O_NONBLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000210#ifdef O_SYNC
211 { O_SYNC, "O_SYNC" },
212#endif
213#ifdef O_ASYNC
214 { O_ASYNC, "O_ASYNC" },
215#endif
216#ifdef O_DSYNC
217 { O_DSYNC, "O_DSYNC" },
218#endif
219#ifdef O_RSYNC
220 { O_RSYNC, "O_RSYNC" },
221#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000222#if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000223 { O_NDELAY, "O_NDELAY" },
224#endif
225#ifdef O_PRIV
226 { O_PRIV, "O_PRIV" },
227#endif
228#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000229 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000230#endif
231#ifdef O_LARGEFILE
Roland McGrathfee836e2005-02-02 22:11:32 +0000232# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
233# undef O_LARGEFILE
234# ifdef SPARC64
235# define O_LARGEFILE 0x40000
236# elif defined X86_64 || defined S390X
237# define O_LARGEFILE 0100000
238# endif
239# endif
Roland McGrath663a8a02005-02-04 09:49:56 +0000240# ifdef O_LARGEFILE
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200241 { O_LARGEFILE, "O_LARGEFILE" },
Roland McGrath663a8a02005-02-04 09:49:56 +0000242# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000243#endif
244#ifdef O_DIRECTORY
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200245 { O_DIRECTORY, "O_DIRECTORY" },
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000246#endif
247#ifdef O_NOFOLLOW
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200248 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000249#endif
Roland McGrath1025c3e2005-05-09 07:40:35 +0000250#ifdef O_NOATIME
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200251 { O_NOATIME, "O_NOATIME" },
Roland McGrath1025c3e2005-05-09 07:40:35 +0000252#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000253#ifdef O_CLOEXEC
254 { O_CLOEXEC, "O_CLOEXEC" },
255#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000256#ifdef FNDELAY
257 { FNDELAY, "FNDELAY" },
258#endif
259#ifdef FAPPEND
260 { FAPPEND, "FAPPEND" },
261#endif
262#ifdef FMARK
263 { FMARK, "FMARK" },
264#endif
265#ifdef FDEFER
266 { FDEFER, "FDEFER" },
267#endif
268#ifdef FASYNC
269 { FASYNC, "FASYNC" },
270#endif
271#ifdef FSHLOCK
272 { FSHLOCK, "FSHLOCK" },
273#endif
274#ifdef FEXLOCK
275 { FEXLOCK, "FEXLOCK" },
276#endif
277#ifdef FCREAT
278 { FCREAT, "FCREAT" },
279#endif
280#ifdef FTRUNC
281 { FTRUNC, "FTRUNC" },
282#endif
283#ifdef FEXCL
284 { FEXCL, "FEXCL" },
285#endif
286#ifdef FNBIO
287 { FNBIO, "FNBIO" },
288#endif
289#ifdef FSYNC
290 { FSYNC, "FSYNC" },
291#endif
292#ifdef FNOCTTY
293 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000294#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000295#ifdef O_SHLOCK
296 { O_SHLOCK, "O_SHLOCK" },
297#endif
298#ifdef O_EXLOCK
299 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000300#endif
301 { 0, NULL },
302};
303
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000304
305#ifndef AT_FDCWD
306# define AT_FDCWD -100
307#endif
308
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000309/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
310 * extension to get the right value. We do this by declaring fd as int here.
311 */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000312static void
Dmitry V. Levin31382132011-03-04 05:08:02 +0300313print_dirfd(struct tcb *tcp, int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000314{
315 if (fd == AT_FDCWD)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200316 tprints("AT_FDCWD, ");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200317 else {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300318 printfd(tcp, fd);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200319 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300320 }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000321}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000322
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000323/*
324 * low bits of the open(2) flags define access mode,
325 * other bits are real flags.
326 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000327const char *
328sprint_open_modes(mode_t flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000329{
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100330 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000331 char *p;
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100332 char sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000333 const char *str;
334 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000335
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100336 sep = ' ';
337 p = stpcpy(outstr, "flags");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000338 str = xlookup(open_access_modes, flags & 3);
339 if (str) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100340 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200341 p = stpcpy(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000342 flags &= ~3;
343 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000344 return outstr;
345 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000346 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000347
348 for (x = open_mode_flags; x->str; x++) {
349 if ((flags & x->val) == x->val) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100350 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200351 p = stpcpy(p, x->str);
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000352 flags &= ~x->val;
353 if (!flags)
354 return outstr;
355 sep = '|';
356 }
357 }
358 /* flags is still nonzero */
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100359 *p++ = sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000360 sprintf(p, "%#x", flags);
361 return outstr;
362}
363
364void
365tprint_open_modes(mode_t flags)
366{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200367 tprints(sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000368}
369
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000370static int
371decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000372{
373 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000374 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200375 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000376 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000377 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000378 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000379 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000380 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000381 }
382 }
383 return 0;
384}
385
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000386int
387sys_open(struct tcb *tcp)
388{
389 return decode_open(tcp, 0);
390}
391
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000392int
393sys_openat(struct tcb *tcp)
394{
395 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300396 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000397 return decode_open(tcp, 1);
398}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000399
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000400#ifdef LINUXSPARC
Roland McGratha4d48532005-06-08 20:45:28 +0000401static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000402 { 0, "O_RDWR" },
403 { 1, "O_RDONLY" },
404 { 2, "O_WRONLY" },
405 { 0x80, "O_NONBLOCK" },
406 { 8, "O_APPEND" },
407 { 0x100, "O_CREAT" },
408 { 0x200, "O_TRUNC" },
409 { 0x400, "O_EXCL" },
410 { 0x800, "O_NOCTTY" },
411 { 0x10, "O_SYNC" },
412 { 0x40, "O_DSYNC" },
413 { 0x8000, "O_RSYNC" },
414 { 4, "O_NDELAY" },
415 { 0x1000, "O_PRIV" },
416 { 0, NULL },
417};
418
419int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000420solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000421{
422 if (entering(tcp)) {
423 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200424 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000425 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000426 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000427 if (tcp->u_arg[1] & 0x100) {
428 /* mode */
429 tprintf(", %#lo", tcp->u_arg[2]);
430 }
431 }
432 return 0;
433}
434
435#endif
436
437int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000438sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000439{
440 if (entering(tcp)) {
441 printpath(tcp, tcp->u_arg[0]);
442 tprintf(", %#lo", tcp->u_arg[1]);
443 }
444 return 0;
445}
446
Roland McGrathd9f816f2004-09-04 03:39:20 +0000447static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000448 { F_OK, "F_OK", },
449 { R_OK, "R_OK" },
450 { W_OK, "W_OK" },
451 { X_OK, "X_OK" },
452#ifdef EFF_ONLY_OK
453 { EFF_ONLY_OK, "EFF_ONLY_OK" },
454#endif
455#ifdef EX_OK
456 { EX_OK, "EX_OK" },
457#endif
458 { 0, NULL },
459};
460
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000461static int
462decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000463{
464 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000465 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200466 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000467 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000468 }
469 return 0;
470}
471
472int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000473sys_access(struct tcb *tcp)
474{
475 return decode_access(tcp, 0);
476}
477
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000478int
479sys_faccessat(struct tcb *tcp)
480{
481 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300482 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000483 return decode_access(tcp, 1);
484}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000485
486int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000487sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000488{
489 if (entering(tcp)) {
490 tprintf("%#lo", tcp->u_arg[0]);
491 }
492 return RVAL_OCTAL;
493}
494
Roland McGrathd9f816f2004-09-04 03:39:20 +0000495static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000496 { SEEK_SET, "SEEK_SET" },
497 { SEEK_CUR, "SEEK_CUR" },
498 { SEEK_END, "SEEK_END" },
499 { 0, NULL },
500};
501
John Hughes70623be2001-03-08 13:59:00 +0000502#ifndef HAVE_LONG_LONG_OFF_T
Roland McGrath542c2c62008-05-20 01:11:56 +0000503#if defined (LINUX_MIPSN32)
504int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000505sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000506{
507 long long offset;
508 int _whence;
509
510 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300511 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200512 tprints(", ");
Roland McGrath542c2c62008-05-20 01:11:56 +0000513 offset = tcp->ext_arg[1];
514 _whence = tcp->u_arg[2];
515 if (_whence == SEEK_SET)
516 tprintf("%llu, ", offset);
517 else
518 tprintf("%lld, ", offset);
519 printxval(whence, _whence, "SEEK_???");
520 }
521 return RVAL_UDECIMAL;
522}
523#else /* !LINUX_MIPSN32 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000524int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000525sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000526{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000527 off_t offset;
528 int _whence;
529
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000530 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300531 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200532 tprints(", ");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000533 offset = tcp->u_arg[1];
534 _whence = tcp->u_arg[2];
535 if (_whence == SEEK_SET)
536 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000537 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000538 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000539 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000540 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541 return RVAL_UDECIMAL;
542}
Roland McGrath542c2c62008-05-20 01:11:56 +0000543#endif /* LINUX_MIPSN32 */
John Hughes5a826b82001-03-07 13:21:24 +0000544#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000545
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000546int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000547sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000548{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000549 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300550 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000551 /*
552 * This one call takes explicitly two 32-bit arguments hi, lo,
553 * rather than one 64-bit argument for which LONG_LONG works
554 * appropriate for the native byte order.
555 */
556 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300557 tprintf(", %llu, ",
558 ((long long int) tcp->u_arg[1]) << 32 |
559 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000560 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300561 tprintf(", %lld, ",
562 ((long long int) tcp->u_arg[1]) << 32 |
563 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000564 }
565 else {
566 long long int off;
567 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
568 tprintf("%#lx, ", tcp->u_arg[3]);
569 else
570 tprintf("[%llu], ", off);
571 printxval(whence, tcp->u_arg[4], "SEEK_???");
572 }
573 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000574}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000575
576int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000577sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000578{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000579 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100580 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300581 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200582 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100583 argn = printllval(tcp, "%lld", 1);
584 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000585 }
586 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000587}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000588
John Hughes70623be2001-03-08 13:59:00 +0000589#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000590int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000591sys_lseek64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +0000592{
593 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100594 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300595 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200596 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000597 if (tcp->u_arg[3] == SEEK_SET)
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100598 argn = printllval(tcp, "%llu, ", 1);
John Hughesbdf48f52001-03-06 15:08:09 +0000599 else
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100600 argn = printllval(tcp, "%lld, ", 1);
601 printxval(whence, tcp->u_arg[argn], "SEEK_???");
John Hughesbdf48f52001-03-06 15:08:09 +0000602 }
603 return RVAL_LUDECIMAL;
604}
605#endif
606
John Hughes70623be2001-03-08 13:59:00 +0000607#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000608int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000609sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000610{
611 if (entering(tcp)) {
612 printpath(tcp, tcp->u_arg[0]);
613 tprintf(", %lu", tcp->u_arg[1]);
614 }
615 return 0;
616}
John Hughes5a826b82001-03-07 13:21:24 +0000617#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000618
John Hughes70623be2001-03-08 13:59:00 +0000619#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000620int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000621sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000622{
623 if (entering(tcp)) {
624 printpath(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100625 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000626 }
627 return 0;
628}
629#endif
630
John Hughes70623be2001-03-08 13:59:00 +0000631#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000632int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000633sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000634{
635 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300636 printfd(tcp, tcp->u_arg[0]);
637 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000638 }
639 return 0;
640}
John Hughes5a826b82001-03-07 13:21:24 +0000641#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000642
John Hughes70623be2001-03-08 13:59:00 +0000643#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000644int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000645sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000646{
647 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300648 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200649 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100650 printllval(tcp, "%llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000651 }
652 return 0;
653}
654#endif
655
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000656/* several stats */
657
Roland McGrathd9f816f2004-09-04 03:39:20 +0000658static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000659 { S_IFREG, "S_IFREG" },
660 { S_IFSOCK, "S_IFSOCK" },
661 { S_IFIFO, "S_IFIFO" },
662 { S_IFLNK, "S_IFLNK" },
663 { S_IFDIR, "S_IFDIR" },
664 { S_IFBLK, "S_IFBLK" },
665 { S_IFCHR, "S_IFCHR" },
666 { 0, NULL },
667};
668
Roland McGrathf9c49b22004-10-06 22:11:54 +0000669static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000670sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000671{
672 static char buf[64];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000673 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000674
675 if ((mode & S_IFMT) == 0)
676 s = "";
677 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
678 sprintf(buf, "%#o", mode);
679 return buf;
680 }
681 sprintf(buf, "%s%s%s%s", s,
682 (mode & S_ISUID) ? "|S_ISUID" : "",
683 (mode & S_ISGID) ? "|S_ISGID" : "",
684 (mode & S_ISVTX) ? "|S_ISVTX" : "");
685 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
686 if (mode)
687 sprintf(buf + strlen(buf), "|%#o", mode);
688 s = (*buf == '|') ? buf + 1 : buf;
689 return *s ? s : "0";
690}
691
692static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000693sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000694{
695 struct tm *tmp;
696 static char buf[32];
697
698 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000699 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000700 return buf;
701 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200702 tmp = localtime(&t);
703 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000704 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
705 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
706 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
707 else
708 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
709
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000710 return buf;
711}
712
713#ifdef LINUXSPARC
714typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000715 int tv_sec;
716 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000717} timestruct_t;
718
719struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000720 unsigned st_dev;
721 int st_pad1[3]; /* network id */
722 unsigned st_ino;
723 unsigned st_mode;
724 unsigned st_nlink;
725 unsigned st_uid;
726 unsigned st_gid;
727 unsigned st_rdev;
728 int st_pad2[2];
729 int st_size;
730 int st_pad3; /* st_size, off_t expansion */
731 timestruct_t st_atime;
732 timestruct_t st_mtime;
733 timestruct_t st_ctime;
734 int st_blksize;
735 int st_blocks;
736 char st_fstype[16];
737 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000738};
739
740static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000741printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000742{
743 struct solstat statbuf;
744
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000745 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200746 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000747 return;
748 }
749 if (!abbrev(tcp)) {
750 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
751 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
752 (unsigned long) (statbuf.st_dev & 0x3ffff),
753 (unsigned long) statbuf.st_ino,
754 sprintmode(statbuf.st_mode));
755 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
756 (unsigned long) statbuf.st_nlink,
757 (unsigned long) statbuf.st_uid,
758 (unsigned long) statbuf.st_gid);
759 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
760 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
761 }
762 else
763 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
764 switch (statbuf.st_mode & S_IFMT) {
765 case S_IFCHR: case S_IFBLK:
766 tprintf("st_rdev=makedev(%lu, %lu), ",
767 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
768 (unsigned long) (statbuf.st_rdev & 0x3ffff));
769 break;
770 default:
771 tprintf("st_size=%u, ", statbuf.st_size);
772 break;
773 }
774 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000775 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
776 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
777 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000778 }
779 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200780 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000781}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000782
783#if defined (SPARC64)
784static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000785printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000786{
787 struct stat_sparc64 statbuf;
788
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000789 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200790 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000791 return;
792 }
793
794 if (!abbrev(tcp)) {
795 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
796 (unsigned long) major(statbuf.st_dev),
797 (unsigned long) minor(statbuf.st_dev),
798 (unsigned long) statbuf.st_ino,
799 sprintmode(statbuf.st_mode));
800 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
801 (unsigned long) statbuf.st_nlink,
802 (unsigned long) statbuf.st_uid,
803 (unsigned long) statbuf.st_gid);
804 tprintf("st_blksize=%lu, ",
805 (unsigned long) statbuf.st_blksize);
806 tprintf("st_blocks=%lu, ",
807 (unsigned long) statbuf.st_blocks);
808 }
809 else
810 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
811 switch (statbuf.st_mode & S_IFMT) {
812 case S_IFCHR: case S_IFBLK:
813 tprintf("st_rdev=makedev(%lu, %lu), ",
814 (unsigned long) major(statbuf.st_rdev),
815 (unsigned long) minor(statbuf.st_rdev));
816 break;
817 default:
818 tprintf("st_size=%lu, ", statbuf.st_size);
819 break;
820 }
821 if (!abbrev(tcp)) {
822 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
823 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
824 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200825 tprints("}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000826 }
827 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200828 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000829}
830#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000831#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000832
Andreas Schwabd69fa492010-07-12 21:39:57 +0200833#if defined LINUX && defined POWERPC64
834struct stat_powerpc32 {
835 unsigned int st_dev;
836 unsigned int st_ino;
837 unsigned int st_mode;
838 unsigned short st_nlink;
839 unsigned int st_uid;
840 unsigned int st_gid;
841 unsigned int st_rdev;
842 unsigned int st_size;
843 unsigned int st_blksize;
844 unsigned int st_blocks;
845 unsigned int st_atime;
846 unsigned int st_atime_nsec;
847 unsigned int st_mtime;
848 unsigned int st_mtime_nsec;
849 unsigned int st_ctime;
850 unsigned int st_ctime_nsec;
851 unsigned int __unused4;
852 unsigned int __unused5;
853};
854
855static void
856printstat_powerpc32(struct tcb *tcp, long addr)
857{
858 struct stat_powerpc32 statbuf;
859
860 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200861 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200862 return;
863 }
864
865 if (!abbrev(tcp)) {
866 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
867 major(statbuf.st_dev), minor(statbuf.st_dev),
868 statbuf.st_ino,
869 sprintmode(statbuf.st_mode));
870 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
871 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
872 tprintf("st_blksize=%u, ", statbuf.st_blksize);
873 tprintf("st_blocks=%u, ", statbuf.st_blocks);
874 }
875 else
876 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
877 switch (statbuf.st_mode & S_IFMT) {
878 case S_IFCHR: case S_IFBLK:
879 tprintf("st_rdev=makedev(%lu, %lu), ",
880 (unsigned long) major(statbuf.st_rdev),
881 (unsigned long) minor(statbuf.st_rdev));
882 break;
883 default:
884 tprintf("st_size=%u, ", statbuf.st_size);
885 break;
886 }
887 if (!abbrev(tcp)) {
888 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
889 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
890 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200891 tprints("}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200892 }
893 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200894 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200895}
896#endif /* LINUX && POWERPC64 */
897
Roland McGratha4d48532005-06-08 20:45:28 +0000898static const struct xlat fileflags[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000899 { 0, NULL },
900};
901
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000902
John Hughes70623be2001-03-08 13:59:00 +0000903#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000904static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000905realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000906{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000907 if (!abbrev(tcp)) {
908 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
909 (unsigned long) major(statbuf->st_dev),
910 (unsigned long) minor(statbuf->st_dev),
911 (unsigned long) statbuf->st_ino,
912 sprintmode(statbuf->st_mode));
913 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
914 (unsigned long) statbuf->st_nlink,
915 (unsigned long) statbuf->st_uid,
916 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000917#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000918 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
919#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000920#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000921 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
922#endif
923 }
924 else
925 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
926 switch (statbuf->st_mode & S_IFMT) {
927 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000928#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000929 tprintf("st_rdev=makedev(%lu, %lu), ",
930 (unsigned long) major(statbuf->st_rdev),
931 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000932#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000933 tprintf("st_size=makedev(%lu, %lu), ",
934 (unsigned long) major(statbuf->st_size),
935 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000936#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000937 break;
938 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000939 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000940 break;
941 }
942 if (!abbrev(tcp)) {
943 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
944 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
945 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000946#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200947 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000948 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000949#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000950#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000951 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
952#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000953#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000954 tprintf(", st_level=%ld", statbuf->st_level);
955#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000956#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000957 tprintf(", st_fstype=%.*s",
958 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
959#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000960#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000961 tprintf(", st_gen=%u", statbuf->st_gen);
962#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200963 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000964 }
965 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200966 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000967}
968
Nate Sammons771a6ff1999-04-05 22:39:31 +0000969
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000970static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000971printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000972{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000973 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000974
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000975 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200976 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000977 return;
978 }
979 if (syserror(tcp) || !verbose(tcp)) {
980 tprintf("%#lx", addr);
981 return;
982 }
983
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000984#ifdef LINUXSPARC
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000985 if (current_personality == 1) {
986 printstatsol(tcp, addr);
987 return;
988 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000989#ifdef SPARC64
990 else if (current_personality == 2) {
991 printstat_sparc64(tcp, addr);
992 return;
993 }
994#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000995#endif /* LINUXSPARC */
996
Andreas Schwabd69fa492010-07-12 21:39:57 +0200997#if defined LINUX && defined POWERPC64
998 if (current_personality == 1) {
999 printstat_powerpc32(tcp, addr);
1000 return;
1001 }
1002#endif
1003
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001004 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001005 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001006 return;
1007 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001008
1009 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001010}
John Hughes70623be2001-03-08 13:59:00 +00001011#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001012
Roland McGrathe6d0f712007-08-07 01:22:49 +00001013#if !defined HAVE_STAT64 && defined LINUX && defined X86_64
1014/*
1015 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1016 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1017 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1018 * __GNUC__ is needed for the required __attribute__ below.
1019 */
1020struct stat64 {
1021 unsigned long long st_dev;
1022 unsigned char __pad0[4];
1023 unsigned int __st_ino;
1024 unsigned int st_mode;
1025 unsigned int st_nlink;
1026 unsigned int st_uid;
1027 unsigned int st_gid;
1028 unsigned long long st_rdev;
1029 unsigned char __pad3[4];
1030 long long st_size;
1031 unsigned int st_blksize;
1032 unsigned long long st_blocks;
1033 unsigned int st_atime;
1034 unsigned int st_atime_nsec;
1035 unsigned int st_mtime;
1036 unsigned int st_mtime_nsec;
1037 unsigned int st_ctime;
1038 unsigned int st_ctime_nsec;
1039 unsigned long long st_ino;
1040} __attribute__((packed));
1041# define HAVE_STAT64 1
1042# define STAT64_SIZE 96
1043#endif
1044
Wichert Akkermanc7926982000-04-10 22:22:31 +00001045#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001046static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001047printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001048{
1049 struct stat64 statbuf;
1050
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001051#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001052 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1053#endif
1054
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001055 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001056 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001057 return;
1058 }
1059 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001060 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001061 return;
1062 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001063
1064#ifdef LINUXSPARC
1065 if (current_personality == 1) {
1066 printstatsol(tcp, addr);
1067 return;
1068 }
1069# ifdef SPARC64
1070 else if (current_personality == 2) {
1071 printstat_sparc64(tcp, addr);
1072 return;
1073 }
1074# endif
1075#endif /* LINUXSPARC */
1076
Andreas Schwab61b74352009-10-16 11:37:13 +02001077#if defined LINUX && defined X86_64
1078 if (current_personality == 0) {
1079 printstat(tcp, addr);
1080 return;
1081 }
1082#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +00001083
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001084 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001085 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001086 return;
1087 }
1088
1089 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001090#ifdef HAVE_LONG_LONG
1091 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1092#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001093 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001094#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001095 (unsigned long) major(statbuf.st_dev),
1096 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001097#ifdef HAVE_LONG_LONG
1098 (unsigned long long) statbuf.st_ino,
1099#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001100 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001101#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001102 sprintmode(statbuf.st_mode));
1103 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1104 (unsigned long) statbuf.st_nlink,
1105 (unsigned long) statbuf.st_uid,
1106 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001107#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001108 tprintf("st_blksize=%lu, ",
1109 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001110#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1111#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001112 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001113#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001114 }
1115 else
1116 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1117 switch (statbuf.st_mode & S_IFMT) {
1118 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001119#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001120 tprintf("st_rdev=makedev(%lu, %lu), ",
1121 (unsigned long) major(statbuf.st_rdev),
1122 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001123#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001124 tprintf("st_size=makedev(%lu, %lu), ",
1125 (unsigned long) major(statbuf.st_size),
1126 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001127#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001128 break;
1129 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001130#ifdef HAVE_LONG_LONG
1131 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1132#else
1133 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1134#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001135 break;
1136 }
1137 if (!abbrev(tcp)) {
1138 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1139 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001140 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001141#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001142 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001143 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001144#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001145#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001146 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1147#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001148#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001149 tprintf(", st_level=%ld", statbuf.st_level);
1150#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001151#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001152 tprintf(", st_fstype=%.*s",
1153 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1154#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001155#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001156 tprintf(", st_gen=%u", statbuf.st_gen);
1157#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001158 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001159 }
1160 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001161 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001162}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001163#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001164
H.J. Lua13b3fe2012-02-03 10:10:30 -08001165#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT) \
1166 && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001167static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001168convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001169{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001170 newbuf->st_dev = oldbuf->st_dev;
1171 newbuf->st_ino = oldbuf->st_ino;
1172 newbuf->st_mode = oldbuf->st_mode;
1173 newbuf->st_nlink = oldbuf->st_nlink;
1174 newbuf->st_uid = oldbuf->st_uid;
1175 newbuf->st_gid = oldbuf->st_gid;
1176 newbuf->st_rdev = oldbuf->st_rdev;
1177 newbuf->st_size = oldbuf->st_size;
1178 newbuf->st_atime = oldbuf->st_atime;
1179 newbuf->st_mtime = oldbuf->st_mtime;
1180 newbuf->st_ctime = oldbuf->st_ctime;
1181 newbuf->st_blksize = 0; /* not supported in old_stat */
1182 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001183}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001184
1185
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001186static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001187printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001188{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001189 struct __old_kernel_stat statbuf;
1190 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001191
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001192 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001193 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001194 return;
1195 }
1196 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001197 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001198 return;
1199 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001200
1201#ifdef LINUXSPARC
1202 if (current_personality == 1) {
1203 printstatsol(tcp, addr);
1204 return;
1205 }
1206#endif /* LINUXSPARC */
1207
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001208 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001209 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001210 return;
1211 }
1212
1213 convertoldstat(&statbuf, &newstatbuf);
1214 realprintstat(tcp, &newstatbuf);
1215}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001216#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001217
John Hughes70623be2001-03-08 13:59:00 +00001218#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001219int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001220sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001221{
1222 if (entering(tcp)) {
1223 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001224 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001225 } else {
1226 printstat(tcp, tcp->u_arg[1]);
1227 }
1228 return 0;
1229}
John Hughesb8c9f772001-03-07 16:53:07 +00001230#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001231
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001232int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001233sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001234{
1235#ifdef HAVE_STAT64
1236 if (entering(tcp)) {
1237 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001238 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001239 } else {
1240 printstat64(tcp, tcp->u_arg[1]);
1241 }
1242 return 0;
1243#else
1244 return printargs(tcp);
1245#endif
1246}
1247
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001248static const struct xlat fstatatflags[] = {
1249#ifndef AT_SYMLINK_NOFOLLOW
1250# define AT_SYMLINK_NOFOLLOW 0x100
1251#endif
1252 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1253 { 0, NULL },
1254};
Roland McGrath6afc5652007-07-24 01:57:11 +00001255#define utimensatflags fstatatflags
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001256
1257int
1258sys_newfstatat(struct tcb *tcp)
1259{
1260 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001261 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001262 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001263 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001264 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001265#ifdef POWERPC64
1266 if (current_personality == 0)
1267 printstat(tcp, tcp->u_arg[2]);
1268 else
1269 printstat64(tcp, tcp->u_arg[2]);
1270#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001271 printstat64(tcp, tcp->u_arg[2]);
1272#else
1273 printstat(tcp, tcp->u_arg[2]);
1274#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001275 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001276 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1277 }
1278 return 0;
1279}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001280
H.J. Lua13b3fe2012-02-03 10:10:30 -08001281#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT) \
1282 && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001283int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001284sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001285{
1286 if (entering(tcp)) {
1287 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001288 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001289 } else {
1290 printoldstat(tcp, tcp->u_arg[1]);
1291 }
1292 return 0;
1293}
Roland McGrath79db8af2003-06-27 21:20:09 +00001294#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001295
John Hughes70623be2001-03-08 13:59:00 +00001296#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001297int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001298sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001299{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001300 if (entering(tcp)) {
1301 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001302 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001303 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001304 printstat(tcp, tcp->u_arg[1]);
1305 }
1306 return 0;
1307}
John Hughesb8c9f772001-03-07 16:53:07 +00001308#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001309
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001310int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001311sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001312{
1313#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001314 if (entering(tcp)) {
1315 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001316 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001317 } else {
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001318 printstat64(tcp, tcp->u_arg[1]);
1319 }
1320 return 0;
1321#else
1322 return printargs(tcp);
1323#endif
1324}
1325
H.J. Lua13b3fe2012-02-03 10:10:30 -08001326#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT) \
1327 && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001328int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001329sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001330{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001331 if (entering(tcp)) {
1332 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001333 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001334 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001335 printoldstat(tcp, tcp->u_arg[1]);
1336 }
1337 return 0;
1338}
Roland McGrath79db8af2003-06-27 21:20:09 +00001339#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001340
John Hughes70623be2001-03-08 13:59:00 +00001341#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001342int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001343sys_lstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001344{
1345 if (entering(tcp)) {
1346 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001347 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001348 } else {
1349 printstat(tcp, tcp->u_arg[1]);
1350 }
1351 return 0;
1352}
John Hughesb8c9f772001-03-07 16:53:07 +00001353#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001354
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001355int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001356sys_lstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001357{
1358#ifdef HAVE_STAT64
1359 if (entering(tcp)) {
1360 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001361 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001362 } else {
1363 printstat64(tcp, tcp->u_arg[1]);
1364 }
1365 return 0;
1366#else
1367 return printargs(tcp);
1368#endif
1369}
1370
H.J. Lua13b3fe2012-02-03 10:10:30 -08001371#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT) \
1372 && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001373int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001374sys_oldlstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001375{
1376 if (entering(tcp)) {
1377 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001378 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001379 } else {
1380 printoldstat(tcp, tcp->u_arg[1]);
1381 }
1382 return 0;
1383}
Roland McGrath79db8af2003-06-27 21:20:09 +00001384#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001385
1386
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001387#if defined(SVR4) || defined(LINUXSPARC)
1388
1389int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001390sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001391{
1392 if (entering(tcp)) {
1393 tprintf("%ld, ", tcp->u_arg[0]);
1394 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001395 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001396 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001397#ifdef _STAT64_VER
1398 if (tcp->u_arg[0] == _STAT64_VER)
1399 printstat64 (tcp, tcp->u_arg[2]);
1400 else
1401#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001402 printstat(tcp, tcp->u_arg[2]);
1403 }
1404 return 0;
1405}
1406
1407int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001408sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001409{
1410 if (entering(tcp))
1411 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1412 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001413#ifdef _STAT64_VER
1414 if (tcp->u_arg[0] == _STAT64_VER)
1415 printstat64 (tcp, tcp->u_arg[2]);
1416 else
1417#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001418 printstat(tcp, tcp->u_arg[2]);
1419 }
1420 return 0;
1421}
1422
1423int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001424sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001425{
1426 if (entering(tcp)) {
1427 tprintf("%ld, ", tcp->u_arg[0]);
1428 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001429 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001430 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001431#ifdef _STAT64_VER
1432 if (tcp->u_arg[0] == _STAT64_VER)
1433 printstat64 (tcp, tcp->u_arg[2]);
1434 else
1435#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001436 printstat(tcp, tcp->u_arg[2]);
1437 }
1438 return 0;
1439}
1440
1441int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001442sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001443{
1444 int mode = tcp->u_arg[2];
1445
1446 if (entering(tcp)) {
1447 tprintf("%ld, ", tcp->u_arg[0]);
1448 printpath(tcp, tcp->u_arg[1]);
1449 tprintf(", %s", sprintmode(mode));
1450 switch (mode & S_IFMT) {
1451 case S_IFCHR: case S_IFBLK:
1452#ifdef LINUXSPARC
1453 tprintf(", makedev(%lu, %lu)",
1454 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1455 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001456#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001457 tprintf(", makedev(%lu, %lu)",
1458 (unsigned long) major(tcp->u_arg[3]),
1459 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001460#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001461 break;
1462 default:
1463 break;
1464 }
1465 }
1466 return 0;
1467}
1468
Wichert Akkerman8829a551999-06-11 13:18:40 +00001469#ifdef HAVE_SYS_ACL_H
1470
1471#include <sys/acl.h>
1472
Roland McGratha4d48532005-06-08 20:45:28 +00001473static const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001474#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001475 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001476#endif
1477#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001478 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001479#endif
1480#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001481 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001482#endif
1483#ifdef ACL_GET
1484 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001485#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001486#ifdef ACL_SET
1487 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001488#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001489#ifdef ACL_CNT
1490 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001491#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001492 { 0, NULL },
1493};
1494
1495int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001496sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001497{
1498 if (entering(tcp)) {
1499 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001500 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001501 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1502 tprintf(", %ld", tcp->u_arg[2]);
1503 /*
1504 * FIXME - dump out the list of aclent_t's pointed to
1505 * by "tcp->u_arg[3]" if it's not NULL.
1506 */
1507 if (tcp->u_arg[3])
1508 tprintf(", %#lx", tcp->u_arg[3]);
1509 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001510 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001511 }
1512 return 0;
1513}
1514
1515
1516int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001517sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001518{
1519 if (entering(tcp)) {
1520 tprintf("%ld, ", tcp->u_arg[0]);
1521 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1522 tprintf(", %ld", tcp->u_arg[2]);
1523 /*
1524 * FIXME - dump out the list of aclent_t's pointed to
1525 * by "tcp->u_arg[3]" if it's not NULL.
1526 */
1527 if (tcp->u_arg[3])
1528 tprintf(", %#lx", tcp->u_arg[3]);
1529 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001530 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001531 }
1532 return 0;
1533}
1534
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001535
Roland McGratha4d48532005-06-08 20:45:28 +00001536static const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001537#ifdef IPC_SHM
1538 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001539#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001540#ifdef IPC_SEM
1541 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001542#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001543#ifdef IPC_MSG
1544 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001545#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001546 { 0, NULL },
1547};
1548
1549
1550int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001551sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001552{
1553 if (entering(tcp)) {
1554 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1555 tprintf(", %#lx, ", tcp->u_arg[1]);
1556 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1557 tprintf(", %ld", tcp->u_arg[3]);
1558 /*
1559 * FIXME - dump out the list of aclent_t's pointed to
1560 * by "tcp->u_arg[4]" if it's not NULL.
1561 */
1562 if (tcp->u_arg[4])
1563 tprintf(", %#lx", tcp->u_arg[4]);
1564 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001565 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001566 }
1567 return 0;
1568}
1569
Wichert Akkerman8829a551999-06-11 13:18:40 +00001570#endif /* HAVE_SYS_ACL_H */
1571
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001572#endif /* SVR4 || LINUXSPARC */
1573
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001574
Roland McGrathd9f816f2004-09-04 03:39:20 +00001575static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001576 { 0x73757245, "CODA_SUPER_MAGIC" },
1577 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1578 { 0x1373, "DEVFS_SUPER_MAGIC" },
1579 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1580 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001581 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1582 { 0xef53, "EXT2_SUPER_MAGIC" },
1583 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001584 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001585 { 0x9660, "ISOFS_SUPER_MAGIC" },
1586 { 0x137f, "MINIX_SUPER_MAGIC" },
1587 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001588 { 0x2468, "MINIX2_SUPER_MAGIC" },
1589 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001590 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001591 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001592 { 0x6969, "NFS_SUPER_MAGIC" },
1593 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001594 { 0x002f, "QNX4_SUPER_MAGIC" },
1595 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1596 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1597 { 0x517b, "SMB_SUPER_MAGIC" },
1598 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1599 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1600 { 0x00011954, "UFS_MAGIC" },
1601 { 0x54190100, "UFS_CIGAM" },
1602 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001603 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001604 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001605 { 0, NULL },
1606};
1607
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001608
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001609
Roland McGrathf9c49b22004-10-06 22:11:54 +00001610static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001611sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001612{
1613 static char buf[32];
Roland McGrathf9c49b22004-10-06 22:11:54 +00001614 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001615
1616 s = xlookup(fsmagic, magic);
1617 if (s) {
1618 sprintf(buf, "\"%s\"", s);
1619 return buf;
1620 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001621 sprintf(buf, "%#x", magic);
1622 return buf;
1623}
1624
1625static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001626printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001627{
1628 struct statfs statbuf;
1629
1630 if (syserror(tcp) || !verbose(tcp)) {
1631 tprintf("%#lx", addr);
1632 return;
1633 }
1634 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001635 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001636 return;
1637 }
1638#ifdef ALPHA
1639
1640 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1641 sprintfstype(statbuf.f_type),
1642 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001643 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001644 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001645 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1646 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001647#else /* !ALPHA */
1648 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1649 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001650 (unsigned long)statbuf.f_bsize,
1651 (unsigned long)statbuf.f_blocks,
1652 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001653 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1654 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001655 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001656 (unsigned long)statbuf.f_ffree,
1657 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001658 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001659#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001660#ifdef _STATFS_F_FRSIZE
1661 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1662#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001663 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001664}
1665
1666int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001667sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001668{
1669 if (entering(tcp)) {
1670 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001671 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001672 } else {
1673 printstatfs(tcp, tcp->u_arg[1]);
1674 }
1675 return 0;
1676}
1677
1678int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001679sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001680{
1681 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001682 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001683 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001684 } else {
1685 printstatfs(tcp, tcp->u_arg[1]);
1686 }
1687 return 0;
1688}
1689
Bernhard Reutner-Fischer9906e6d2009-10-14 16:33:58 +02001690#if defined LINUX && defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001691static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001692printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001693{
1694 struct statfs64 statbuf;
1695
1696 if (syserror(tcp) || !verbose(tcp)) {
1697 tprintf("%#lx", addr);
1698 return;
1699 }
1700 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001701 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001702 return;
1703 }
Roland McGrath08738432005-06-03 02:40:39 +00001704 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001705 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001706 (unsigned long long)statbuf.f_bsize,
1707 (unsigned long long)statbuf.f_blocks,
1708 (unsigned long long)statbuf.f_bfree);
1709 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1710 (unsigned long long)statbuf.f_bavail,
1711 (unsigned long long)statbuf.f_files,
1712 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001713 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1714 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001715#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001716 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001717#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001718#ifdef _STATFS_F_FLAGS
1719 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1720#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001721 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001722}
1723
Andreas Schwab7d558012012-01-17 18:14:22 +01001724struct compat_statfs64 {
1725 uint32_t f_type;
1726 uint32_t f_bsize;
1727 uint64_t f_blocks;
1728 uint64_t f_bfree;
1729 uint64_t f_bavail;
1730 uint64_t f_files;
1731 uint64_t f_ffree;
1732 fsid_t f_fsid;
1733 uint32_t f_namelen;
1734 uint32_t f_frsize;
1735 uint32_t f_flags;
1736 uint32_t f_spare[4];
1737}
1738#if defined(X86_64) || defined(IA64)
1739 __attribute__ ((packed, aligned(4)))
1740#endif
1741;
1742
1743static void
1744printcompat_statfs64(struct tcb *tcp, long addr)
1745{
1746 struct compat_statfs64 statbuf;
1747
1748 if (syserror(tcp) || !verbose(tcp)) {
1749 tprintf("%#lx", addr);
1750 return;
1751 }
1752 if (umove(tcp, addr, &statbuf) < 0) {
1753 tprints("{...}");
1754 return;
1755 }
1756 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1757 sprintfstype(statbuf.f_type),
1758 (unsigned long)statbuf.f_bsize,
1759 (unsigned long long)statbuf.f_blocks,
1760 (unsigned long long)statbuf.f_bfree);
1761 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1762 (unsigned long long)statbuf.f_bavail,
1763 (unsigned long long)statbuf.f_files,
1764 (unsigned long long)statbuf.f_ffree,
1765 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1766 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1767 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1768 tprintf(", f_flags=%lu", (unsigned long)statbuf.f_frsize);
1769 tprints("}");
1770}
1771
Roland McGrathab147c52003-07-17 09:03:02 +00001772int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001773sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001774{
1775 if (entering(tcp)) {
1776 printpath(tcp, tcp->u_arg[0]);
1777 tprintf(", %lu, ", tcp->u_arg[1]);
1778 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001779 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001780 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001781 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1782 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001783 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001784 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001785 }
1786 return 0;
1787}
1788
1789int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001790sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001791{
1792 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001793 printfd(tcp, tcp->u_arg[0]);
1794 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001795 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001796 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001797 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001798 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1799 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001800 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001801 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001802 }
1803 return 0;
1804}
1805#endif
1806
Michal Ludvig53b320f2002-09-23 13:30:09 +00001807#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001808
1809int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001810osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001811{
1812 if (entering(tcp)) {
1813 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001814 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001815 } else {
1816 printstatfs(tcp, tcp->u_arg[1]);
1817 tprintf(", %lu", tcp->u_arg[2]);
1818 }
1819 return 0;
1820}
1821
1822int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001823osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001824{
1825 if (entering(tcp)) {
1826 tprintf("%lu, ", tcp->u_arg[0]);
1827 } else {
1828 printstatfs(tcp, tcp->u_arg[1]);
1829 tprintf(", %lu", tcp->u_arg[2]);
1830 }
1831 return 0;
1832}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001833#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001834
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001835
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001836
1837/* directory */
1838int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001839sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001840{
1841 if (entering(tcp)) {
1842 printpath(tcp, tcp->u_arg[0]);
1843 }
1844 return 0;
1845}
1846
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001847static int
1848decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001849{
1850 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001851 printpath(tcp, tcp->u_arg[offset]);
1852 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001853 }
1854 return 0;
1855}
1856
1857int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001858sys_mkdir(struct tcb *tcp)
1859{
1860 return decode_mkdir(tcp, 0);
1861}
1862
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001863int
1864sys_mkdirat(struct tcb *tcp)
1865{
1866 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001867 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001868 return decode_mkdir(tcp, 1);
1869}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001870
1871int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001872sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001873{
1874 if (entering(tcp)) {
1875 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001876 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001877 printpath(tcp, tcp->u_arg[1]);
1878 }
1879 return 0;
1880}
1881
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001882int
1883sys_linkat(struct tcb *tcp)
1884{
1885 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001886 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001887 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001888 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001889 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001890 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001891 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001892 printfd(tcp, tcp->u_arg[4]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001893 }
1894 return 0;
1895}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001896
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001897static const struct xlat unlinkatflags[] = {
1898#ifndef AT_REMOVEDIR
1899# define AT_REMOVEDIR 0x200
1900#endif
1901 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1902 { 0, NULL },
1903};
1904
1905int
1906sys_unlinkat(struct tcb *tcp)
1907{
1908 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001909 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001910 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001911 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001912 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1913 }
1914 return 0;
1915}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001916
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001917int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001918sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001919{
1920 if (entering(tcp)) {
1921 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001922 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001923 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001924 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001925 }
1926 return 0;
1927}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001928
1929static int
1930decode_readlink(struct tcb *tcp, int offset)
1931{
1932 if (entering(tcp)) {
1933 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001934 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001935 } else {
1936 if (syserror(tcp))
1937 tprintf("%#lx", tcp->u_arg[offset + 1]);
1938 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001939 /* Used to use printpathn(), but readlink
1940 * neither includes NUL in the returned count,
1941 * nor actually writes it into memory.
1942 * printpathn() would decide on printing
1943 * "..." continuation based on garbage
1944 * past return buffer's end.
1945 */
1946 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001947 tprintf(", %lu", tcp->u_arg[offset + 2]);
1948 }
1949 return 0;
1950}
1951
1952int
1953sys_readlink(struct tcb *tcp)
1954{
1955 return decode_readlink(tcp, 0);
1956}
1957
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001958int
1959sys_readlinkat(struct tcb *tcp)
1960{
1961 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001962 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001963 return decode_readlink(tcp, 1);
1964}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001965
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001966int
1967sys_renameat(struct tcb *tcp)
1968{
1969 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001970 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001971 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001972 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001973 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001974 printpath(tcp, tcp->u_arg[3]);
1975 }
1976 return 0;
1977}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001978
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001979int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001980sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001981{
1982 if (entering(tcp)) {
1983 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001984 printuid(", ", tcp->u_arg[1]);
1985 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001986 }
1987 return 0;
1988}
1989
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001990int
1991sys_fchownat(struct tcb *tcp)
1992{
1993 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001994 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001995 printpath(tcp, tcp->u_arg[1]);
1996 printuid(", ", tcp->u_arg[2]);
1997 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001998 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001999 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
2000 }
2001 return 0;
2002}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002003
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002004int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002005sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002006{
2007 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002008 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002009 printuid(", ", tcp->u_arg[1]);
2010 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002011 }
2012 return 0;
2013}
2014
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002015static int
2016decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002017{
2018 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002019 printpath(tcp, tcp->u_arg[offset]);
2020 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002021 }
2022 return 0;
2023}
2024
2025int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002026sys_chmod(struct tcb *tcp)
2027{
2028 return decode_chmod(tcp, 0);
2029}
2030
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002031int
2032sys_fchmodat(struct tcb *tcp)
2033{
2034 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002035 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002036 return decode_chmod(tcp, 1);
2037}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002038
2039int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002040sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002041{
2042 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002043 printfd(tcp, tcp->u_arg[0]);
2044 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002045 }
2046 return 0;
2047}
2048
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002049#ifdef ALPHA
2050int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002051sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002052{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002053 if (entering(tcp)) {
2054 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002055 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002056 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2057 }
2058 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002059}
2060#endif
2061
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002062static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002063decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002064{
2065 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002066 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002067 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002068 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002069 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00002070 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002071 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00002072 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2073 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002074 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002075 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002076 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00002077 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002078 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00002079 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002080 }
2081 return 0;
2082}
2083
2084int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002085sys_utimes(struct tcb *tcp)
2086{
Roland McGrath6afc5652007-07-24 01:57:11 +00002087 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002088}
2089
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002090int
2091sys_futimesat(struct tcb *tcp)
2092{
2093 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002094 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002095 return decode_utimes(tcp, 1, 0);
2096}
2097
2098int
2099sys_utimensat(struct tcb *tcp)
2100{
2101 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002102 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002103 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002104 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002105 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2106 }
2107 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002108}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002109
2110int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002111sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002112{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002113 union {
2114 long utl[2];
2115 int uti[2];
2116 } u;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002117
2118 if (entering(tcp)) {
2119 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002120 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002121 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002122 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002123 else if (!verbose(tcp))
2124 tprintf("%#lx", tcp->u_arg[1]);
Roland McGrath7e9817c2007-07-05 20:31:58 +00002125 else if (umoven(tcp, tcp->u_arg[1],
2126 2 * personality_wordsize[current_personality],
2127 (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002128 tprints("[?, ?]");
Roland McGrath7e9817c2007-07-05 20:31:58 +00002129 else if (personality_wordsize[current_personality]
2130 == sizeof u.utl[0]) {
2131 tprintf("[%s,", sprinttime(u.utl[0]));
2132 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002133 }
Roland McGrath7e9817c2007-07-05 20:31:58 +00002134 else if (personality_wordsize[current_personality]
2135 == sizeof u.uti[0]) {
2136 tprintf("[%s,", sprinttime(u.uti[0]));
2137 tprintf(" %s]", sprinttime(u.uti[1]));
2138 }
2139 else
2140 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002141 }
2142 return 0;
2143}
2144
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002145static int
2146decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002147{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002148 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002149
2150 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002151 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002152 tprintf(", %s", sprintmode(mode));
2153 switch (mode & S_IFMT) {
2154 case S_IFCHR: case S_IFBLK:
2155#ifdef LINUXSPARC
2156 if (current_personality == 1)
2157 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002158 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2159 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002160 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002161#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002162 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002163 (unsigned long) major(tcp->u_arg[offset + 2]),
2164 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002165 break;
2166 default:
2167 break;
2168 }
2169 }
2170 return 0;
2171}
2172
2173int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002174sys_mknod(struct tcb *tcp)
2175{
2176 return decode_mknod(tcp, 0);
2177}
2178
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002179int
2180sys_mknodat(struct tcb *tcp)
2181{
2182 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002183 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002184 return decode_mknod(tcp, 1);
2185}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002186
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002187
2188int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002189sys_fsync(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002190{
2191 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002192 printfd(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002193 }
2194 return 0;
2195}
2196
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002197
2198static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002199printdir(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002200{
2201 struct dirent d;
2202
2203 if (!verbose(tcp)) {
2204 tprintf("%#lx", addr);
2205 return;
2206 }
2207 if (umove(tcp, addr, &d) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002208 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002209 return;
2210 }
2211 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002212 tprints("d_name=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002213 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002214 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002215}
2216
2217int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002218sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002219{
2220 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002221 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002222 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002223 } else {
2224 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2225 tprintf("%#lx", tcp->u_arg[1]);
2226 else
2227 printdir(tcp, tcp->u_arg[1]);
2228 /* Not much point in printing this out, it is always 1. */
2229 if (tcp->u_arg[2] != 1)
2230 tprintf(", %lu", tcp->u_arg[2]);
2231 }
2232 return 0;
2233}
2234
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002235
Roland McGratha4d48532005-06-08 20:45:28 +00002236static const struct xlat direnttypes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002237 { DT_UNKNOWN, "DT_UNKNOWN" },
2238 { DT_FIFO, "DT_FIFO" },
2239 { DT_CHR, "DT_CHR" },
2240 { DT_DIR, "DT_DIR" },
2241 { DT_BLK, "DT_BLK" },
2242 { DT_REG, "DT_REG" },
2243 { DT_LNK, "DT_LNK" },
2244 { DT_SOCK, "DT_SOCK" },
2245 { DT_WHT, "DT_WHT" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002246 { 0, NULL },
2247};
2248
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002249
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002250int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002251sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002252{
2253 int i, len, dents = 0;
2254 char *buf;
2255
2256 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002257 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002258 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002259 return 0;
2260 }
2261 if (syserror(tcp) || !verbose(tcp)) {
2262 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2263 return 0;
2264 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002265 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002266 /* Beware of insanely large or negative values in tcp->u_rval */
2267 if (tcp->u_rval > 1024*1024)
2268 len = 1024*1024;
2269 if (tcp->u_rval < 0)
2270 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002271 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002272 if (len && !buf)
2273 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002274 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002275 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002276 free(buf);
2277 return 0;
2278 }
2279 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002280 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002281 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002282 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002283 if (!abbrev(tcp)) {
2284 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2285 i ? " " : "", d->d_ino, d->d_off);
2286 tprintf("d_reclen=%u, d_name=\"%s\"}",
2287 d->d_reclen, d->d_name);
2288 }
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002289 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002290 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002291 break;
2292 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002293 i += d->d_reclen;
2294 dents++;
2295 }
2296 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002297 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002298 else
2299 tprintf("/* %u entries */", dents);
2300 tprintf(", %lu", tcp->u_arg[2]);
2301 free(buf);
2302 return 0;
2303}
2304
John Hughesbdf48f52001-03-06 15:08:09 +00002305
2306#if _LFS64_LARGEFILE
2307int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002308sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002309{
2310 int i, len, dents = 0;
2311 char *buf;
2312
2313 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002314 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002315 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002316 return 0;
2317 }
2318 if (syserror(tcp) || !verbose(tcp)) {
2319 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2320 return 0;
2321 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002322
John Hughesbdf48f52001-03-06 15:08:09 +00002323 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002324 /* Beware of insanely large or negative tcp->u_rval */
2325 if (tcp->u_rval > 1024*1024)
2326 len = 1024*1024;
2327 if (tcp->u_rval < 0)
2328 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002329 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002330 if (len && !buf)
2331 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002332
John Hughesbdf48f52001-03-06 15:08:09 +00002333 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002334 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002335 free(buf);
2336 return 0;
2337 }
2338 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002339 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002340 for (i = 0; i < len;) {
2341 struct dirent64 *d = (struct dirent64 *) &buf[i];
John Hughesbdf48f52001-03-06 15:08:09 +00002342 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002343 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002344 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002345 d->d_ino,
2346 d->d_off);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002347 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002348 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002349 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002350 tprintf("d_reclen=%u, d_name=\"%s\"}",
2351 d->d_reclen, d->d_name);
2352 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002353 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002354 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002355 break;
2356 }
John Hughesbdf48f52001-03-06 15:08:09 +00002357 i += d->d_reclen;
2358 dents++;
2359 }
2360 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002361 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002362 else
2363 tprintf("/* %u entries */", dents);
2364 tprintf(", %lu", tcp->u_arg[2]);
2365 free(buf);
2366 return 0;
2367}
2368#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002369
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002370
2371int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002372sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002373{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002374 if (exiting(tcp)) {
2375 if (syserror(tcp))
2376 tprintf("%#lx", tcp->u_arg[0]);
2377 else
2378 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2379 tprintf(", %lu", tcp->u_arg[1]);
2380 }
2381 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002382}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002383
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002384
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002385#ifdef HAVE_SYS_ASYNCH_H
2386
2387int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002388sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002389{
2390 struct aio_result_t res;
2391
2392 if (entering(tcp)) {
2393 tprintf("%lu, ", tcp->u_arg[0]);
2394 } else {
2395 if (syserror(tcp))
2396 tprintf("%#lx", tcp->u_arg[1]);
2397 else
2398 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2399 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2400 printxval(whence, tcp->u_arg[4], "L_???");
2401 if (syserror(tcp) || tcp->u_arg[5] == 0
2402 || umove(tcp, tcp->u_arg[5], &res) < 0)
2403 tprintf(", %#lx", tcp->u_arg[5]);
2404 else
2405 tprintf(", {aio_return %d aio_errno %d}",
2406 res.aio_return, res.aio_errno);
2407 }
2408 return 0;
2409}
2410
2411int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002412sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002413{
2414 struct aio_result_t res;
2415
2416 if (entering(tcp)) {
2417 tprintf("%lu, ", tcp->u_arg[0]);
2418 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2419 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2420 printxval(whence, tcp->u_arg[4], "L_???");
2421 }
2422 else {
2423 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002424 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002425 else if (syserror(tcp)
2426 || umove(tcp, tcp->u_arg[5], &res) < 0)
2427 tprintf(", %#lx", tcp->u_arg[5]);
2428 else
2429 tprintf(", {aio_return %d aio_errno %d}",
2430 res.aio_return, res.aio_errno);
2431 }
2432 return 0;
2433}
2434
2435int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002436sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002437{
2438 if (entering(tcp))
2439 printtv(tcp, tcp->u_arg[0]);
2440 return 0;
2441}
2442
2443int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002444sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002445{
2446 struct aio_result_t res;
2447
2448 if (exiting(tcp)) {
2449 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002450 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002451 else if (syserror(tcp)
2452 || umove(tcp, tcp->u_arg[0], &res) < 0)
2453 tprintf("%#lx", tcp->u_arg[0]);
2454 else
2455 tprintf("{aio_return %d aio_errno %d}",
2456 res.aio_return, res.aio_errno);
2457 }
2458 return 0;
2459}
2460
2461#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002462
Roland McGratha4d48532005-06-08 20:45:28 +00002463static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002464#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002465 { XATTR_CREATE, "XATTR_CREATE" },
2466 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002467#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002468 { 0, NULL }
2469};
2470
Roland McGrath3292e222004-08-31 06:30:48 +00002471static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002472print_xattr_val(struct tcb *tcp, int failed,
2473 unsigned long arg,
2474 unsigned long insize,
2475 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002476{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002477 if (!failed) {
2478 unsigned long capacity = 4 * size + 1;
2479 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2480 if (buf == NULL || /* probably a bogus size argument */
2481 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2482 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002483 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002484 else {
2485 unsigned char *out = buf;
2486 unsigned char *in = &buf[3 * size];
2487 size_t i;
2488 for (i = 0; i < size; ++i) {
2489 if (isprint(in[i]))
2490 *out++ = in[i];
2491 else {
2492#define tohex(n) "0123456789abcdef"[n]
2493 *out++ = '\\';
2494 *out++ = 'x';
2495 *out++ = tohex(in[i] / 16);
2496 *out++ = tohex(in[i] % 16);
2497 }
2498 }
2499 /* Don't print terminating NUL if there is one. */
2500 if (i > 0 && in[i - 1] == '\0')
2501 out -= 4;
2502 *out = '\0';
2503 tprintf(", \"%s\", %ld", buf, insize);
2504 }
2505 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002506 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002507 if (failed)
2508 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002509}
2510
Roland McGrath186c5ac2002-12-15 23:58:23 +00002511int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002512sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002513{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002514 if (entering(tcp)) {
2515 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002516 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002517 printstr(tcp, tcp->u_arg[1], -1);
2518 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002519 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002520 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2521 }
2522 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002523}
2524
2525int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002526sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002527{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002528 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002529 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002530 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002531 printstr(tcp, tcp->u_arg[1], -1);
2532 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002533 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002534 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2535 }
2536 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002537}
2538
2539int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002540sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002541{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002542 if (entering(tcp)) {
2543 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002544 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002545 printstr(tcp, tcp->u_arg[1], -1);
2546 } else {
2547 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2548 tcp->u_rval);
2549 }
2550 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002551}
2552
2553int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002554sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002555{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002556 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002557 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002558 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002559 printstr(tcp, tcp->u_arg[1], -1);
2560 } else {
2561 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2562 tcp->u_rval);
2563 }
2564 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002565}
2566
2567int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002568sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002569{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002570 if (entering(tcp)) {
2571 printpath(tcp, tcp->u_arg[0]);
2572 } else {
2573 /* XXX Print value in format */
2574 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2575 }
2576 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002577}
2578
2579int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002580sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002581{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002582 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002583 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002584 } else {
2585 /* XXX Print value in format */
2586 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2587 }
2588 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002589}
2590
2591int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002592sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002593{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002594 if (entering(tcp)) {
2595 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002596 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002597 printstr(tcp, tcp->u_arg[1], -1);
2598 }
2599 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002600}
2601
2602int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002603sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002604{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002605 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002606 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002607 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002608 printstr(tcp, tcp->u_arg[1], -1);
2609 }
2610 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002611}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002612
2613
2614static const struct xlat advise[] = {
2615 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2616 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2617 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2618 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2619 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2620 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2621 { 0, NULL }
2622};
2623
2624
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002625int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002626sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002627{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002628 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002629 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002630 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002631 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002632 argn = printllval(tcp, "%lld", 1);
2633 tprintf(", %ld, ", tcp->u_arg[argn++]);
2634 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002635 }
2636 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002637}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002638
2639
2640int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002641sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002642{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002643 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002644 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002645 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002646 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002647#if defined ARM || defined POWERPC
2648 argn = printllval(tcp, "%lld, ", 2);
2649#else
2650 argn = printllval(tcp, "%lld, ", 1);
2651#endif
2652 argn = printllval(tcp, "%lld, ", argn);
2653#if defined ARM || defined POWERPC
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002654 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002655#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002656 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002657#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002658 }
2659 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002660}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002661
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002662static const struct xlat inotify_modes[] = {
Dmitry V. Levind475c062011-03-03 01:02:41 +00002663 { 0x00000001, "IN_ACCESS" },
2664 { 0x00000002, "IN_MODIFY" },
2665 { 0x00000004, "IN_ATTRIB" },
2666 { 0x00000008, "IN_CLOSE_WRITE"},
2667 { 0x00000010, "IN_CLOSE_NOWRITE"},
2668 { 0x00000020, "IN_OPEN" },
2669 { 0x00000040, "IN_MOVED_FROM" },
2670 { 0x00000080, "IN_MOVED_TO" },
2671 { 0x00000100, "IN_CREATE" },
2672 { 0x00000200, "IN_DELETE" },
2673 { 0x00000400, "IN_DELETE_SELF"},
2674 { 0x00000800, "IN_MOVE_SELF" },
2675 { 0x00002000, "IN_UNMOUNT" },
2676 { 0x00004000, "IN_Q_OVERFLOW" },
2677 { 0x00008000, "IN_IGNORED" },
2678 { 0x01000000, "IN_ONLYDIR" },
2679 { 0x02000000, "IN_DONT_FOLLOW"},
2680 { 0x20000000, "IN_MASK_ADD" },
2681 { 0x40000000, "IN_ISDIR" },
2682 { 0x80000000, "IN_ONESHOT" },
2683 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002684};
2685
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002686static const struct xlat inotify_init_flags[] = {
2687 { 0x00000800, "IN_NONBLOCK" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002688 { 0x00080000, "IN_CLOEXEC" },
2689 { 0, NULL }
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002690};
2691
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002692int
2693sys_inotify_add_watch(struct tcb *tcp)
2694{
2695 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002696 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002697 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002698 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002699 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002700 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2701 }
2702 return 0;
2703}
2704
2705int
2706sys_inotify_rm_watch(struct tcb *tcp)
2707{
2708 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002709 printfd(tcp, tcp->u_arg[0]);
2710 tprintf(", %ld", tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002711 }
2712 return 0;
2713}
Roland McGrath96a96612008-05-20 04:56:18 +00002714
2715int
Mark Wielaardbab89402010-03-21 14:41:26 +01002716sys_inotify_init1(struct tcb *tcp)
2717{
2718 if (entering(tcp))
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002719 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
Mark Wielaardbab89402010-03-21 14:41:26 +01002720 return 0;
2721}
2722
2723int
Roland McGrath96a96612008-05-20 04:56:18 +00002724sys_fallocate(struct tcb *tcp)
2725{
2726 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002727 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002728 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002729 tprints(", ");
Roland McGrath96a96612008-05-20 04:56:18 +00002730 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002731 argn = printllval(tcp, "%llu, ", 2); /* offset */
2732 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002733 }
2734 return 0;
2735}