blob: e7792223d696cf05e6f655f46ed0df6889105c38 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include <dirent.h>
Dmitry V. Levin88293652012-03-09 21:02:19 +000033#include <sys/swap.h>
Roland McGrathc531e572008-08-01 01:13:10 +000034
Denys Vlasenko9472a272013-02-12 11:43:46 +010035#if defined(SPARC) || defined(SPARC64)
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000036struct stat {
37 unsigned short st_dev;
38 unsigned int st_ino;
39 unsigned short st_mode;
40 short st_nlink;
41 unsigned short st_uid;
42 unsigned short st_gid;
43 unsigned short st_rdev;
44 unsigned int st_size;
45 int st_atime;
46 unsigned int __unused1;
47 int st_mtime;
48 unsigned int __unused2;
49 int st_ctime;
50 unsigned int __unused3;
51 int st_blksize;
52 int st_blocks;
53 unsigned int __unused4[2];
54};
Denys Vlasenko84703742012-02-25 02:38:52 +010055# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +000056struct stat_sparc64 {
57 unsigned int st_dev;
58 unsigned long st_ino;
59 unsigned int st_mode;
60 unsigned int st_nlink;
61 unsigned int st_uid;
62 unsigned int st_gid;
63 unsigned int st_rdev;
64 long st_size;
65 long st_atime;
66 long st_mtime;
67 long st_ctime;
68 long st_blksize;
69 long st_blocks;
70 unsigned long __unused4[2];
71};
Denys Vlasenko84703742012-02-25 02:38:52 +010072# endif /* SPARC64 */
73# define stat kernel_stat
74# include <asm/stat.h>
75# undef stat
H.J. Lu35be5812012-04-16 13:00:01 +020076#elif defined(X32)
77struct stat {
78 unsigned long long st_dev;
79 unsigned long long st_ino;
80 unsigned long long st_nlink;
81
82 unsigned int st_mode;
83 unsigned int st_uid;
84 unsigned int st_gid;
85 unsigned int __pad0;
86 unsigned long long st_rdev;
87 long long st_size;
88 long long st_blksize;
89 long long st_blocks;
90
91 unsigned long long st_atime;
92 unsigned long long st_atime_nsec;
93 unsigned long long st_mtime;
94 unsigned long long st_mtime_nsec;
95 unsigned long long st_ctime;
96 unsigned long long st_ctime_nsec;
97 long long __unused[3];
98};
H.J. Lu085e4282012-04-17 11:05:04 -070099
100struct stat64 {
101 unsigned long long st_dev;
102 unsigned char __pad0[4];
103 unsigned long __st_ino;
104 unsigned int st_mode;
105 unsigned int st_nlink;
106 unsigned long st_uid;
107 unsigned long st_gid;
108 unsigned long long st_rdev;
109 unsigned char __pad3[4];
110 long long st_size;
111 unsigned long st_blksize;
112 unsigned long long st_blocks;
113 unsigned long st_atime;
114 unsigned long st_atime_nsec;
115 unsigned long st_mtime;
116 unsigned int st_mtime_nsec;
117 unsigned long st_ctime;
118 unsigned long st_ctime_nsec;
119 unsigned long long st_ino;
120};
Denys Vlasenko84703742012-02-25 02:38:52 +0100121#else
122# undef dev_t
123# undef ino_t
124# undef mode_t
125# undef nlink_t
126# undef uid_t
127# undef gid_t
128# undef off_t
129# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100130# define dev_t __kernel_dev_t
131# define ino_t __kernel_ino_t
132# define mode_t __kernel_mode_t
133# define nlink_t __kernel_nlink_t
134# define uid_t __kernel_uid_t
135# define gid_t __kernel_gid_t
136# define off_t __kernel_off_t
137# define loff_t __kernel_loff_t
Wichert Akkermana6013701999-07-08 14:00:58 +0000138
Denys Vlasenko84703742012-02-25 02:38:52 +0100139# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +0000140
Denys Vlasenko84703742012-02-25 02:38:52 +0100141# undef dev_t
142# undef ino_t
143# undef mode_t
144# undef nlink_t
145# undef uid_t
146# undef gid_t
147# undef off_t
148# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100149# define dev_t dev_t
150# define ino_t ino_t
151# define mode_t mode_t
152# define nlink_t nlink_t
153# define uid_t uid_t
154# define gid_t gid_t
155# define off_t off_t
156# define loff_t loff_t
157#endif
158
159#ifdef HPPA /* asm-parisc/stat.h defines stat64 */
160# undef stat64
161#endif
162#define stat libc_stat
163#define stat64 libc_stat64
164#include <sys/stat.h>
165#undef stat
166#undef stat64
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100167/* These might be macros. */
Denys Vlasenko84703742012-02-25 02:38:52 +0100168#undef st_atime
169#undef st_mtime
170#undef st_ctime
171#ifdef HPPA
172# define stat64 hpux_stat64
173#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000174
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000175#include <fcntl.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000176#ifdef HAVE_SYS_VFS_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100177# include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000178#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +0000179#ifdef HAVE_LINUX_XATTR_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100180# include <linux/xattr.h>
Denys Vlasenkoed720fd2012-02-25 02:24:03 +0100181#else
Denys Vlasenko84703742012-02-25 02:38:52 +0100182# define XATTR_CREATE 1
183# define XATTR_REPLACE 2
Roland McGrath186c5ac2002-12-15 23:58:23 +0000184#endif
185
John Hughes70623be2001-03-08 13:59:00 +0000186#if HAVE_LONG_LONG_OFF_T
187/*
188 * Ugly hacks for systems that have typedef long long off_t
189 */
Denys Vlasenko84703742012-02-25 02:38:52 +0100190# define stat64 stat
191# define HAVE_STAT64 1 /* Ugly hack */
Denys Vlasenko84703742012-02-25 02:38:52 +0100192# define sys_stat64 sys_stat
193# define sys_fstat64 sys_fstat
194# define sys_lstat64 sys_lstat
Denys Vlasenko84703742012-02-25 02:38:52 +0100195# define sys_truncate64 sys_truncate
196# define sys_ftruncate64 sys_ftruncate
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000197#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000198
199#ifdef MAJOR_IN_SYSMACROS
Denys Vlasenko84703742012-02-25 02:38:52 +0100200# include <sys/sysmacros.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000201#endif
202
203#ifdef MAJOR_IN_MKDEV
Denys Vlasenko84703742012-02-25 02:38:52 +0100204# include <sys/mkdev.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205#endif
206
207#ifdef HAVE_SYS_ASYNCH_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100208# include <sys/asynch.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000209#endif
210
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100211struct kernel_dirent {
212 unsigned long d_ino;
213 unsigned long d_off;
214 unsigned short d_reclen;
215 char d_name[1];
216};
217
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000218const struct xlat open_access_modes[] = {
219 { O_RDONLY, "O_RDONLY" },
220 { O_WRONLY, "O_WRONLY" },
221 { O_RDWR, "O_RDWR" },
222#ifdef O_ACCMODE
223 { O_ACCMODE, "O_ACCMODE" },
224#endif
225 { 0, NULL },
226};
227
228const struct xlat open_mode_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000229 { O_CREAT, "O_CREAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000230 { O_EXCL, "O_EXCL" },
231 { O_NOCTTY, "O_NOCTTY" },
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000232 { O_TRUNC, "O_TRUNC" },
233 { O_APPEND, "O_APPEND" },
234 { O_NONBLOCK, "O_NONBLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000235#ifdef O_SYNC
236 { O_SYNC, "O_SYNC" },
237#endif
238#ifdef O_ASYNC
239 { O_ASYNC, "O_ASYNC" },
240#endif
241#ifdef O_DSYNC
242 { O_DSYNC, "O_DSYNC" },
243#endif
244#ifdef O_RSYNC
245 { O_RSYNC, "O_RSYNC" },
246#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000247#if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000248 { O_NDELAY, "O_NDELAY" },
249#endif
250#ifdef O_PRIV
251 { O_PRIV, "O_PRIV" },
252#endif
253#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000254 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000255#endif
256#ifdef O_LARGEFILE
Roland McGrathfee836e2005-02-02 22:11:32 +0000257# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
258# undef O_LARGEFILE
259# ifdef SPARC64
260# define O_LARGEFILE 0x40000
261# elif defined X86_64 || defined S390X
262# define O_LARGEFILE 0100000
263# endif
264# endif
Roland McGrath663a8a02005-02-04 09:49:56 +0000265# ifdef O_LARGEFILE
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200266 { O_LARGEFILE, "O_LARGEFILE" },
Roland McGrath663a8a02005-02-04 09:49:56 +0000267# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000268#endif
269#ifdef O_DIRECTORY
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200270 { O_DIRECTORY, "O_DIRECTORY" },
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000271#endif
272#ifdef O_NOFOLLOW
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200273 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000274#endif
Roland McGrath1025c3e2005-05-09 07:40:35 +0000275#ifdef O_NOATIME
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200276 { O_NOATIME, "O_NOATIME" },
Roland McGrath1025c3e2005-05-09 07:40:35 +0000277#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000278#ifdef O_CLOEXEC
279 { O_CLOEXEC, "O_CLOEXEC" },
280#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000281#ifdef FNDELAY
282 { FNDELAY, "FNDELAY" },
283#endif
284#ifdef FAPPEND
285 { FAPPEND, "FAPPEND" },
286#endif
287#ifdef FMARK
288 { FMARK, "FMARK" },
289#endif
290#ifdef FDEFER
291 { FDEFER, "FDEFER" },
292#endif
293#ifdef FASYNC
294 { FASYNC, "FASYNC" },
295#endif
296#ifdef FSHLOCK
297 { FSHLOCK, "FSHLOCK" },
298#endif
299#ifdef FEXLOCK
300 { FEXLOCK, "FEXLOCK" },
301#endif
302#ifdef FCREAT
303 { FCREAT, "FCREAT" },
304#endif
305#ifdef FTRUNC
306 { FTRUNC, "FTRUNC" },
307#endif
308#ifdef FEXCL
309 { FEXCL, "FEXCL" },
310#endif
311#ifdef FNBIO
312 { FNBIO, "FNBIO" },
313#endif
314#ifdef FSYNC
315 { FSYNC, "FSYNC" },
316#endif
317#ifdef FNOCTTY
318 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000319#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000320#ifdef O_SHLOCK
321 { O_SHLOCK, "O_SHLOCK" },
322#endif
323#ifdef O_EXLOCK
324 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000325#endif
326 { 0, NULL },
327};
328
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000329#ifndef AT_FDCWD
330# define AT_FDCWD -100
331#endif
332
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000333/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
334 * extension to get the right value. We do this by declaring fd as int here.
335 */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000336static void
Dmitry V. Levin31382132011-03-04 05:08:02 +0300337print_dirfd(struct tcb *tcp, int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000338{
339 if (fd == AT_FDCWD)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200340 tprints("AT_FDCWD, ");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200341 else {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300342 printfd(tcp, fd);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200343 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300344 }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000345}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000346
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000347/*
348 * low bits of the open(2) flags define access mode,
349 * other bits are real flags.
350 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000351const char *
352sprint_open_modes(mode_t flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000353{
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100354 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000355 char *p;
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100356 char sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000357 const char *str;
358 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000359
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100360 sep = ' ';
361 p = stpcpy(outstr, "flags");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000362 str = xlookup(open_access_modes, flags & 3);
363 if (str) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100364 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200365 p = stpcpy(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000366 flags &= ~3;
367 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000368 return outstr;
369 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000370 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000371
372 for (x = open_mode_flags; x->str; x++) {
373 if ((flags & x->val) == x->val) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100374 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200375 p = stpcpy(p, x->str);
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000376 flags &= ~x->val;
377 if (!flags)
378 return outstr;
379 sep = '|';
380 }
381 }
382 /* flags is still nonzero */
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100383 *p++ = sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000384 sprintf(p, "%#x", flags);
385 return outstr;
386}
387
388void
389tprint_open_modes(mode_t flags)
390{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200391 tprints(sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000392}
393
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000394static int
395decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000396{
397 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000398 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200399 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000400 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000401 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000402 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000403 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000404 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000405 }
406 }
407 return 0;
408}
409
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000410int
411sys_open(struct tcb *tcp)
412{
413 return decode_open(tcp, 0);
414}
415
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000416int
417sys_openat(struct tcb *tcp)
418{
419 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300420 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000421 return decode_open(tcp, 1);
422}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000423
Denys Vlasenko9472a272013-02-12 11:43:46 +0100424#if defined(SPARC) || defined(SPARC64)
Roland McGratha4d48532005-06-08 20:45:28 +0000425static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000426 { 0, "O_RDWR" },
427 { 1, "O_RDONLY" },
428 { 2, "O_WRONLY" },
429 { 0x80, "O_NONBLOCK" },
430 { 8, "O_APPEND" },
431 { 0x100, "O_CREAT" },
432 { 0x200, "O_TRUNC" },
433 { 0x400, "O_EXCL" },
434 { 0x800, "O_NOCTTY" },
435 { 0x10, "O_SYNC" },
436 { 0x40, "O_DSYNC" },
437 { 0x8000, "O_RSYNC" },
438 { 4, "O_NDELAY" },
439 { 0x1000, "O_PRIV" },
440 { 0, NULL },
441};
442
443int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000444solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000445{
446 if (entering(tcp)) {
447 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200448 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000449 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000450 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000451 if (tcp->u_arg[1] & 0x100) {
452 /* mode */
453 tprintf(", %#lo", tcp->u_arg[2]);
454 }
455 }
456 return 0;
457}
458
459#endif
460
461int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000462sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000463{
464 if (entering(tcp)) {
465 printpath(tcp, tcp->u_arg[0]);
466 tprintf(", %#lo", tcp->u_arg[1]);
467 }
468 return 0;
469}
470
Roland McGrathd9f816f2004-09-04 03:39:20 +0000471static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000472 { F_OK, "F_OK", },
473 { R_OK, "R_OK" },
474 { W_OK, "W_OK" },
475 { X_OK, "X_OK" },
476#ifdef EFF_ONLY_OK
477 { EFF_ONLY_OK, "EFF_ONLY_OK" },
478#endif
479#ifdef EX_OK
480 { EX_OK, "EX_OK" },
481#endif
482 { 0, NULL },
483};
484
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000485static int
486decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000487{
488 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000489 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200490 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000491 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000492 }
493 return 0;
494}
495
496int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000497sys_access(struct tcb *tcp)
498{
499 return decode_access(tcp, 0);
500}
501
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000502int
503sys_faccessat(struct tcb *tcp)
504{
505 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300506 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000507 return decode_access(tcp, 1);
508}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000509
510int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000511sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000512{
513 if (entering(tcp)) {
514 tprintf("%#lo", tcp->u_arg[0]);
515 }
516 return RVAL_OCTAL;
517}
518
Roland McGrathd9f816f2004-09-04 03:39:20 +0000519static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520 { SEEK_SET, "SEEK_SET" },
521 { SEEK_CUR, "SEEK_CUR" },
522 { SEEK_END, "SEEK_END" },
523 { 0, NULL },
524};
525
H.J. Luc933f272012-04-16 17:41:13 +0200526#if defined(LINUX_MIPSN32) || defined(X32)
Roland McGrath542c2c62008-05-20 01:11:56 +0000527int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000528sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000529{
530 long long offset;
531 int _whence;
532
533 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300534 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200535 tprints(", ");
Roland McGrath542c2c62008-05-20 01:11:56 +0000536 offset = tcp->ext_arg[1];
537 _whence = tcp->u_arg[2];
538 if (_whence == SEEK_SET)
539 tprintf("%llu, ", offset);
540 else
541 tprintf("%lld, ", offset);
542 printxval(whence, _whence, "SEEK_???");
543 }
H.J. Ludd0130b2012-04-16 12:16:45 +0200544 return RVAL_LUDECIMAL;
Roland McGrath542c2c62008-05-20 01:11:56 +0000545}
H.J. Lu085e4282012-04-17 11:05:04 -0700546
547# if defined(X32)
548int
549sys_lseek32(struct tcb *tcp)
550{
551 long offset;
552 int _whence;
553
554 if (entering(tcp)) {
555 printfd(tcp, tcp->u_arg[0]);
556 tprints(", ");
557 offset = tcp->u_arg[1];
558 _whence = tcp->u_arg[2];
559 if (_whence == SEEK_SET)
560 tprintf("%lu, ", offset);
561 else
562 tprintf("%ld, ", offset);
563 printxval(whence, _whence, "SEEK_???");
564 }
565 return RVAL_UDECIMAL;
566}
567# endif
H.J. Ludd0130b2012-04-16 12:16:45 +0200568#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000569int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000570sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000571{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000572 off_t offset;
573 int _whence;
574
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000575 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300576 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200577 tprints(", ");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000578 offset = tcp->u_arg[1];
579 _whence = tcp->u_arg[2];
580 if (_whence == SEEK_SET)
581 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000582 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000583 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000584 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000585 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000586 return RVAL_UDECIMAL;
587}
John Hughes5a826b82001-03-07 13:21:24 +0000588#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000589
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000590int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000591sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000592{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000593 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300594 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000595 /*
596 * This one call takes explicitly two 32-bit arguments hi, lo,
597 * rather than one 64-bit argument for which LONG_LONG works
598 * appropriate for the native byte order.
599 */
600 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300601 tprintf(", %llu, ",
602 ((long long int) tcp->u_arg[1]) << 32 |
603 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000604 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300605 tprintf(", %lld, ",
606 ((long long int) tcp->u_arg[1]) << 32 |
607 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000608 }
609 else {
610 long long int off;
611 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
612 tprintf("%#lx, ", tcp->u_arg[3]);
613 else
614 tprintf("[%llu], ", off);
615 printxval(whence, tcp->u_arg[4], "SEEK_???");
616 }
617 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000618}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000619
620int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000621sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000622{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000623 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100624 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300625 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +0200626 argn = printllval(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100627 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000628 }
629 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000630}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000631
John Hughes70623be2001-03-08 13:59:00 +0000632#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000633int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000634sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000635{
636 if (entering(tcp)) {
637 printpath(tcp, tcp->u_arg[0]);
638 tprintf(", %lu", tcp->u_arg[1]);
639 }
640 return 0;
641}
John Hughes5a826b82001-03-07 13:21:24 +0000642#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000643
John Hughes70623be2001-03-08 13:59:00 +0000644#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000645int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000646sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000647{
648 if (entering(tcp)) {
649 printpath(tcp, tcp->u_arg[0]);
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
John Hughes70623be2001-03-08 13:59:00 +0000656#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000657int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000658sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000659{
660 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300661 printfd(tcp, tcp->u_arg[0]);
662 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000663 }
664 return 0;
665}
John Hughes5a826b82001-03-07 13:21:24 +0000666#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000667
John Hughes70623be2001-03-08 13:59:00 +0000668#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000669int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000670sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000671{
672 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300673 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +0200674 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000675 }
676 return 0;
677}
678#endif
679
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000680/* several stats */
681
Roland McGrathd9f816f2004-09-04 03:39:20 +0000682static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000683 { S_IFREG, "S_IFREG" },
684 { S_IFSOCK, "S_IFSOCK" },
685 { S_IFIFO, "S_IFIFO" },
686 { S_IFLNK, "S_IFLNK" },
687 { S_IFDIR, "S_IFDIR" },
688 { S_IFBLK, "S_IFBLK" },
689 { S_IFCHR, "S_IFCHR" },
690 { 0, NULL },
691};
692
Roland McGrathf9c49b22004-10-06 22:11:54 +0000693static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000694sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000695{
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100696 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
697 + sizeof(int)*3
698 + /*paranoia:*/ 8];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000699 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000700
701 if ((mode & S_IFMT) == 0)
702 s = "";
703 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
704 sprintf(buf, "%#o", mode);
705 return buf;
706 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100707 s = buf + sprintf(buf, "%s%s%s%s", s,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000708 (mode & S_ISUID) ? "|S_ISUID" : "",
709 (mode & S_ISGID) ? "|S_ISGID" : "",
710 (mode & S_ISVTX) ? "|S_ISVTX" : "");
711 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
712 if (mode)
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100713 sprintf((char*)s, "|%#o", mode);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000714 s = (*buf == '|') ? buf + 1 : buf;
715 return *s ? s : "0";
716}
717
718static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000719sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000720{
721 struct tm *tmp;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100722 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000723
724 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000725 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000726 return buf;
727 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200728 tmp = localtime(&t);
729 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000730 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
731 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
732 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
733 else
734 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
735
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000736 return buf;
737}
738
Denys Vlasenko9472a272013-02-12 11:43:46 +0100739#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000740typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000741 int tv_sec;
742 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000743} timestruct_t;
744
745struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000746 unsigned st_dev;
747 int st_pad1[3]; /* network id */
748 unsigned st_ino;
749 unsigned st_mode;
750 unsigned st_nlink;
751 unsigned st_uid;
752 unsigned st_gid;
753 unsigned st_rdev;
754 int st_pad2[2];
755 int st_size;
756 int st_pad3; /* st_size, off_t expansion */
757 timestruct_t st_atime;
758 timestruct_t st_mtime;
759 timestruct_t st_ctime;
760 int st_blksize;
761 int st_blocks;
762 char st_fstype[16];
763 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000764};
765
766static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000767printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000768{
769 struct solstat statbuf;
770
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000771 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200772 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000773 return;
774 }
775 if (!abbrev(tcp)) {
776 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
777 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
778 (unsigned long) (statbuf.st_dev & 0x3ffff),
779 (unsigned long) statbuf.st_ino,
780 sprintmode(statbuf.st_mode));
781 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
782 (unsigned long) statbuf.st_nlink,
783 (unsigned long) statbuf.st_uid,
784 (unsigned long) statbuf.st_gid);
785 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
786 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
787 }
788 else
789 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
790 switch (statbuf.st_mode & S_IFMT) {
791 case S_IFCHR: case S_IFBLK:
792 tprintf("st_rdev=makedev(%lu, %lu), ",
793 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
794 (unsigned long) (statbuf.st_rdev & 0x3ffff));
795 break;
796 default:
797 tprintf("st_size=%u, ", statbuf.st_size);
798 break;
799 }
800 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000801 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
802 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
803 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000804 }
805 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200806 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000807}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000808
Denys Vlasenko9472a272013-02-12 11:43:46 +0100809# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000810static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000811printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000812{
813 struct stat_sparc64 statbuf;
814
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000815 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200816 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000817 return;
818 }
819
820 if (!abbrev(tcp)) {
821 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
822 (unsigned long) major(statbuf.st_dev),
823 (unsigned long) minor(statbuf.st_dev),
824 (unsigned long) statbuf.st_ino,
825 sprintmode(statbuf.st_mode));
826 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
827 (unsigned long) statbuf.st_nlink,
828 (unsigned long) statbuf.st_uid,
829 (unsigned long) statbuf.st_gid);
830 tprintf("st_blksize=%lu, ",
831 (unsigned long) statbuf.st_blksize);
832 tprintf("st_blocks=%lu, ",
833 (unsigned long) statbuf.st_blocks);
834 }
835 else
836 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
837 switch (statbuf.st_mode & S_IFMT) {
838 case S_IFCHR: case S_IFBLK:
839 tprintf("st_rdev=makedev(%lu, %lu), ",
840 (unsigned long) major(statbuf.st_rdev),
841 (unsigned long) minor(statbuf.st_rdev));
842 break;
843 default:
844 tprintf("st_size=%lu, ", statbuf.st_size);
845 break;
846 }
847 if (!abbrev(tcp)) {
848 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
849 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100850 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000851 }
852 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200853 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000854}
Denys Vlasenko9472a272013-02-12 11:43:46 +0100855# endif /* SPARC64 */
856#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000857
Denys Vlasenko84703742012-02-25 02:38:52 +0100858#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200859struct stat_powerpc32 {
860 unsigned int st_dev;
861 unsigned int st_ino;
862 unsigned int st_mode;
863 unsigned short st_nlink;
864 unsigned int st_uid;
865 unsigned int st_gid;
866 unsigned int st_rdev;
867 unsigned int st_size;
868 unsigned int st_blksize;
869 unsigned int st_blocks;
870 unsigned int st_atime;
871 unsigned int st_atime_nsec;
872 unsigned int st_mtime;
873 unsigned int st_mtime_nsec;
874 unsigned int st_ctime;
875 unsigned int st_ctime_nsec;
876 unsigned int __unused4;
877 unsigned int __unused5;
878};
879
880static void
881printstat_powerpc32(struct tcb *tcp, long addr)
882{
883 struct stat_powerpc32 statbuf;
884
885 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200886 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200887 return;
888 }
889
890 if (!abbrev(tcp)) {
891 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
892 major(statbuf.st_dev), minor(statbuf.st_dev),
893 statbuf.st_ino,
894 sprintmode(statbuf.st_mode));
895 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
896 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
897 tprintf("st_blksize=%u, ", statbuf.st_blksize);
898 tprintf("st_blocks=%u, ", statbuf.st_blocks);
899 }
900 else
901 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
902 switch (statbuf.st_mode & S_IFMT) {
903 case S_IFCHR: case S_IFBLK:
904 tprintf("st_rdev=makedev(%lu, %lu), ",
905 (unsigned long) major(statbuf.st_rdev),
906 (unsigned long) minor(statbuf.st_rdev));
907 break;
908 default:
909 tprintf("st_size=%u, ", statbuf.st_size);
910 break;
911 }
912 if (!abbrev(tcp)) {
913 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
914 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100915 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200916 }
917 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200918 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200919}
Denys Vlasenko84703742012-02-25 02:38:52 +0100920#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200921
Roland McGratha4d48532005-06-08 20:45:28 +0000922static const struct xlat fileflags[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000923 { 0, NULL },
924};
925
John Hughes70623be2001-03-08 13:59:00 +0000926#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000927static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000928realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000929{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000930 if (!abbrev(tcp)) {
931 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
932 (unsigned long) major(statbuf->st_dev),
933 (unsigned long) minor(statbuf->st_dev),
934 (unsigned long) statbuf->st_ino,
935 sprintmode(statbuf->st_mode));
936 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
937 (unsigned long) statbuf->st_nlink,
938 (unsigned long) statbuf->st_uid,
939 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000940#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000941 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
942#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000943#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000944 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
945#endif
946 }
947 else
948 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
949 switch (statbuf->st_mode & S_IFMT) {
950 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000951#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000952 tprintf("st_rdev=makedev(%lu, %lu), ",
953 (unsigned long) major(statbuf->st_rdev),
954 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000955#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000956 tprintf("st_size=makedev(%lu, %lu), ",
957 (unsigned long) major(statbuf->st_size),
958 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000959#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000960 break;
961 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000962 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000963 break;
964 }
965 if (!abbrev(tcp)) {
966 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
967 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
968 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000969#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200970 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000971 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000972#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000973#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000974 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
975#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000976#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000977 tprintf(", st_level=%ld", statbuf->st_level);
978#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000979#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000980 tprintf(", st_fstype=%.*s",
981 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
982#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000983#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000984 tprintf(", st_gen=%u", statbuf->st_gen);
985#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200986 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000987 }
988 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200989 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000990}
991
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000992static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000993printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000994{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000995 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000996
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000997 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200998 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000999 return;
1000 }
1001 if (syserror(tcp) || !verbose(tcp)) {
1002 tprintf("%#lx", addr);
1003 return;
1004 }
1005
Denys Vlasenko9472a272013-02-12 11:43:46 +01001006#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001007 if (current_personality == 1) {
1008 printstatsol(tcp, addr);
1009 return;
1010 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001011#ifdef SPARC64
1012 else if (current_personality == 2) {
1013 printstat_sparc64(tcp, addr);
1014 return;
1015 }
1016#endif
Denys Vlasenko9472a272013-02-12 11:43:46 +01001017#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001018
Denys Vlasenko84703742012-02-25 02:38:52 +01001019#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +02001020 if (current_personality == 1) {
1021 printstat_powerpc32(tcp, addr);
1022 return;
1023 }
1024#endif
1025
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001026 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001027 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001028 return;
1029 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001030
1031 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001032}
John Hughes70623be2001-03-08 13:59:00 +00001033#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001034
Denys Vlasenko84703742012-02-25 02:38:52 +01001035#if !defined HAVE_STAT64 && defined X86_64
Roland McGrathe6d0f712007-08-07 01:22:49 +00001036/*
1037 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1038 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1039 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1040 * __GNUC__ is needed for the required __attribute__ below.
1041 */
1042struct stat64 {
1043 unsigned long long st_dev;
1044 unsigned char __pad0[4];
1045 unsigned int __st_ino;
1046 unsigned int st_mode;
1047 unsigned int st_nlink;
1048 unsigned int st_uid;
1049 unsigned int st_gid;
1050 unsigned long long st_rdev;
1051 unsigned char __pad3[4];
1052 long long st_size;
1053 unsigned int st_blksize;
1054 unsigned long long st_blocks;
1055 unsigned int st_atime;
1056 unsigned int st_atime_nsec;
1057 unsigned int st_mtime;
1058 unsigned int st_mtime_nsec;
1059 unsigned int st_ctime;
1060 unsigned int st_ctime_nsec;
1061 unsigned long long st_ino;
1062} __attribute__((packed));
1063# define HAVE_STAT64 1
1064# define STAT64_SIZE 96
1065#endif
1066
Wichert Akkermanc7926982000-04-10 22:22:31 +00001067#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001068static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001069printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001070{
1071 struct stat64 statbuf;
1072
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001073#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001074 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1075#endif
1076
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001077 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001078 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001079 return;
1080 }
1081 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001082 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001083 return;
1084 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001085
Denys Vlasenko9472a272013-02-12 11:43:46 +01001086#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001087 if (current_personality == 1) {
1088 printstatsol(tcp, addr);
1089 return;
1090 }
1091# ifdef SPARC64
1092 else if (current_personality == 2) {
1093 printstat_sparc64(tcp, addr);
1094 return;
1095 }
1096# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +01001097#endif /* SPARC[64] */
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001098
Denys Vlasenko84703742012-02-25 02:38:52 +01001099#if defined X86_64
H.J. Lu35be5812012-04-16 13:00:01 +02001100 if (current_personality != 1) {
Andreas Schwab61b74352009-10-16 11:37:13 +02001101 printstat(tcp, addr);
1102 return;
1103 }
1104#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +00001105
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001106 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001107 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001108 return;
1109 }
1110
1111 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001112#ifdef HAVE_LONG_LONG
1113 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1114#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001115 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001116#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001117 (unsigned long) major(statbuf.st_dev),
1118 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001119#ifdef HAVE_LONG_LONG
1120 (unsigned long long) statbuf.st_ino,
1121#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001122 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001123#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001124 sprintmode(statbuf.st_mode));
1125 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1126 (unsigned long) statbuf.st_nlink,
1127 (unsigned long) statbuf.st_uid,
1128 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001129#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001130 tprintf("st_blksize=%lu, ",
1131 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001132#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1133#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001134 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001135#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001136 }
1137 else
1138 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1139 switch (statbuf.st_mode & S_IFMT) {
1140 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001141#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001142 tprintf("st_rdev=makedev(%lu, %lu), ",
1143 (unsigned long) major(statbuf.st_rdev),
1144 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001145#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001146 tprintf("st_size=makedev(%lu, %lu), ",
1147 (unsigned long) major(statbuf.st_size),
1148 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001149#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001150 break;
1151 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001152#ifdef HAVE_LONG_LONG
1153 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1154#else
1155 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1156#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001157 break;
1158 }
1159 if (!abbrev(tcp)) {
1160 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1161 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001162 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001163#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001164 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001165 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001166#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001167#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001168 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1169#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001170#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001171 tprintf(", st_level=%ld", statbuf.st_level);
1172#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001173#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001174 tprintf(", st_fstype=%.*s",
1175 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1176#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001177#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001178 tprintf(", st_gen=%u", statbuf.st_gen);
1179#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001180 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001181 }
1182 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001183 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001184}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001185#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001186
Denys Vlasenko84703742012-02-25 02:38:52 +01001187#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001188static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001189convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001190{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001191 newbuf->st_dev = oldbuf->st_dev;
1192 newbuf->st_ino = oldbuf->st_ino;
1193 newbuf->st_mode = oldbuf->st_mode;
1194 newbuf->st_nlink = oldbuf->st_nlink;
1195 newbuf->st_uid = oldbuf->st_uid;
1196 newbuf->st_gid = oldbuf->st_gid;
1197 newbuf->st_rdev = oldbuf->st_rdev;
1198 newbuf->st_size = oldbuf->st_size;
1199 newbuf->st_atime = oldbuf->st_atime;
1200 newbuf->st_mtime = oldbuf->st_mtime;
1201 newbuf->st_ctime = oldbuf->st_ctime;
1202 newbuf->st_blksize = 0; /* not supported in old_stat */
1203 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001204}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001205
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001206static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001207printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001208{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001209 struct __old_kernel_stat statbuf;
1210 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001211
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001212 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001213 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001214 return;
1215 }
1216 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001217 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001218 return;
1219 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001220
Denys Vlasenko9472a272013-02-12 11:43:46 +01001221# if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001222 if (current_personality == 1) {
1223 printstatsol(tcp, addr);
1224 return;
1225 }
Denys Vlasenko84703742012-02-25 02:38:52 +01001226# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001227
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001228 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001229 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001230 return;
1231 }
1232
1233 convertoldstat(&statbuf, &newstatbuf);
1234 realprintstat(tcp, &newstatbuf);
1235}
Denys Vlasenko84703742012-02-25 02:38:52 +01001236#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001237
John Hughes70623be2001-03-08 13:59:00 +00001238#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001239int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001240sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001241{
1242 if (entering(tcp)) {
1243 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001244 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001245 } else {
1246 printstat(tcp, tcp->u_arg[1]);
1247 }
1248 return 0;
1249}
John Hughesb8c9f772001-03-07 16:53:07 +00001250#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001251
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001252int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001253sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001254{
1255#ifdef HAVE_STAT64
1256 if (entering(tcp)) {
1257 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001258 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001259 } else {
1260 printstat64(tcp, tcp->u_arg[1]);
1261 }
1262 return 0;
1263#else
1264 return printargs(tcp);
1265#endif
1266}
1267
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001268#ifndef AT_SYMLINK_NOFOLLOW
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001269# define AT_SYMLINK_NOFOLLOW 0x100
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001270#endif
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001271#ifndef AT_REMOVEDIR
1272# define AT_REMOVEDIR 0x200
1273#endif
1274#ifndef AT_SYMLINK_FOLLOW
1275# define AT_SYMLINK_FOLLOW 0x400
1276#endif
1277#ifndef AT_NO_AUTOMOUNT
1278# define AT_NO_AUTOMOUNT 0x800
1279#endif
1280#ifndef AT_EMPTY_PATH
1281# define AT_EMPTY_PATH 0x1000
1282#endif
1283
1284static const struct xlat at_flags[] = {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001285 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001286 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1287 { AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" },
1288 { AT_NO_AUTOMOUNT, "AT_NO_AUTOMOUNT" },
1289 { AT_EMPTY_PATH, "AT_EMPTY_PATH" },
1290 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001291};
1292
1293int
1294sys_newfstatat(struct tcb *tcp)
1295{
1296 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001297 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001298 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001299 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001300 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001301#ifdef POWERPC64
1302 if (current_personality == 0)
1303 printstat(tcp, tcp->u_arg[2]);
1304 else
1305 printstat64(tcp, tcp->u_arg[2]);
1306#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001307 printstat64(tcp, tcp->u_arg[2]);
1308#else
1309 printstat(tcp, tcp->u_arg[2]);
1310#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001311 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001312 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001313 }
1314 return 0;
1315}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001316
Denys Vlasenko84703742012-02-25 02:38:52 +01001317#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001318int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001319sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001320{
1321 if (entering(tcp)) {
1322 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001323 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001324 } else {
1325 printoldstat(tcp, tcp->u_arg[1]);
1326 }
1327 return 0;
1328}
Denys Vlasenko84703742012-02-25 02:38:52 +01001329#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001330
John Hughes70623be2001-03-08 13:59:00 +00001331#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001332int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001333sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001334{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001335 if (entering(tcp)) {
1336 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001337 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001338 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001339 printstat(tcp, tcp->u_arg[1]);
1340 }
1341 return 0;
1342}
John Hughesb8c9f772001-03-07 16:53:07 +00001343#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001344
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001345int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001346sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001347{
1348#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001349 if (entering(tcp)) {
1350 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001351 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001352 } else {
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001353 printstat64(tcp, tcp->u_arg[1]);
1354 }
1355 return 0;
1356#else
1357 return printargs(tcp);
1358#endif
1359}
1360
Denys Vlasenko84703742012-02-25 02:38:52 +01001361#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001362int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001363sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001364{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001365 if (entering(tcp)) {
1366 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001367 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001368 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001369 printoldstat(tcp, tcp->u_arg[1]);
1370 }
1371 return 0;
1372}
Denys Vlasenko84703742012-02-25 02:38:52 +01001373#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001374
John Hughes70623be2001-03-08 13:59:00 +00001375#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001376int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001377sys_lstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001378{
1379 if (entering(tcp)) {
1380 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001381 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001382 } else {
1383 printstat(tcp, tcp->u_arg[1]);
1384 }
1385 return 0;
1386}
John Hughesb8c9f772001-03-07 16:53:07 +00001387#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001388
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001389int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001390sys_lstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001391{
1392#ifdef HAVE_STAT64
1393 if (entering(tcp)) {
1394 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001395 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001396 } else {
1397 printstat64(tcp, tcp->u_arg[1]);
1398 }
1399 return 0;
1400#else
1401 return printargs(tcp);
1402#endif
1403}
1404
Denys Vlasenko84703742012-02-25 02:38:52 +01001405#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001406int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001407sys_oldlstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001408{
1409 if (entering(tcp)) {
1410 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001411 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001412 } else {
1413 printoldstat(tcp, tcp->u_arg[1]);
1414 }
1415 return 0;
1416}
Denys Vlasenko84703742012-02-25 02:38:52 +01001417#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001418
Denys Vlasenko9472a272013-02-12 11:43:46 +01001419#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001420
1421int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001422sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001423{
1424 if (entering(tcp)) {
1425 tprintf("%ld, ", tcp->u_arg[0]);
1426 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001427 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001428 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001429# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001430 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001431 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001432 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001433# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001434 printstat(tcp, tcp->u_arg[2]);
1435 }
1436 return 0;
1437}
1438
1439int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001440sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001441{
1442 if (entering(tcp))
1443 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1444 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001445# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001446 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001447 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001448 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001449# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001450 printstat(tcp, tcp->u_arg[2]);
1451 }
1452 return 0;
1453}
1454
1455int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001456sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001457{
1458 if (entering(tcp)) {
1459 tprintf("%ld, ", tcp->u_arg[0]);
1460 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001461 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001462 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001463# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001464 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001465 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001466 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001467# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001468 printstat(tcp, tcp->u_arg[2]);
1469 }
1470 return 0;
1471}
1472
1473int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001474sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001475{
1476 int mode = tcp->u_arg[2];
1477
1478 if (entering(tcp)) {
1479 tprintf("%ld, ", tcp->u_arg[0]);
1480 printpath(tcp, tcp->u_arg[1]);
1481 tprintf(", %s", sprintmode(mode));
1482 switch (mode & S_IFMT) {
1483 case S_IFCHR: case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001484 tprintf(", makedev(%lu, %lu)",
1485 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1486 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001487 break;
1488 default:
1489 break;
1490 }
1491 }
1492 return 0;
1493}
1494
Denys Vlasenko84703742012-02-25 02:38:52 +01001495# ifdef HAVE_SYS_ACL_H
Wichert Akkerman8829a551999-06-11 13:18:40 +00001496
Denys Vlasenko84703742012-02-25 02:38:52 +01001497# include <sys/acl.h>
Wichert Akkerman8829a551999-06-11 13:18:40 +00001498
Roland McGratha4d48532005-06-08 20:45:28 +00001499static const struct xlat aclcmds[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001500# ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001501 { SETACL, "SETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001502# endif
1503# ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001504 { GETACL, "GETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001505# endif
1506# ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001507 { GETACLCNT, "GETACLCNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001508# endif
1509# ifdef ACL_GET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001510 { ACL_GET, "ACL_GET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001511# endif
1512# ifdef ACL_SET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001513 { ACL_SET, "ACL_SET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001514# endif
1515# ifdef ACL_CNT
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001516 { ACL_CNT, "ACL_CNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001517# endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001518 { 0, NULL },
1519};
1520
1521int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001522sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001523{
1524 if (entering(tcp)) {
1525 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001526 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001527 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1528 tprintf(", %ld", tcp->u_arg[2]);
1529 /*
1530 * FIXME - dump out the list of aclent_t's pointed to
1531 * by "tcp->u_arg[3]" if it's not NULL.
1532 */
1533 if (tcp->u_arg[3])
1534 tprintf(", %#lx", tcp->u_arg[3]);
1535 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001536 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001537 }
1538 return 0;
1539}
1540
Wichert Akkerman8829a551999-06-11 13:18:40 +00001541int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001542sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001543{
1544 if (entering(tcp)) {
1545 tprintf("%ld, ", tcp->u_arg[0]);
1546 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1547 tprintf(", %ld", tcp->u_arg[2]);
1548 /*
1549 * FIXME - dump out the list of aclent_t's pointed to
1550 * by "tcp->u_arg[3]" if it's not NULL.
1551 */
1552 if (tcp->u_arg[3])
1553 tprintf(", %#lx", tcp->u_arg[3]);
1554 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001555 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001556 }
1557 return 0;
1558}
1559
Roland McGratha4d48532005-06-08 20:45:28 +00001560static const struct xlat aclipc[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001561# ifdef IPC_SHM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001562 { IPC_SHM, "IPC_SHM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001563# endif
1564# ifdef IPC_SEM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001565 { IPC_SEM, "IPC_SEM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001566# endif
1567# ifdef IPC_MSG
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001568 { IPC_MSG, "IPC_MSG" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001569# endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001570 { 0, NULL },
1571};
1572
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001573int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001574sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001575{
1576 if (entering(tcp)) {
1577 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1578 tprintf(", %#lx, ", tcp->u_arg[1]);
1579 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1580 tprintf(", %ld", tcp->u_arg[3]);
1581 /*
1582 * FIXME - dump out the list of aclent_t's pointed to
1583 * by "tcp->u_arg[4]" if it's not NULL.
1584 */
1585 if (tcp->u_arg[4])
1586 tprintf(", %#lx", tcp->u_arg[4]);
1587 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001588 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001589 }
1590 return 0;
1591}
1592
Denys Vlasenko84703742012-02-25 02:38:52 +01001593# endif /* HAVE_SYS_ACL_H */
Wichert Akkerman8829a551999-06-11 13:18:40 +00001594
Denys Vlasenko9472a272013-02-12 11:43:46 +01001595#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001596
Roland McGrathd9f816f2004-09-04 03:39:20 +00001597static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001598 { 0x73757245, "CODA_SUPER_MAGIC" },
1599 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1600 { 0x1373, "DEVFS_SUPER_MAGIC" },
1601 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1602 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001603 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1604 { 0xef53, "EXT2_SUPER_MAGIC" },
1605 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001606 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001607 { 0x9660, "ISOFS_SUPER_MAGIC" },
1608 { 0x137f, "MINIX_SUPER_MAGIC" },
1609 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001610 { 0x2468, "MINIX2_SUPER_MAGIC" },
1611 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001612 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001613 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001614 { 0x6969, "NFS_SUPER_MAGIC" },
1615 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001616 { 0x002f, "QNX4_SUPER_MAGIC" },
1617 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1618 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1619 { 0x517b, "SMB_SUPER_MAGIC" },
1620 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1621 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1622 { 0x00011954, "UFS_MAGIC" },
1623 { 0x54190100, "UFS_CIGAM" },
1624 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001625 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001626 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001627 { 0, NULL },
1628};
1629
Roland McGrathf9c49b22004-10-06 22:11:54 +00001630static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001631sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001632{
1633 static char buf[32];
Roland McGrathf9c49b22004-10-06 22:11:54 +00001634 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001635
1636 s = xlookup(fsmagic, magic);
1637 if (s) {
1638 sprintf(buf, "\"%s\"", s);
1639 return buf;
1640 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001641 sprintf(buf, "%#x", magic);
1642 return buf;
1643}
1644
1645static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001646printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001647{
1648 struct statfs statbuf;
1649
1650 if (syserror(tcp) || !verbose(tcp)) {
1651 tprintf("%#lx", addr);
1652 return;
1653 }
1654 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001655 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001656 return;
1657 }
1658#ifdef ALPHA
1659
1660 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1661 sprintfstype(statbuf.f_type),
1662 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001663 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001664 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001665 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1666 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001667#else /* !ALPHA */
1668 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1669 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001670 (unsigned long)statbuf.f_bsize,
1671 (unsigned long)statbuf.f_blocks,
1672 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001673 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1674 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001675 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001676 (unsigned long)statbuf.f_ffree,
1677 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001678 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001679#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001680#ifdef _STATFS_F_FRSIZE
1681 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1682#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001683 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001684}
1685
1686int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001687sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001688{
1689 if (entering(tcp)) {
1690 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001691 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001692 } else {
1693 printstatfs(tcp, tcp->u_arg[1]);
1694 }
1695 return 0;
1696}
1697
1698int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001699sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001700{
1701 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001702 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001703 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001704 } else {
1705 printstatfs(tcp, tcp->u_arg[1]);
1706 }
1707 return 0;
1708}
1709
Denys Vlasenko84703742012-02-25 02:38:52 +01001710#if defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001711static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001712printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001713{
1714 struct statfs64 statbuf;
1715
1716 if (syserror(tcp) || !verbose(tcp)) {
1717 tprintf("%#lx", addr);
1718 return;
1719 }
1720 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001721 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001722 return;
1723 }
Roland McGrath08738432005-06-03 02:40:39 +00001724 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001725 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001726 (unsigned long long)statbuf.f_bsize,
1727 (unsigned long long)statbuf.f_blocks,
1728 (unsigned long long)statbuf.f_bfree);
1729 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1730 (unsigned long long)statbuf.f_bavail,
1731 (unsigned long long)statbuf.f_files,
1732 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001733 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1734 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001735#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001736 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001737#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001738#ifdef _STATFS_F_FLAGS
1739 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1740#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001741 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001742}
1743
Andreas Schwab7d558012012-01-17 18:14:22 +01001744struct compat_statfs64 {
1745 uint32_t f_type;
1746 uint32_t f_bsize;
1747 uint64_t f_blocks;
1748 uint64_t f_bfree;
1749 uint64_t f_bavail;
1750 uint64_t f_files;
1751 uint64_t f_ffree;
1752 fsid_t f_fsid;
1753 uint32_t f_namelen;
1754 uint32_t f_frsize;
1755 uint32_t f_flags;
1756 uint32_t f_spare[4];
1757}
1758#if defined(X86_64) || defined(IA64)
1759 __attribute__ ((packed, aligned(4)))
1760#endif
1761;
1762
1763static void
1764printcompat_statfs64(struct tcb *tcp, long addr)
1765{
1766 struct compat_statfs64 statbuf;
1767
1768 if (syserror(tcp) || !verbose(tcp)) {
1769 tprintf("%#lx", addr);
1770 return;
1771 }
1772 if (umove(tcp, addr, &statbuf) < 0) {
1773 tprints("{...}");
1774 return;
1775 }
1776 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1777 sprintfstype(statbuf.f_type),
1778 (unsigned long)statbuf.f_bsize,
1779 (unsigned long long)statbuf.f_blocks,
1780 (unsigned long long)statbuf.f_bfree);
1781 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1782 (unsigned long long)statbuf.f_bavail,
1783 (unsigned long long)statbuf.f_files,
1784 (unsigned long long)statbuf.f_ffree,
1785 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1786 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1787 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001788 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
Andreas Schwab7d558012012-01-17 18:14:22 +01001789}
1790
Roland McGrathab147c52003-07-17 09:03:02 +00001791int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001792sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001793{
1794 if (entering(tcp)) {
1795 printpath(tcp, tcp->u_arg[0]);
1796 tprintf(", %lu, ", tcp->u_arg[1]);
1797 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001798 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001799 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001800 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1801 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001802 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001803 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001804 }
1805 return 0;
1806}
1807
1808int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001809sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001810{
1811 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001812 printfd(tcp, tcp->u_arg[0]);
1813 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001814 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001815 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001816 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001817 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1818 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001819 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001820 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001821 }
1822 return 0;
1823}
1824#endif
1825
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001826#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001827int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001828osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001829{
1830 if (entering(tcp)) {
1831 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001832 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001833 } else {
1834 printstatfs(tcp, tcp->u_arg[1]);
1835 tprintf(", %lu", tcp->u_arg[2]);
1836 }
1837 return 0;
1838}
1839
1840int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001841osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001842{
1843 if (entering(tcp)) {
1844 tprintf("%lu, ", tcp->u_arg[0]);
1845 } else {
1846 printstatfs(tcp, tcp->u_arg[1]);
1847 tprintf(", %lu", tcp->u_arg[2]);
1848 }
1849 return 0;
1850}
Denys Vlasenko84703742012-02-25 02:38:52 +01001851#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001852
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001853/* directory */
1854int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001855sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001856{
1857 if (entering(tcp)) {
1858 printpath(tcp, tcp->u_arg[0]);
1859 }
1860 return 0;
1861}
1862
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001863static int
1864decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001865{
1866 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001867 printpath(tcp, tcp->u_arg[offset]);
1868 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001869 }
1870 return 0;
1871}
1872
1873int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001874sys_mkdir(struct tcb *tcp)
1875{
1876 return decode_mkdir(tcp, 0);
1877}
1878
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001879int
1880sys_mkdirat(struct tcb *tcp)
1881{
1882 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001883 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001884 return decode_mkdir(tcp, 1);
1885}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001886
1887int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001888sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001889{
1890 if (entering(tcp)) {
1891 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001892 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001893 printpath(tcp, tcp->u_arg[1]);
1894 }
1895 return 0;
1896}
1897
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001898int
1899sys_linkat(struct tcb *tcp)
1900{
1901 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001902 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001903 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001904 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001905 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001906 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001907 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001908 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001909 }
1910 return 0;
1911}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001912
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001913int
1914sys_unlinkat(struct tcb *tcp)
1915{
1916 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001917 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001918 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001919 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001920 printflags(at_flags, tcp->u_arg[2], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001921 }
1922 return 0;
1923}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001924
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001925int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001926sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001927{
1928 if (entering(tcp)) {
1929 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001930 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001931 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001932 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001933 }
1934 return 0;
1935}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001936
1937static int
1938decode_readlink(struct tcb *tcp, int offset)
1939{
1940 if (entering(tcp)) {
1941 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001942 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001943 } else {
1944 if (syserror(tcp))
1945 tprintf("%#lx", tcp->u_arg[offset + 1]);
1946 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001947 /* Used to use printpathn(), but readlink
1948 * neither includes NUL in the returned count,
1949 * nor actually writes it into memory.
1950 * printpathn() would decide on printing
1951 * "..." continuation based on garbage
1952 * past return buffer's end.
1953 */
1954 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001955 tprintf(", %lu", tcp->u_arg[offset + 2]);
1956 }
1957 return 0;
1958}
1959
1960int
1961sys_readlink(struct tcb *tcp)
1962{
1963 return decode_readlink(tcp, 0);
1964}
1965
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001966int
1967sys_readlinkat(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 return decode_readlink(tcp, 1);
1972}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001973
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001974int
1975sys_renameat(struct tcb *tcp)
1976{
1977 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001978 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001979 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001980 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001981 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001982 printpath(tcp, tcp->u_arg[3]);
1983 }
1984 return 0;
1985}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001986
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001987int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001988sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001989{
1990 if (entering(tcp)) {
1991 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001992 printuid(", ", tcp->u_arg[1]);
1993 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001994 }
1995 return 0;
1996}
1997
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001998int
1999sys_fchownat(struct tcb *tcp)
2000{
2001 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002002 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002003 printpath(tcp, tcp->u_arg[1]);
2004 printuid(", ", tcp->u_arg[2]);
2005 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002006 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00002007 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002008 }
2009 return 0;
2010}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002011
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002012int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002013sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002014{
2015 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002016 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002017 printuid(", ", tcp->u_arg[1]);
2018 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002019 }
2020 return 0;
2021}
2022
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002023static int
2024decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002025{
2026 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002027 printpath(tcp, tcp->u_arg[offset]);
2028 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002029 }
2030 return 0;
2031}
2032
2033int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002034sys_chmod(struct tcb *tcp)
2035{
2036 return decode_chmod(tcp, 0);
2037}
2038
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002039int
2040sys_fchmodat(struct tcb *tcp)
2041{
2042 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002043 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002044 return decode_chmod(tcp, 1);
2045}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002046
2047int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002048sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002049{
2050 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002051 printfd(tcp, tcp->u_arg[0]);
2052 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002053 }
2054 return 0;
2055}
2056
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002057#ifdef ALPHA
2058int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002059sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002060{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002061 if (entering(tcp)) {
2062 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002063 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002064 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2065 }
2066 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002067}
2068#endif
2069
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002070static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002071decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002072{
2073 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002074 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002075 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002076 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002077 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00002078 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002079 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00002080 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2081 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002082 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002083 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002084 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00002085 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002086 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00002087 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002088 }
2089 return 0;
2090}
2091
2092int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002093sys_utimes(struct tcb *tcp)
2094{
Roland McGrath6afc5652007-07-24 01:57:11 +00002095 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002096}
2097
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002098int
2099sys_futimesat(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 return decode_utimes(tcp, 1, 0);
2104}
2105
2106int
2107sys_utimensat(struct tcb *tcp)
2108{
2109 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002110 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002111 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002112 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00002113 printflags(at_flags, tcp->u_arg[3], "AT_???");
Roland McGrath6afc5652007-07-24 01:57:11 +00002114 }
2115 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002116}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002117
2118int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002119sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002120{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002121 union {
2122 long utl[2];
2123 int uti[2];
Denys Vlasenko751acb32013-02-08 15:34:46 +01002124 long paranoia_for_huge_wordsize[4];
Roland McGrath7e9817c2007-07-05 20:31:58 +00002125 } u;
Denys Vlasenko751acb32013-02-08 15:34:46 +01002126 unsigned wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002127
2128 if (entering(tcp)) {
2129 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002130 tprints(", ");
Denys Vlasenko751acb32013-02-08 15:34:46 +01002131
2132 wordsize = current_wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002133 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002134 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002135 else if (!verbose(tcp))
2136 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002137 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002138 tprints("[?, ?]");
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002139 else if (wordsize == sizeof u.utl[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002140 tprintf("[%s,", sprinttime(u.utl[0]));
2141 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002142 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002143 else if (wordsize == sizeof u.uti[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002144 tprintf("[%s,", sprinttime(u.uti[0]));
2145 tprintf(" %s]", sprinttime(u.uti[1]));
2146 }
2147 else
Denys Vlasenko751acb32013-02-08 15:34:46 +01002148 tprintf("<decode error: unsupported wordsize %d>",
2149 wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002150 }
2151 return 0;
2152}
2153
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002154static int
2155decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002156{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002157 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002158
2159 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002160 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002161 tprintf(", %s", sprintmode(mode));
2162 switch (mode & S_IFMT) {
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002163 case S_IFCHR:
2164 case S_IFBLK:
Denys Vlasenko9472a272013-02-12 11:43:46 +01002165#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002166 if (current_personality == 1)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002167 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002168 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2169 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002170 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002171#endif
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002172 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002173 (unsigned long) major(tcp->u_arg[offset + 2]),
2174 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002175 break;
2176 default:
2177 break;
2178 }
2179 }
2180 return 0;
2181}
2182
2183int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002184sys_mknod(struct tcb *tcp)
2185{
2186 return decode_mknod(tcp, 0);
2187}
2188
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002189int
2190sys_mknodat(struct tcb *tcp)
2191{
2192 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002193 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002194 return decode_mknod(tcp, 1);
2195}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002196
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002197static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002198printdir(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002199{
2200 struct dirent d;
2201
2202 if (!verbose(tcp)) {
2203 tprintf("%#lx", addr);
2204 return;
2205 }
2206 if (umove(tcp, addr, &d) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002207 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002208 return;
2209 }
2210 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002211 tprints("d_name=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002212 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002213 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002214}
2215
2216int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002217sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002218{
2219 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002220 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002221 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002222 } else {
2223 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2224 tprintf("%#lx", tcp->u_arg[1]);
2225 else
2226 printdir(tcp, tcp->u_arg[1]);
2227 /* Not much point in printing this out, it is always 1. */
2228 if (tcp->u_arg[2] != 1)
2229 tprintf(", %lu", tcp->u_arg[2]);
2230 }
2231 return 0;
2232}
2233
Roland McGratha4d48532005-06-08 20:45:28 +00002234static const struct xlat direnttypes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002235 { DT_UNKNOWN, "DT_UNKNOWN" },
2236 { DT_FIFO, "DT_FIFO" },
2237 { DT_CHR, "DT_CHR" },
2238 { DT_DIR, "DT_DIR" },
2239 { DT_BLK, "DT_BLK" },
2240 { DT_REG, "DT_REG" },
2241 { DT_LNK, "DT_LNK" },
2242 { DT_SOCK, "DT_SOCK" },
2243 { DT_WHT, "DT_WHT" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002244 { 0, NULL },
2245};
2246
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002247int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002248sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002249{
2250 int i, len, dents = 0;
2251 char *buf;
2252
2253 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002254 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002255 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002256 return 0;
2257 }
2258 if (syserror(tcp) || !verbose(tcp)) {
2259 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2260 return 0;
2261 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002262 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002263 /* Beware of insanely large or negative values in tcp->u_rval */
2264 if (tcp->u_rval > 1024*1024)
2265 len = 1024*1024;
2266 if (tcp->u_rval < 0)
2267 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002268 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002269 if (len && !buf)
2270 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002271 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002272 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002273 free(buf);
2274 return 0;
2275 }
2276 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002277 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002278 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002279 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002280 if (!abbrev(tcp)) {
2281 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2282 i ? " " : "", d->d_ino, d->d_off);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002283 tprintf("d_reclen=%u, d_name=\"%s\", d_type=",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002284 d->d_reclen, d->d_name);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002285 printxval(direnttypes, buf[i + d->d_reclen - 1], "DT_???");
2286 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002287 }
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002288 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002289 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002290 break;
2291 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002292 i += d->d_reclen;
2293 dents++;
2294 }
2295 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002296 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002297 else
2298 tprintf("/* %u entries */", dents);
2299 tprintf(", %lu", tcp->u_arg[2]);
2300 free(buf);
2301 return 0;
2302}
2303
John Hughesbdf48f52001-03-06 15:08:09 +00002304#if _LFS64_LARGEFILE
2305int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002306sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002307{
2308 int i, len, dents = 0;
2309 char *buf;
2310
2311 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002312 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002313 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002314 return 0;
2315 }
2316 if (syserror(tcp) || !verbose(tcp)) {
2317 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2318 return 0;
2319 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002320
John Hughesbdf48f52001-03-06 15:08:09 +00002321 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002322 /* Beware of insanely large or negative tcp->u_rval */
2323 if (tcp->u_rval > 1024*1024)
2324 len = 1024*1024;
2325 if (tcp->u_rval < 0)
2326 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002327 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002328 if (len && !buf)
2329 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002330
John Hughesbdf48f52001-03-06 15:08:09 +00002331 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002332 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002333 free(buf);
2334 return 0;
2335 }
2336 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002337 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002338 for (i = 0; i < len;) {
2339 struct dirent64 *d = (struct dirent64 *) &buf[i];
John Hughesbdf48f52001-03-06 15:08:09 +00002340 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002341 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002342 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002343 d->d_ino,
2344 d->d_off);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002345 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002346 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002347 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002348 tprintf("d_reclen=%u, d_name=\"%s\"}",
2349 d->d_reclen, d->d_name);
2350 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002351 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002352 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002353 break;
2354 }
John Hughesbdf48f52001-03-06 15:08:09 +00002355 i += d->d_reclen;
2356 dents++;
2357 }
2358 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002359 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002360 else
2361 tprintf("/* %u entries */", dents);
2362 tprintf(", %lu", tcp->u_arg[2]);
2363 free(buf);
2364 return 0;
2365}
2366#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002367
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002368int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002369sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002370{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002371 if (exiting(tcp)) {
2372 if (syserror(tcp))
2373 tprintf("%#lx", tcp->u_arg[0]);
2374 else
2375 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2376 tprintf(", %lu", tcp->u_arg[1]);
2377 }
2378 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002379}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002380
2381#ifdef HAVE_SYS_ASYNCH_H
2382
2383int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002384sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002385{
2386 struct aio_result_t res;
2387
2388 if (entering(tcp)) {
2389 tprintf("%lu, ", tcp->u_arg[0]);
2390 } else {
2391 if (syserror(tcp))
2392 tprintf("%#lx", tcp->u_arg[1]);
2393 else
2394 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2395 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2396 printxval(whence, tcp->u_arg[4], "L_???");
2397 if (syserror(tcp) || tcp->u_arg[5] == 0
2398 || umove(tcp, tcp->u_arg[5], &res) < 0)
2399 tprintf(", %#lx", tcp->u_arg[5]);
2400 else
2401 tprintf(", {aio_return %d aio_errno %d}",
2402 res.aio_return, res.aio_errno);
2403 }
2404 return 0;
2405}
2406
2407int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002408sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002409{
2410 struct aio_result_t res;
2411
2412 if (entering(tcp)) {
2413 tprintf("%lu, ", tcp->u_arg[0]);
2414 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2415 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2416 printxval(whence, tcp->u_arg[4], "L_???");
2417 }
2418 else {
2419 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002420 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002421 else if (syserror(tcp)
2422 || umove(tcp, tcp->u_arg[5], &res) < 0)
2423 tprintf(", %#lx", tcp->u_arg[5]);
2424 else
2425 tprintf(", {aio_return %d aio_errno %d}",
2426 res.aio_return, res.aio_errno);
2427 }
2428 return 0;
2429}
2430
2431int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002432sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002433{
2434 if (entering(tcp))
2435 printtv(tcp, tcp->u_arg[0]);
2436 return 0;
2437}
2438
2439int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002440sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002441{
2442 struct aio_result_t res;
2443
2444 if (exiting(tcp)) {
2445 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002446 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002447 else if (syserror(tcp)
2448 || umove(tcp, tcp->u_arg[0], &res) < 0)
2449 tprintf("%#lx", tcp->u_arg[0]);
2450 else
2451 tprintf("{aio_return %d aio_errno %d}",
2452 res.aio_return, res.aio_errno);
2453 }
2454 return 0;
2455}
2456
2457#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002458
Roland McGratha4d48532005-06-08 20:45:28 +00002459static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002460#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002461 { XATTR_CREATE, "XATTR_CREATE" },
2462 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002463#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002464 { 0, NULL }
2465};
2466
Roland McGrath3292e222004-08-31 06:30:48 +00002467static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002468print_xattr_val(struct tcb *tcp, int failed,
2469 unsigned long arg,
2470 unsigned long insize,
2471 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002472{
Dmitry V. Levin1f215132012-12-07 21:38:52 +00002473 if (insize == 0)
2474 failed = 1;
Denys Vlasenko1d632462009-04-14 12:51:00 +00002475 if (!failed) {
2476 unsigned long capacity = 4 * size + 1;
2477 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2478 if (buf == NULL || /* probably a bogus size argument */
2479 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2480 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002481 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002482 else {
2483 unsigned char *out = buf;
2484 unsigned char *in = &buf[3 * size];
2485 size_t i;
2486 for (i = 0; i < size; ++i) {
2487 if (isprint(in[i]))
2488 *out++ = in[i];
2489 else {
2490#define tohex(n) "0123456789abcdef"[n]
2491 *out++ = '\\';
2492 *out++ = 'x';
2493 *out++ = tohex(in[i] / 16);
2494 *out++ = tohex(in[i] % 16);
2495 }
2496 }
2497 /* Don't print terminating NUL if there is one. */
2498 if (i > 0 && in[i - 1] == '\0')
2499 out -= 4;
2500 *out = '\0';
2501 tprintf(", \"%s\", %ld", buf, insize);
2502 }
2503 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002504 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002505 if (failed)
2506 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002507}
2508
Roland McGrath186c5ac2002-12-15 23:58:23 +00002509int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002510sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002511{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002512 if (entering(tcp)) {
2513 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002514 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002515 printstr(tcp, tcp->u_arg[1], -1);
2516 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002517 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002518 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2519 }
2520 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002521}
2522
2523int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002524sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002525{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002526 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002527 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002528 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002529 printstr(tcp, tcp->u_arg[1], -1);
2530 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002531 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002532 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2533 }
2534 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002535}
2536
2537int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002538sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002539{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002540 if (entering(tcp)) {
2541 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002542 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002543 printstr(tcp, tcp->u_arg[1], -1);
2544 } else {
2545 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2546 tcp->u_rval);
2547 }
2548 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002549}
2550
2551int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002552sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002553{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002554 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002555 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002556 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002557 printstr(tcp, tcp->u_arg[1], -1);
2558 } else {
2559 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2560 tcp->u_rval);
2561 }
2562 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002563}
2564
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002565static void
2566print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2567{
2568 if (syserror(tcp)) {
2569 tprintf("%#lx", addr);
2570 } else {
2571 if (!addr) {
2572 tprints("NULL");
2573 } else {
2574 unsigned long len =
2575 (size < tcp->u_rval) ? size : tcp->u_rval;
2576 printstr(tcp, addr, len);
2577 }
2578 }
2579 tprintf(", %lu", size);
2580}
2581
Roland McGrath186c5ac2002-12-15 23:58:23 +00002582int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002583sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002584{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002585 if (entering(tcp)) {
2586 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002587 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002588 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002589 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002590 }
2591 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002592}
2593
2594int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002595sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002596{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002597 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002598 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002599 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002600 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002601 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002602 }
2603 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002604}
2605
2606int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002607sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002608{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002609 if (entering(tcp)) {
2610 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002611 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002612 printstr(tcp, tcp->u_arg[1], -1);
2613 }
2614 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002615}
2616
2617int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002618sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002619{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002620 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002621 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002622 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002623 printstr(tcp, tcp->u_arg[1], -1);
2624 }
2625 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002626}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002627
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002628static const struct xlat advise[] = {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002629 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2630 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2631 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2632 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2633 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2634 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2635 { 0, NULL }
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002636};
2637
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002638int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002639sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002640{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002641 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002642 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002643 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002644 argn = printllval(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002645 tprintf(", %ld, ", tcp->u_arg[argn++]);
2646 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002647 }
2648 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002649}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002650
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002651int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002652sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002653{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002654 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002655 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002656 printfd(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002657#if defined ARM || defined POWERPC
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002658 argn = printllval(tcp, ", %lld, ", 2);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002659#else
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002660 argn = printllval(tcp, ", %lld, ", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002661#endif
2662 argn = printllval(tcp, "%lld, ", argn);
2663#if defined ARM || defined POWERPC
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002664 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002665#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002666 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002667#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002668 }
2669 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002670}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002671
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002672static const struct xlat inotify_modes[] = {
Dmitry V. Levind475c062011-03-03 01:02:41 +00002673 { 0x00000001, "IN_ACCESS" },
2674 { 0x00000002, "IN_MODIFY" },
2675 { 0x00000004, "IN_ATTRIB" },
2676 { 0x00000008, "IN_CLOSE_WRITE"},
2677 { 0x00000010, "IN_CLOSE_NOWRITE"},
2678 { 0x00000020, "IN_OPEN" },
2679 { 0x00000040, "IN_MOVED_FROM" },
2680 { 0x00000080, "IN_MOVED_TO" },
2681 { 0x00000100, "IN_CREATE" },
2682 { 0x00000200, "IN_DELETE" },
2683 { 0x00000400, "IN_DELETE_SELF"},
2684 { 0x00000800, "IN_MOVE_SELF" },
2685 { 0x00002000, "IN_UNMOUNT" },
2686 { 0x00004000, "IN_Q_OVERFLOW" },
2687 { 0x00008000, "IN_IGNORED" },
2688 { 0x01000000, "IN_ONLYDIR" },
2689 { 0x02000000, "IN_DONT_FOLLOW"},
2690 { 0x20000000, "IN_MASK_ADD" },
2691 { 0x40000000, "IN_ISDIR" },
2692 { 0x80000000, "IN_ONESHOT" },
2693 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002694};
2695
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002696static const struct xlat inotify_init_flags[] = {
2697 { 0x00000800, "IN_NONBLOCK" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002698 { 0x00080000, "IN_CLOEXEC" },
2699 { 0, NULL }
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002700};
2701
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002702int
2703sys_inotify_add_watch(struct tcb *tcp)
2704{
2705 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002706 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002707 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002708 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002709 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002710 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2711 }
2712 return 0;
2713}
2714
2715int
2716sys_inotify_rm_watch(struct tcb *tcp)
2717{
2718 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002719 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levinab1a70c2012-03-11 15:33:34 +00002720 tprintf(", %d", (int) tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002721 }
2722 return 0;
2723}
Roland McGrath96a96612008-05-20 04:56:18 +00002724
2725int
Mark Wielaardbab89402010-03-21 14:41:26 +01002726sys_inotify_init1(struct tcb *tcp)
2727{
2728 if (entering(tcp))
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002729 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
Mark Wielaardbab89402010-03-21 14:41:26 +01002730 return 0;
2731}
2732
2733int
Roland McGrath96a96612008-05-20 04:56:18 +00002734sys_fallocate(struct tcb *tcp)
2735{
2736 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002737 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002738 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002739 tprintf(", %#lo, ", tcp->u_arg[1]); /* mode */
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002740 argn = printllval(tcp, "%llu, ", 2); /* offset */
2741 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002742 }
2743 return 0;
2744}
Dmitry V. Levin88293652012-03-09 21:02:19 +00002745
Dmitry V. Levinad0c01e2012-03-15 00:52:22 +00002746#ifndef SWAP_FLAG_PREFER
2747# define SWAP_FLAG_PREFER 0x8000
2748#endif
2749#ifndef SWAP_FLAG_DISCARD
2750# define SWAP_FLAG_DISCARD 0x10000
2751#endif
Dmitry V. Levin88293652012-03-09 21:02:19 +00002752static const struct xlat swap_flags[] = {
2753 { SWAP_FLAG_PREFER, "SWAP_FLAG_PREFER" },
2754 { SWAP_FLAG_DISCARD, "SWAP_FLAG_DISCARD" },
2755 { 0, NULL }
2756};
2757
2758int
2759sys_swapon(struct tcb *tcp)
2760{
2761 if (entering(tcp)) {
2762 int flags = tcp->u_arg[1];
2763 printpath(tcp, tcp->u_arg[0]);
2764 tprints(", ");
2765 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2766 "SWAP_FLAG_???");
2767 if (flags & SWAP_FLAG_PREFER)
2768 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);
2769 }
2770 return 0;
2771}
H.J. Lu085e4282012-04-17 11:05:04 -07002772
2773#ifdef X32
2774# undef stat64
2775# undef sys_fstat64
2776# undef sys_stat64
2777
2778static void
2779realprintstat64(struct tcb *tcp, long addr)
2780{
2781 struct stat64 statbuf;
2782
2783 if (!addr) {
2784 tprints("NULL");
2785 return;
2786 }
2787 if (syserror(tcp) || !verbose(tcp)) {
2788 tprintf("%#lx", addr);
2789 return;
2790 }
2791
2792 if (umove(tcp, addr, &statbuf) < 0) {
2793 tprints("{...}");
2794 return;
2795 }
2796
2797 if (!abbrev(tcp)) {
2798 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
2799 (unsigned long) major(statbuf.st_dev),
2800 (unsigned long) minor(statbuf.st_dev),
2801 (unsigned long long) statbuf.st_ino,
2802 sprintmode(statbuf.st_mode));
2803 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
2804 (unsigned long) statbuf.st_nlink,
2805 (unsigned long) statbuf.st_uid,
2806 (unsigned long) statbuf.st_gid);
2807 tprintf("st_blksize=%lu, ",
2808 (unsigned long) statbuf.st_blksize);
2809 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
2810 }
2811 else
2812 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
2813 switch (statbuf.st_mode & S_IFMT) {
2814 case S_IFCHR: case S_IFBLK:
2815 tprintf("st_rdev=makedev(%lu, %lu), ",
2816 (unsigned long) major(statbuf.st_rdev),
2817 (unsigned long) minor(statbuf.st_rdev));
2818 break;
2819 default:
2820 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
2821 break;
2822 }
2823 if (!abbrev(tcp)) {
2824 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
2825 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
2826 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
2827 tprints("}");
2828 }
2829 else
2830 tprints("...}");
2831}
2832
2833int
2834sys_fstat64(struct tcb *tcp)
2835{
2836 if (entering(tcp)) {
2837 printfd(tcp, tcp->u_arg[0]);
2838 tprints(", ");
2839 } else {
2840 realprintstat64(tcp, tcp->u_arg[1]);
2841 }
2842 return 0;
2843}
2844
2845int
2846sys_stat64(struct tcb *tcp)
2847{
2848 if (entering(tcp)) {
2849 printpath(tcp, tcp->u_arg[0]);
2850 tprints(", ");
2851 } else {
2852 realprintstat64(tcp, tcp->u_arg[1]);
2853 }
2854 return 0;
2855}
2856#endif