blob: bea531211cef2b6b3a28d6baf1c914ecacc81813 [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
Denys Vlasenko86738a22013-02-17 14:31:55 +0100519const struct xlat whence_codes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520 { SEEK_SET, "SEEK_SET" },
521 { SEEK_CUR, "SEEK_CUR" },
522 { SEEK_END, "SEEK_END" },
Denys Vlasenko86738a22013-02-17 14:31:55 +0100523#ifdef SEEK_DATA
524 { SEEK_DATA, "SEEK_DATA" },
525#endif
526#ifdef SEEK_HOLE
527 { SEEK_HOLE, "SEEK_HOLE" },
528#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000529 { 0, NULL },
530};
531
Denys Vlasenko386b8712013-02-17 01:38:14 +0100532/* Linux kernel has exactly one version of lseek:
533 * fs/read_write.c::SYSCALL_DEFINE3(lseek, unsigned, fd, off_t, offset, unsigned, origin)
534 * In kernel, off_t is always the same as (kernel's) long
535 * (see include/uapi/asm-generic/posix_types.h),
536 * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument.
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100537 * Use test/x32_lseek.c to test lseek decoding.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100538 */
H.J. Luc933f272012-04-16 17:41:13 +0200539#if defined(LINUX_MIPSN32) || defined(X32)
Roland McGrath542c2c62008-05-20 01:11:56 +0000540int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000541sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000542{
543 long long offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100544 int whence;
Roland McGrath542c2c62008-05-20 01:11:56 +0000545
546 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300547 printfd(tcp, tcp->u_arg[0]);
Roland McGrath542c2c62008-05-20 01:11:56 +0000548 offset = tcp->ext_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100549 whence = tcp->u_arg[2];
550 if (whence == SEEK_SET)
551 tprintf(", %llu, ", offset);
Roland McGrath542c2c62008-05-20 01:11:56 +0000552 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100553 tprintf(", %lld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100554 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath542c2c62008-05-20 01:11:56 +0000555 }
H.J. Ludd0130b2012-04-16 12:16:45 +0200556 return RVAL_LUDECIMAL;
Roland McGrath542c2c62008-05-20 01:11:56 +0000557}
H.J. Ludd0130b2012-04-16 12:16:45 +0200558#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000559int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000560sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000561{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000562 off_t offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100563 int whence;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000564
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000565 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300566 printfd(tcp, tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000567 offset = tcp->u_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100568 whence = tcp->u_arg[2];
569 if (whence == SEEK_SET)
570 tprintf(", %lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000571 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100572 tprintf(", %ld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100573 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000574 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000575 return RVAL_UDECIMAL;
576}
John Hughes5a826b82001-03-07 13:21:24 +0000577#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000578
Denys Vlasenko386b8712013-02-17 01:38:14 +0100579/* llseek syscall takes explicitly two ulong arguments hi, lo,
580 * rather than one 64-bit argument for which LONG_LONG works
581 * appropriate for the native byte order.
582 *
583 * See kernel's fs/read_write.c::SYSCALL_DEFINE5(llseek, ...)
584 *
585 * hi,lo are "unsigned longs" and combined exactly this way in kernel:
586 * ((loff_t) hi << 32) | lo
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100587 * Note that for architectures with kernel's long wider than userspace long
Denys Vlasenko386b8712013-02-17 01:38:14 +0100588 * (such as x32), combining code will use *kernel's*, i.e. *wide* longs
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100589 * for hi and lo. We may need to use tcp->ext_arg[N]!
Denys Vlasenko386b8712013-02-17 01:38:14 +0100590 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000591int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000592sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000593{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000594 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300595 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000596 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300597 tprintf(", %llu, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100598 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300599 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000600 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300601 tprintf(", %lld, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100602 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300603 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000604 }
605 else {
Denys Vlasenko386b8712013-02-17 01:38:14 +0100606 long long off;
Denys Vlasenko1d632462009-04-14 12:51:00 +0000607 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
608 tprintf("%#lx, ", tcp->u_arg[3]);
609 else
610 tprintf("[%llu], ", off);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100611 printxval(whence_codes, tcp->u_arg[4], "SEEK_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000612 }
613 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000614}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000615
616int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000617sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000618{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000619 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100620 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300621 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +0200622 argn = printllval(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100623 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000624 }
625 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000626}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000627
John Hughes70623be2001-03-08 13:59:00 +0000628#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000629int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000630sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000631{
632 if (entering(tcp)) {
633 printpath(tcp, tcp->u_arg[0]);
634 tprintf(", %lu", tcp->u_arg[1]);
635 }
636 return 0;
637}
John Hughes5a826b82001-03-07 13:21:24 +0000638#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000639
John Hughes70623be2001-03-08 13:59:00 +0000640#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000641int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000642sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000643{
644 if (entering(tcp)) {
645 printpath(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100646 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000647 }
648 return 0;
649}
650#endif
651
John Hughes70623be2001-03-08 13:59:00 +0000652#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000653int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000654sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000655{
656 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300657 printfd(tcp, tcp->u_arg[0]);
658 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000659 }
660 return 0;
661}
John Hughes5a826b82001-03-07 13:21:24 +0000662#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000663
John Hughes70623be2001-03-08 13:59:00 +0000664#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000665int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000666sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000667{
668 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300669 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +0200670 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000671 }
672 return 0;
673}
674#endif
675
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000676/* several stats */
677
Roland McGrathd9f816f2004-09-04 03:39:20 +0000678static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000679 { S_IFREG, "S_IFREG" },
680 { S_IFSOCK, "S_IFSOCK" },
681 { S_IFIFO, "S_IFIFO" },
682 { S_IFLNK, "S_IFLNK" },
683 { S_IFDIR, "S_IFDIR" },
684 { S_IFBLK, "S_IFBLK" },
685 { S_IFCHR, "S_IFCHR" },
686 { 0, NULL },
687};
688
Roland McGrathf9c49b22004-10-06 22:11:54 +0000689static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000690sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000691{
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100692 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
693 + sizeof(int)*3
694 + /*paranoia:*/ 8];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000695 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000696
697 if ((mode & S_IFMT) == 0)
698 s = "";
699 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
700 sprintf(buf, "%#o", mode);
701 return buf;
702 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100703 s = buf + sprintf(buf, "%s%s%s%s", s,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000704 (mode & S_ISUID) ? "|S_ISUID" : "",
705 (mode & S_ISGID) ? "|S_ISGID" : "",
706 (mode & S_ISVTX) ? "|S_ISVTX" : "");
707 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
708 if (mode)
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100709 sprintf((char*)s, "|%#o", mode);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000710 s = (*buf == '|') ? buf + 1 : buf;
711 return *s ? s : "0";
712}
713
714static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000715sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000716{
717 struct tm *tmp;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100718 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000719
720 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000721 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000722 return buf;
723 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200724 tmp = localtime(&t);
725 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000726 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
727 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
728 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
729 else
730 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
731
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000732 return buf;
733}
734
Denys Vlasenko9472a272013-02-12 11:43:46 +0100735#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000736typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000737 int tv_sec;
738 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000739} timestruct_t;
740
741struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000742 unsigned st_dev;
743 int st_pad1[3]; /* network id */
744 unsigned st_ino;
745 unsigned st_mode;
746 unsigned st_nlink;
747 unsigned st_uid;
748 unsigned st_gid;
749 unsigned st_rdev;
750 int st_pad2[2];
751 int st_size;
752 int st_pad3; /* st_size, off_t expansion */
753 timestruct_t st_atime;
754 timestruct_t st_mtime;
755 timestruct_t st_ctime;
756 int st_blksize;
757 int st_blocks;
758 char st_fstype[16];
759 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000760};
761
762static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000763printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000764{
765 struct solstat statbuf;
766
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000767 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200768 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000769 return;
770 }
771 if (!abbrev(tcp)) {
772 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
773 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
774 (unsigned long) (statbuf.st_dev & 0x3ffff),
775 (unsigned long) statbuf.st_ino,
776 sprintmode(statbuf.st_mode));
777 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
778 (unsigned long) statbuf.st_nlink,
779 (unsigned long) statbuf.st_uid,
780 (unsigned long) statbuf.st_gid);
781 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
782 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
783 }
784 else
785 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
786 switch (statbuf.st_mode & S_IFMT) {
787 case S_IFCHR: case S_IFBLK:
788 tprintf("st_rdev=makedev(%lu, %lu), ",
789 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
790 (unsigned long) (statbuf.st_rdev & 0x3ffff));
791 break;
792 default:
793 tprintf("st_size=%u, ", statbuf.st_size);
794 break;
795 }
796 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000797 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
798 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
799 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000800 }
801 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200802 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000803}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000804
Denys Vlasenko9472a272013-02-12 11:43:46 +0100805# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000806static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000807printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000808{
809 struct stat_sparc64 statbuf;
810
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000811 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200812 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000813 return;
814 }
815
816 if (!abbrev(tcp)) {
817 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
818 (unsigned long) major(statbuf.st_dev),
819 (unsigned long) minor(statbuf.st_dev),
820 (unsigned long) statbuf.st_ino,
821 sprintmode(statbuf.st_mode));
822 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
823 (unsigned long) statbuf.st_nlink,
824 (unsigned long) statbuf.st_uid,
825 (unsigned long) statbuf.st_gid);
826 tprintf("st_blksize=%lu, ",
827 (unsigned long) statbuf.st_blksize);
828 tprintf("st_blocks=%lu, ",
829 (unsigned long) statbuf.st_blocks);
830 }
831 else
832 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
833 switch (statbuf.st_mode & S_IFMT) {
834 case S_IFCHR: case S_IFBLK:
835 tprintf("st_rdev=makedev(%lu, %lu), ",
836 (unsigned long) major(statbuf.st_rdev),
837 (unsigned long) minor(statbuf.st_rdev));
838 break;
839 default:
840 tprintf("st_size=%lu, ", statbuf.st_size);
841 break;
842 }
843 if (!abbrev(tcp)) {
844 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
845 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100846 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000847 }
848 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200849 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000850}
Denys Vlasenko9472a272013-02-12 11:43:46 +0100851# endif /* SPARC64 */
852#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000853
Denys Vlasenko84703742012-02-25 02:38:52 +0100854#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200855struct stat_powerpc32 {
856 unsigned int st_dev;
857 unsigned int st_ino;
858 unsigned int st_mode;
859 unsigned short st_nlink;
860 unsigned int st_uid;
861 unsigned int st_gid;
862 unsigned int st_rdev;
863 unsigned int st_size;
864 unsigned int st_blksize;
865 unsigned int st_blocks;
866 unsigned int st_atime;
867 unsigned int st_atime_nsec;
868 unsigned int st_mtime;
869 unsigned int st_mtime_nsec;
870 unsigned int st_ctime;
871 unsigned int st_ctime_nsec;
872 unsigned int __unused4;
873 unsigned int __unused5;
874};
875
876static void
877printstat_powerpc32(struct tcb *tcp, long addr)
878{
879 struct stat_powerpc32 statbuf;
880
881 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200882 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200883 return;
884 }
885
886 if (!abbrev(tcp)) {
887 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
888 major(statbuf.st_dev), minor(statbuf.st_dev),
889 statbuf.st_ino,
890 sprintmode(statbuf.st_mode));
891 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
892 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
893 tprintf("st_blksize=%u, ", statbuf.st_blksize);
894 tprintf("st_blocks=%u, ", statbuf.st_blocks);
895 }
896 else
897 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
898 switch (statbuf.st_mode & S_IFMT) {
899 case S_IFCHR: case S_IFBLK:
900 tprintf("st_rdev=makedev(%lu, %lu), ",
901 (unsigned long) major(statbuf.st_rdev),
902 (unsigned long) minor(statbuf.st_rdev));
903 break;
904 default:
905 tprintf("st_size=%u, ", statbuf.st_size);
906 break;
907 }
908 if (!abbrev(tcp)) {
909 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
910 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100911 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200912 }
913 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200914 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200915}
Denys Vlasenko84703742012-02-25 02:38:52 +0100916#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200917
Roland McGratha4d48532005-06-08 20:45:28 +0000918static const struct xlat fileflags[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000919 { 0, NULL },
920};
921
John Hughes70623be2001-03-08 13:59:00 +0000922#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000923static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000924realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000925{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000926 if (!abbrev(tcp)) {
927 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
928 (unsigned long) major(statbuf->st_dev),
929 (unsigned long) minor(statbuf->st_dev),
930 (unsigned long) statbuf->st_ino,
931 sprintmode(statbuf->st_mode));
932 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
933 (unsigned long) statbuf->st_nlink,
934 (unsigned long) statbuf->st_uid,
935 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000936#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000937 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
938#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000939#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000940 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
941#endif
942 }
943 else
944 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
945 switch (statbuf->st_mode & S_IFMT) {
946 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000947#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000948 tprintf("st_rdev=makedev(%lu, %lu), ",
949 (unsigned long) major(statbuf->st_rdev),
950 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000951#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000952 tprintf("st_size=makedev(%lu, %lu), ",
953 (unsigned long) major(statbuf->st_size),
954 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000955#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000956 break;
957 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000958 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000959 break;
960 }
961 if (!abbrev(tcp)) {
962 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
963 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
964 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000965#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200966 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000967 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000968#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000969#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000970 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
971#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000972#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000973 tprintf(", st_level=%ld", statbuf->st_level);
974#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000975#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000976 tprintf(", st_fstype=%.*s",
977 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
978#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000979#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000980 tprintf(", st_gen=%u", statbuf->st_gen);
981#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200982 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000983 }
984 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200985 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000986}
987
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000988static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000989printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000990{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000991 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000992
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000993 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200994 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000995 return;
996 }
997 if (syserror(tcp) || !verbose(tcp)) {
998 tprintf("%#lx", addr);
999 return;
1000 }
1001
Denys Vlasenko9472a272013-02-12 11:43:46 +01001002#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001003 if (current_personality == 1) {
1004 printstatsol(tcp, addr);
1005 return;
1006 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001007#ifdef SPARC64
1008 else if (current_personality == 2) {
1009 printstat_sparc64(tcp, addr);
1010 return;
1011 }
1012#endif
Denys Vlasenko9472a272013-02-12 11:43:46 +01001013#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001014
Denys Vlasenko84703742012-02-25 02:38:52 +01001015#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +02001016 if (current_personality == 1) {
1017 printstat_powerpc32(tcp, addr);
1018 return;
1019 }
1020#endif
1021
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001022 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001023 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001024 return;
1025 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001026
1027 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001028}
John Hughes70623be2001-03-08 13:59:00 +00001029#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001030
Denys Vlasenko84703742012-02-25 02:38:52 +01001031#if !defined HAVE_STAT64 && defined X86_64
Roland McGrathe6d0f712007-08-07 01:22:49 +00001032/*
1033 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1034 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1035 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1036 * __GNUC__ is needed for the required __attribute__ below.
1037 */
1038struct stat64 {
1039 unsigned long long st_dev;
1040 unsigned char __pad0[4];
1041 unsigned int __st_ino;
1042 unsigned int st_mode;
1043 unsigned int st_nlink;
1044 unsigned int st_uid;
1045 unsigned int st_gid;
1046 unsigned long long st_rdev;
1047 unsigned char __pad3[4];
1048 long long st_size;
1049 unsigned int st_blksize;
1050 unsigned long long st_blocks;
1051 unsigned int st_atime;
1052 unsigned int st_atime_nsec;
1053 unsigned int st_mtime;
1054 unsigned int st_mtime_nsec;
1055 unsigned int st_ctime;
1056 unsigned int st_ctime_nsec;
1057 unsigned long long st_ino;
1058} __attribute__((packed));
1059# define HAVE_STAT64 1
1060# define STAT64_SIZE 96
1061#endif
1062
Wichert Akkermanc7926982000-04-10 22:22:31 +00001063#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001064static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001065printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001066{
1067 struct stat64 statbuf;
1068
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001069#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001070 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1071#endif
1072
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001073 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001074 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001075 return;
1076 }
1077 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001078 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001079 return;
1080 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001081
Denys Vlasenko9472a272013-02-12 11:43:46 +01001082#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001083 if (current_personality == 1) {
1084 printstatsol(tcp, addr);
1085 return;
1086 }
1087# ifdef SPARC64
1088 else if (current_personality == 2) {
1089 printstat_sparc64(tcp, addr);
1090 return;
1091 }
1092# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +01001093#endif /* SPARC[64] */
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001094
Denys Vlasenko84703742012-02-25 02:38:52 +01001095#if defined X86_64
H.J. Lu35be5812012-04-16 13:00:01 +02001096 if (current_personality != 1) {
Andreas Schwab61b74352009-10-16 11:37:13 +02001097 printstat(tcp, addr);
1098 return;
1099 }
1100#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +00001101
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001102 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001103 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001104 return;
1105 }
1106
1107 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001108#ifdef HAVE_LONG_LONG
1109 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1110#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001111 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001112#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001113 (unsigned long) major(statbuf.st_dev),
1114 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001115#ifdef HAVE_LONG_LONG
1116 (unsigned long long) statbuf.st_ino,
1117#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001118 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001119#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001120 sprintmode(statbuf.st_mode));
1121 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1122 (unsigned long) statbuf.st_nlink,
1123 (unsigned long) statbuf.st_uid,
1124 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001125#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001126 tprintf("st_blksize=%lu, ",
1127 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001128#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1129#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001130 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001131#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001132 }
1133 else
1134 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1135 switch (statbuf.st_mode & S_IFMT) {
1136 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001137#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001138 tprintf("st_rdev=makedev(%lu, %lu), ",
1139 (unsigned long) major(statbuf.st_rdev),
1140 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001141#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001142 tprintf("st_size=makedev(%lu, %lu), ",
1143 (unsigned long) major(statbuf.st_size),
1144 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001145#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001146 break;
1147 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001148#ifdef HAVE_LONG_LONG
1149 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1150#else
1151 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1152#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001153 break;
1154 }
1155 if (!abbrev(tcp)) {
1156 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1157 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001158 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001159#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001160 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001161 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001162#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001163#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001164 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1165#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001166#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001167 tprintf(", st_level=%ld", statbuf.st_level);
1168#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001169#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001170 tprintf(", st_fstype=%.*s",
1171 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1172#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001173#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001174 tprintf(", st_gen=%u", statbuf.st_gen);
1175#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001176 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001177 }
1178 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001179 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001180}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001181#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001182
Denys Vlasenko84703742012-02-25 02:38:52 +01001183#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001184static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001185convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001186{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001187 newbuf->st_dev = oldbuf->st_dev;
1188 newbuf->st_ino = oldbuf->st_ino;
1189 newbuf->st_mode = oldbuf->st_mode;
1190 newbuf->st_nlink = oldbuf->st_nlink;
1191 newbuf->st_uid = oldbuf->st_uid;
1192 newbuf->st_gid = oldbuf->st_gid;
1193 newbuf->st_rdev = oldbuf->st_rdev;
1194 newbuf->st_size = oldbuf->st_size;
1195 newbuf->st_atime = oldbuf->st_atime;
1196 newbuf->st_mtime = oldbuf->st_mtime;
1197 newbuf->st_ctime = oldbuf->st_ctime;
1198 newbuf->st_blksize = 0; /* not supported in old_stat */
1199 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001200}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001201
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001202static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001203printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001204{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001205 struct __old_kernel_stat statbuf;
1206 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001207
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001208 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001209 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001210 return;
1211 }
1212 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001213 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001214 return;
1215 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001216
Denys Vlasenko9472a272013-02-12 11:43:46 +01001217# if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001218 if (current_personality == 1) {
1219 printstatsol(tcp, addr);
1220 return;
1221 }
Denys Vlasenko84703742012-02-25 02:38:52 +01001222# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001223
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001224 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001225 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001226 return;
1227 }
1228
1229 convertoldstat(&statbuf, &newstatbuf);
1230 realprintstat(tcp, &newstatbuf);
1231}
Denys Vlasenko84703742012-02-25 02:38:52 +01001232#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001233
John Hughes70623be2001-03-08 13:59:00 +00001234#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001235int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001236sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001237{
1238 if (entering(tcp)) {
1239 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001240 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001241 } else {
1242 printstat(tcp, tcp->u_arg[1]);
1243 }
1244 return 0;
1245}
John Hughesb8c9f772001-03-07 16:53:07 +00001246#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001247
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001248int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001249sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001250{
1251#ifdef HAVE_STAT64
1252 if (entering(tcp)) {
1253 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001254 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001255 } else {
1256 printstat64(tcp, tcp->u_arg[1]);
1257 }
1258 return 0;
1259#else
1260 return printargs(tcp);
1261#endif
1262}
1263
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001264#ifndef AT_SYMLINK_NOFOLLOW
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001265# define AT_SYMLINK_NOFOLLOW 0x100
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001266#endif
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001267#ifndef AT_REMOVEDIR
1268# define AT_REMOVEDIR 0x200
1269#endif
1270#ifndef AT_SYMLINK_FOLLOW
1271# define AT_SYMLINK_FOLLOW 0x400
1272#endif
1273#ifndef AT_NO_AUTOMOUNT
1274# define AT_NO_AUTOMOUNT 0x800
1275#endif
1276#ifndef AT_EMPTY_PATH
1277# define AT_EMPTY_PATH 0x1000
1278#endif
1279
1280static const struct xlat at_flags[] = {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001281 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001282 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1283 { AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" },
1284 { AT_NO_AUTOMOUNT, "AT_NO_AUTOMOUNT" },
1285 { AT_EMPTY_PATH, "AT_EMPTY_PATH" },
1286 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001287};
1288
1289int
1290sys_newfstatat(struct tcb *tcp)
1291{
1292 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001293 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001294 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001295 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001296 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001297#ifdef POWERPC64
1298 if (current_personality == 0)
1299 printstat(tcp, tcp->u_arg[2]);
1300 else
1301 printstat64(tcp, tcp->u_arg[2]);
1302#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001303 printstat64(tcp, tcp->u_arg[2]);
1304#else
1305 printstat(tcp, tcp->u_arg[2]);
1306#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001307 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001308 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001309 }
1310 return 0;
1311}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001312
Denys Vlasenko84703742012-02-25 02:38:52 +01001313#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001314int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001315sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001316{
1317 if (entering(tcp)) {
1318 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001319 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001320 } else {
1321 printoldstat(tcp, tcp->u_arg[1]);
1322 }
1323 return 0;
1324}
Denys Vlasenko84703742012-02-25 02:38:52 +01001325#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001326
John Hughes70623be2001-03-08 13:59:00 +00001327#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001328int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001329sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001330{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001331 if (entering(tcp)) {
1332 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001333 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001334 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001335 printstat(tcp, tcp->u_arg[1]);
1336 }
1337 return 0;
1338}
John Hughesb8c9f772001-03-07 16:53:07 +00001339#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001340
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001341int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001342sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001343{
1344#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001345 if (entering(tcp)) {
1346 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001347 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001348 } else {
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001349 printstat64(tcp, tcp->u_arg[1]);
1350 }
1351 return 0;
1352#else
1353 return printargs(tcp);
1354#endif
1355}
1356
Denys Vlasenko84703742012-02-25 02:38:52 +01001357#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001358int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001359sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001360{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001361 if (entering(tcp)) {
1362 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001363 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001364 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001365 printoldstat(tcp, tcp->u_arg[1]);
1366 }
1367 return 0;
1368}
Denys Vlasenko84703742012-02-25 02:38:52 +01001369#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001370
John Hughes70623be2001-03-08 13:59:00 +00001371#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001372int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001373sys_lstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001374{
1375 if (entering(tcp)) {
1376 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001377 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001378 } else {
1379 printstat(tcp, tcp->u_arg[1]);
1380 }
1381 return 0;
1382}
John Hughesb8c9f772001-03-07 16:53:07 +00001383#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001384
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001385int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001386sys_lstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001387{
1388#ifdef HAVE_STAT64
1389 if (entering(tcp)) {
1390 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001391 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001392 } else {
1393 printstat64(tcp, tcp->u_arg[1]);
1394 }
1395 return 0;
1396#else
1397 return printargs(tcp);
1398#endif
1399}
1400
Denys Vlasenko84703742012-02-25 02:38:52 +01001401#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001402int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001403sys_oldlstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001404{
1405 if (entering(tcp)) {
1406 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001407 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001408 } else {
1409 printoldstat(tcp, tcp->u_arg[1]);
1410 }
1411 return 0;
1412}
Denys Vlasenko84703742012-02-25 02:38:52 +01001413#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001414
Denys Vlasenko9472a272013-02-12 11:43:46 +01001415#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001416
1417int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001418sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001419{
1420 if (entering(tcp)) {
1421 tprintf("%ld, ", tcp->u_arg[0]);
1422 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001423 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001424 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001425# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001426 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001427 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001428 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001429# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001430 printstat(tcp, tcp->u_arg[2]);
1431 }
1432 return 0;
1433}
1434
1435int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001436sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001437{
1438 if (entering(tcp))
1439 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1440 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001441# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001442 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001443 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001444 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001445# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001446 printstat(tcp, tcp->u_arg[2]);
1447 }
1448 return 0;
1449}
1450
1451int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001452sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001453{
1454 if (entering(tcp)) {
1455 tprintf("%ld, ", tcp->u_arg[0]);
1456 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001457 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001458 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001459# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001460 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001461 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001462 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001463# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001464 printstat(tcp, tcp->u_arg[2]);
1465 }
1466 return 0;
1467}
1468
1469int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001470sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001471{
1472 int mode = tcp->u_arg[2];
1473
1474 if (entering(tcp)) {
1475 tprintf("%ld, ", tcp->u_arg[0]);
1476 printpath(tcp, tcp->u_arg[1]);
1477 tprintf(", %s", sprintmode(mode));
1478 switch (mode & S_IFMT) {
1479 case S_IFCHR: case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001480 tprintf(", makedev(%lu, %lu)",
1481 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1482 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001483 break;
1484 default:
1485 break;
1486 }
1487 }
1488 return 0;
1489}
1490
Denys Vlasenko84703742012-02-25 02:38:52 +01001491# ifdef HAVE_SYS_ACL_H
Wichert Akkerman8829a551999-06-11 13:18:40 +00001492
Denys Vlasenko84703742012-02-25 02:38:52 +01001493# include <sys/acl.h>
Wichert Akkerman8829a551999-06-11 13:18:40 +00001494
Roland McGratha4d48532005-06-08 20:45:28 +00001495static const struct xlat aclcmds[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001496# ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001497 { SETACL, "SETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001498# endif
1499# ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001500 { GETACL, "GETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001501# endif
1502# ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001503 { GETACLCNT, "GETACLCNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001504# endif
1505# ifdef ACL_GET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001506 { ACL_GET, "ACL_GET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001507# endif
1508# ifdef ACL_SET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001509 { ACL_SET, "ACL_SET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001510# endif
1511# ifdef ACL_CNT
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001512 { ACL_CNT, "ACL_CNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001513# endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001514 { 0, NULL },
1515};
1516
1517int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001518sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001519{
1520 if (entering(tcp)) {
1521 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001522 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001523 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1524 tprintf(", %ld", tcp->u_arg[2]);
1525 /*
1526 * FIXME - dump out the list of aclent_t's pointed to
1527 * by "tcp->u_arg[3]" if it's not NULL.
1528 */
1529 if (tcp->u_arg[3])
1530 tprintf(", %#lx", tcp->u_arg[3]);
1531 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001532 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001533 }
1534 return 0;
1535}
1536
Wichert Akkerman8829a551999-06-11 13:18:40 +00001537int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001538sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001539{
1540 if (entering(tcp)) {
1541 tprintf("%ld, ", tcp->u_arg[0]);
1542 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1543 tprintf(", %ld", tcp->u_arg[2]);
1544 /*
1545 * FIXME - dump out the list of aclent_t's pointed to
1546 * by "tcp->u_arg[3]" if it's not NULL.
1547 */
1548 if (tcp->u_arg[3])
1549 tprintf(", %#lx", tcp->u_arg[3]);
1550 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001551 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001552 }
1553 return 0;
1554}
1555
Roland McGratha4d48532005-06-08 20:45:28 +00001556static const struct xlat aclipc[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001557# ifdef IPC_SHM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001558 { IPC_SHM, "IPC_SHM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001559# endif
1560# ifdef IPC_SEM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001561 { IPC_SEM, "IPC_SEM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001562# endif
1563# ifdef IPC_MSG
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001564 { IPC_MSG, "IPC_MSG" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001565# endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001566 { 0, NULL },
1567};
1568
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001569int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001570sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001571{
1572 if (entering(tcp)) {
1573 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1574 tprintf(", %#lx, ", tcp->u_arg[1]);
1575 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1576 tprintf(", %ld", tcp->u_arg[3]);
1577 /*
1578 * FIXME - dump out the list of aclent_t's pointed to
1579 * by "tcp->u_arg[4]" if it's not NULL.
1580 */
1581 if (tcp->u_arg[4])
1582 tprintf(", %#lx", tcp->u_arg[4]);
1583 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001584 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001585 }
1586 return 0;
1587}
1588
Denys Vlasenko84703742012-02-25 02:38:52 +01001589# endif /* HAVE_SYS_ACL_H */
Wichert Akkerman8829a551999-06-11 13:18:40 +00001590
Denys Vlasenko9472a272013-02-12 11:43:46 +01001591#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001592
Roland McGrathd9f816f2004-09-04 03:39:20 +00001593static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001594 { 0x73757245, "CODA_SUPER_MAGIC" },
1595 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1596 { 0x1373, "DEVFS_SUPER_MAGIC" },
1597 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1598 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001599 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1600 { 0xef53, "EXT2_SUPER_MAGIC" },
1601 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001602 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001603 { 0x9660, "ISOFS_SUPER_MAGIC" },
1604 { 0x137f, "MINIX_SUPER_MAGIC" },
1605 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001606 { 0x2468, "MINIX2_SUPER_MAGIC" },
1607 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001608 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001609 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001610 { 0x6969, "NFS_SUPER_MAGIC" },
1611 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001612 { 0x002f, "QNX4_SUPER_MAGIC" },
1613 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1614 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1615 { 0x517b, "SMB_SUPER_MAGIC" },
1616 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1617 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1618 { 0x00011954, "UFS_MAGIC" },
1619 { 0x54190100, "UFS_CIGAM" },
1620 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001621 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001622 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001623 { 0, NULL },
1624};
1625
Roland McGrathf9c49b22004-10-06 22:11:54 +00001626static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001627sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001628{
1629 static char buf[32];
Roland McGrathf9c49b22004-10-06 22:11:54 +00001630 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001631
1632 s = xlookup(fsmagic, magic);
1633 if (s) {
1634 sprintf(buf, "\"%s\"", s);
1635 return buf;
1636 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001637 sprintf(buf, "%#x", magic);
1638 return buf;
1639}
1640
1641static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001642printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001643{
1644 struct statfs statbuf;
1645
1646 if (syserror(tcp) || !verbose(tcp)) {
1647 tprintf("%#lx", addr);
1648 return;
1649 }
1650 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001651 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001652 return;
1653 }
1654#ifdef ALPHA
1655
1656 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1657 sprintfstype(statbuf.f_type),
1658 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001659 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001660 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001661 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1662 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001663#else /* !ALPHA */
1664 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1665 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001666 (unsigned long)statbuf.f_bsize,
1667 (unsigned long)statbuf.f_blocks,
1668 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001669 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1670 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001671 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001672 (unsigned long)statbuf.f_ffree,
1673 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001674 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001675#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001676#ifdef _STATFS_F_FRSIZE
1677 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1678#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001679 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001680}
1681
1682int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001683sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001684{
1685 if (entering(tcp)) {
1686 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001687 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001688 } else {
1689 printstatfs(tcp, tcp->u_arg[1]);
1690 }
1691 return 0;
1692}
1693
1694int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001695sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001696{
1697 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001698 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001699 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001700 } else {
1701 printstatfs(tcp, tcp->u_arg[1]);
1702 }
1703 return 0;
1704}
1705
Denys Vlasenko84703742012-02-25 02:38:52 +01001706#if defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001707static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001708printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001709{
1710 struct statfs64 statbuf;
1711
1712 if (syserror(tcp) || !verbose(tcp)) {
1713 tprintf("%#lx", addr);
1714 return;
1715 }
1716 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001717 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001718 return;
1719 }
Roland McGrath08738432005-06-03 02:40:39 +00001720 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001721 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001722 (unsigned long long)statbuf.f_bsize,
1723 (unsigned long long)statbuf.f_blocks,
1724 (unsigned long long)statbuf.f_bfree);
1725 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1726 (unsigned long long)statbuf.f_bavail,
1727 (unsigned long long)statbuf.f_files,
1728 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001729 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1730 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001731#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001732 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001733#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001734#ifdef _STATFS_F_FLAGS
1735 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1736#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001737 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001738}
1739
Andreas Schwab7d558012012-01-17 18:14:22 +01001740struct compat_statfs64 {
1741 uint32_t f_type;
1742 uint32_t f_bsize;
1743 uint64_t f_blocks;
1744 uint64_t f_bfree;
1745 uint64_t f_bavail;
1746 uint64_t f_files;
1747 uint64_t f_ffree;
1748 fsid_t f_fsid;
1749 uint32_t f_namelen;
1750 uint32_t f_frsize;
1751 uint32_t f_flags;
1752 uint32_t f_spare[4];
1753}
1754#if defined(X86_64) || defined(IA64)
1755 __attribute__ ((packed, aligned(4)))
1756#endif
1757;
1758
1759static void
1760printcompat_statfs64(struct tcb *tcp, long addr)
1761{
1762 struct compat_statfs64 statbuf;
1763
1764 if (syserror(tcp) || !verbose(tcp)) {
1765 tprintf("%#lx", addr);
1766 return;
1767 }
1768 if (umove(tcp, addr, &statbuf) < 0) {
1769 tprints("{...}");
1770 return;
1771 }
1772 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1773 sprintfstype(statbuf.f_type),
1774 (unsigned long)statbuf.f_bsize,
1775 (unsigned long long)statbuf.f_blocks,
1776 (unsigned long long)statbuf.f_bfree);
1777 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1778 (unsigned long long)statbuf.f_bavail,
1779 (unsigned long long)statbuf.f_files,
1780 (unsigned long long)statbuf.f_ffree,
1781 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1782 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1783 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001784 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
Andreas Schwab7d558012012-01-17 18:14:22 +01001785}
1786
Roland McGrathab147c52003-07-17 09:03:02 +00001787int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001788sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001789{
1790 if (entering(tcp)) {
1791 printpath(tcp, tcp->u_arg[0]);
1792 tprintf(", %lu, ", tcp->u_arg[1]);
1793 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001794 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001795 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001796 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1797 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001798 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001799 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001800 }
1801 return 0;
1802}
1803
1804int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001805sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001806{
1807 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001808 printfd(tcp, tcp->u_arg[0]);
1809 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001810 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001811 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001812 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001813 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1814 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001815 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001816 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001817 }
1818 return 0;
1819}
1820#endif
1821
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001822#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001823int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001824osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001825{
1826 if (entering(tcp)) {
1827 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001828 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001829 } else {
1830 printstatfs(tcp, tcp->u_arg[1]);
1831 tprintf(", %lu", tcp->u_arg[2]);
1832 }
1833 return 0;
1834}
1835
1836int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001837osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001838{
1839 if (entering(tcp)) {
1840 tprintf("%lu, ", tcp->u_arg[0]);
1841 } else {
1842 printstatfs(tcp, tcp->u_arg[1]);
1843 tprintf(", %lu", tcp->u_arg[2]);
1844 }
1845 return 0;
1846}
Denys Vlasenko84703742012-02-25 02:38:52 +01001847#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001848
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001849/* directory */
1850int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001851sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001852{
1853 if (entering(tcp)) {
1854 printpath(tcp, tcp->u_arg[0]);
1855 }
1856 return 0;
1857}
1858
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001859static int
1860decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001861{
1862 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001863 printpath(tcp, tcp->u_arg[offset]);
1864 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001865 }
1866 return 0;
1867}
1868
1869int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001870sys_mkdir(struct tcb *tcp)
1871{
1872 return decode_mkdir(tcp, 0);
1873}
1874
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001875int
1876sys_mkdirat(struct tcb *tcp)
1877{
1878 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001879 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001880 return decode_mkdir(tcp, 1);
1881}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001882
1883int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001884sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001885{
1886 if (entering(tcp)) {
1887 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001888 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001889 printpath(tcp, tcp->u_arg[1]);
1890 }
1891 return 0;
1892}
1893
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001894int
1895sys_linkat(struct tcb *tcp)
1896{
1897 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001898 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001899 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001900 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001901 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001902 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001903 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001904 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001905 }
1906 return 0;
1907}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001908
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001909int
1910sys_unlinkat(struct tcb *tcp)
1911{
1912 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001913 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001914 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001915 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001916 printflags(at_flags, tcp->u_arg[2], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001917 }
1918 return 0;
1919}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001920
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001921int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001922sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001923{
1924 if (entering(tcp)) {
1925 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001926 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001927 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001928 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001929 }
1930 return 0;
1931}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001932
1933static int
1934decode_readlink(struct tcb *tcp, int offset)
1935{
1936 if (entering(tcp)) {
1937 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001938 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001939 } else {
1940 if (syserror(tcp))
1941 tprintf("%#lx", tcp->u_arg[offset + 1]);
1942 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001943 /* Used to use printpathn(), but readlink
1944 * neither includes NUL in the returned count,
1945 * nor actually writes it into memory.
1946 * printpathn() would decide on printing
1947 * "..." continuation based on garbage
1948 * past return buffer's end.
1949 */
1950 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001951 tprintf(", %lu", tcp->u_arg[offset + 2]);
1952 }
1953 return 0;
1954}
1955
1956int
1957sys_readlink(struct tcb *tcp)
1958{
1959 return decode_readlink(tcp, 0);
1960}
1961
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001962int
1963sys_readlinkat(struct tcb *tcp)
1964{
1965 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001966 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001967 return decode_readlink(tcp, 1);
1968}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001969
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001970int
1971sys_renameat(struct tcb *tcp)
1972{
1973 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001974 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001975 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001976 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001977 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001978 printpath(tcp, tcp->u_arg[3]);
1979 }
1980 return 0;
1981}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001982
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001983int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001984sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001985{
1986 if (entering(tcp)) {
1987 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001988 printuid(", ", tcp->u_arg[1]);
1989 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001990 }
1991 return 0;
1992}
1993
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001994int
1995sys_fchownat(struct tcb *tcp)
1996{
1997 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001998 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001999 printpath(tcp, tcp->u_arg[1]);
2000 printuid(", ", tcp->u_arg[2]);
2001 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002002 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00002003 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002004 }
2005 return 0;
2006}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002007
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002008int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002009sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002010{
2011 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002012 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002013 printuid(", ", tcp->u_arg[1]);
2014 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002015 }
2016 return 0;
2017}
2018
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002019static int
2020decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002021{
2022 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002023 printpath(tcp, tcp->u_arg[offset]);
2024 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002025 }
2026 return 0;
2027}
2028
2029int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002030sys_chmod(struct tcb *tcp)
2031{
2032 return decode_chmod(tcp, 0);
2033}
2034
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002035int
2036sys_fchmodat(struct tcb *tcp)
2037{
2038 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002039 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002040 return decode_chmod(tcp, 1);
2041}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002042
2043int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002044sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002045{
2046 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002047 printfd(tcp, tcp->u_arg[0]);
2048 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002049 }
2050 return 0;
2051}
2052
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002053#ifdef ALPHA
2054int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002055sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002056{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002057 if (entering(tcp)) {
2058 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002059 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002060 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2061 }
2062 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002063}
2064#endif
2065
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002066static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002067decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002068{
2069 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002070 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002071 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002072 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002073 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00002074 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002075 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00002076 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2077 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002078 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002079 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002080 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00002081 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002082 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00002083 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002084 }
2085 return 0;
2086}
2087
2088int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002089sys_utimes(struct tcb *tcp)
2090{
Roland McGrath6afc5652007-07-24 01:57:11 +00002091 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002092}
2093
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002094int
2095sys_futimesat(struct tcb *tcp)
2096{
2097 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002098 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002099 return decode_utimes(tcp, 1, 0);
2100}
2101
2102int
2103sys_utimensat(struct tcb *tcp)
2104{
2105 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002106 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002107 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002108 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00002109 printflags(at_flags, tcp->u_arg[3], "AT_???");
Roland McGrath6afc5652007-07-24 01:57:11 +00002110 }
2111 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002112}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002113
2114int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002115sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002116{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002117 union {
2118 long utl[2];
2119 int uti[2];
Denys Vlasenko751acb32013-02-08 15:34:46 +01002120 long paranoia_for_huge_wordsize[4];
Roland McGrath7e9817c2007-07-05 20:31:58 +00002121 } u;
Denys Vlasenko751acb32013-02-08 15:34:46 +01002122 unsigned wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002123
2124 if (entering(tcp)) {
2125 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002126 tprints(", ");
Denys Vlasenko751acb32013-02-08 15:34:46 +01002127
2128 wordsize = current_wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002129 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002130 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002131 else if (!verbose(tcp))
2132 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002133 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002134 tprints("[?, ?]");
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002135 else if (wordsize == sizeof u.utl[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002136 tprintf("[%s,", sprinttime(u.utl[0]));
2137 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002138 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002139 else if (wordsize == sizeof u.uti[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002140 tprintf("[%s,", sprinttime(u.uti[0]));
2141 tprintf(" %s]", sprinttime(u.uti[1]));
2142 }
2143 else
Denys Vlasenko751acb32013-02-08 15:34:46 +01002144 tprintf("<decode error: unsupported wordsize %d>",
2145 wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002146 }
2147 return 0;
2148}
2149
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002150static int
2151decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002152{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002153 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002154
2155 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002156 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002157 tprintf(", %s", sprintmode(mode));
2158 switch (mode & S_IFMT) {
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002159 case S_IFCHR:
2160 case S_IFBLK:
Denys Vlasenko9472a272013-02-12 11:43:46 +01002161#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002162 if (current_personality == 1)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002163 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002164 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2165 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002166 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002167#endif
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002168 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002169 (unsigned long) major(tcp->u_arg[offset + 2]),
2170 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002171 break;
2172 default:
2173 break;
2174 }
2175 }
2176 return 0;
2177}
2178
2179int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002180sys_mknod(struct tcb *tcp)
2181{
2182 return decode_mknod(tcp, 0);
2183}
2184
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002185int
2186sys_mknodat(struct tcb *tcp)
2187{
2188 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002189 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002190 return decode_mknod(tcp, 1);
2191}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002192
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002193static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002194printdir(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002195{
2196 struct dirent d;
2197
2198 if (!verbose(tcp)) {
2199 tprintf("%#lx", addr);
2200 return;
2201 }
2202 if (umove(tcp, addr, &d) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002203 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002204 return;
2205 }
2206 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002207 tprints("d_name=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002208 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002209 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002210}
2211
2212int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002213sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002214{
2215 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002216 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002217 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002218 } else {
2219 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2220 tprintf("%#lx", tcp->u_arg[1]);
2221 else
2222 printdir(tcp, tcp->u_arg[1]);
2223 /* Not much point in printing this out, it is always 1. */
2224 if (tcp->u_arg[2] != 1)
2225 tprintf(", %lu", tcp->u_arg[2]);
2226 }
2227 return 0;
2228}
2229
Roland McGratha4d48532005-06-08 20:45:28 +00002230static const struct xlat direnttypes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002231 { DT_UNKNOWN, "DT_UNKNOWN" },
2232 { DT_FIFO, "DT_FIFO" },
2233 { DT_CHR, "DT_CHR" },
2234 { DT_DIR, "DT_DIR" },
2235 { DT_BLK, "DT_BLK" },
2236 { DT_REG, "DT_REG" },
2237 { DT_LNK, "DT_LNK" },
2238 { DT_SOCK, "DT_SOCK" },
2239 { DT_WHT, "DT_WHT" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002240 { 0, NULL },
2241};
2242
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002243int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002244sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002245{
2246 int i, len, dents = 0;
2247 char *buf;
2248
2249 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002250 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002251 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002252 return 0;
2253 }
2254 if (syserror(tcp) || !verbose(tcp)) {
2255 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2256 return 0;
2257 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002258 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002259 /* Beware of insanely large or negative values in tcp->u_rval */
2260 if (tcp->u_rval > 1024*1024)
2261 len = 1024*1024;
2262 if (tcp->u_rval < 0)
2263 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002264 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002265 if (len && !buf)
2266 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002267 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002268 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002269 free(buf);
2270 return 0;
2271 }
2272 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002273 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002274 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002275 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002276 if (!abbrev(tcp)) {
2277 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2278 i ? " " : "", d->d_ino, d->d_off);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002279 tprintf("d_reclen=%u, d_name=\"%s\", d_type=",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002280 d->d_reclen, d->d_name);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002281 printxval(direnttypes, buf[i + d->d_reclen - 1], "DT_???");
2282 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002283 }
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002284 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002285 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002286 break;
2287 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002288 i += d->d_reclen;
2289 dents++;
2290 }
2291 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002292 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002293 else
2294 tprintf("/* %u entries */", dents);
2295 tprintf(", %lu", tcp->u_arg[2]);
2296 free(buf);
2297 return 0;
2298}
2299
John Hughesbdf48f52001-03-06 15:08:09 +00002300#if _LFS64_LARGEFILE
2301int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002302sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002303{
2304 int i, len, dents = 0;
2305 char *buf;
2306
2307 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002308 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002309 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002310 return 0;
2311 }
2312 if (syserror(tcp) || !verbose(tcp)) {
2313 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2314 return 0;
2315 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002316
John Hughesbdf48f52001-03-06 15:08:09 +00002317 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002318 /* Beware of insanely large or negative tcp->u_rval */
2319 if (tcp->u_rval > 1024*1024)
2320 len = 1024*1024;
2321 if (tcp->u_rval < 0)
2322 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002323 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002324 if (len && !buf)
2325 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002326
John Hughesbdf48f52001-03-06 15:08:09 +00002327 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002328 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002329 free(buf);
2330 return 0;
2331 }
2332 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002333 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002334 for (i = 0; i < len;) {
2335 struct dirent64 *d = (struct dirent64 *) &buf[i];
John Hughesbdf48f52001-03-06 15:08:09 +00002336 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002337 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002338 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002339 d->d_ino,
2340 d->d_off);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002341 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002342 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002343 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002344 tprintf("d_reclen=%u, d_name=\"%s\"}",
2345 d->d_reclen, d->d_name);
2346 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002347 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002348 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002349 break;
2350 }
John Hughesbdf48f52001-03-06 15:08:09 +00002351 i += d->d_reclen;
2352 dents++;
2353 }
2354 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002355 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002356 else
2357 tprintf("/* %u entries */", dents);
2358 tprintf(", %lu", tcp->u_arg[2]);
2359 free(buf);
2360 return 0;
2361}
2362#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002363
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002364int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002365sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002366{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002367 if (exiting(tcp)) {
2368 if (syserror(tcp))
2369 tprintf("%#lx", tcp->u_arg[0]);
2370 else
2371 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2372 tprintf(", %lu", tcp->u_arg[1]);
2373 }
2374 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002375}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002376
2377#ifdef HAVE_SYS_ASYNCH_H
2378
2379int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002380sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002381{
2382 struct aio_result_t res;
2383
2384 if (entering(tcp)) {
2385 tprintf("%lu, ", tcp->u_arg[0]);
2386 } else {
2387 if (syserror(tcp))
2388 tprintf("%#lx", tcp->u_arg[1]);
2389 else
2390 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2391 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2392 printxval(whence, tcp->u_arg[4], "L_???");
2393 if (syserror(tcp) || tcp->u_arg[5] == 0
2394 || umove(tcp, tcp->u_arg[5], &res) < 0)
2395 tprintf(", %#lx", tcp->u_arg[5]);
2396 else
2397 tprintf(", {aio_return %d aio_errno %d}",
2398 res.aio_return, res.aio_errno);
2399 }
2400 return 0;
2401}
2402
2403int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002404sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002405{
2406 struct aio_result_t res;
2407
2408 if (entering(tcp)) {
2409 tprintf("%lu, ", tcp->u_arg[0]);
2410 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2411 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2412 printxval(whence, tcp->u_arg[4], "L_???");
2413 }
2414 else {
2415 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002416 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002417 else if (syserror(tcp)
2418 || umove(tcp, tcp->u_arg[5], &res) < 0)
2419 tprintf(", %#lx", tcp->u_arg[5]);
2420 else
2421 tprintf(", {aio_return %d aio_errno %d}",
2422 res.aio_return, res.aio_errno);
2423 }
2424 return 0;
2425}
2426
2427int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002428sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002429{
2430 if (entering(tcp))
2431 printtv(tcp, tcp->u_arg[0]);
2432 return 0;
2433}
2434
2435int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002436sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002437{
2438 struct aio_result_t res;
2439
2440 if (exiting(tcp)) {
2441 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002442 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002443 else if (syserror(tcp)
2444 || umove(tcp, tcp->u_arg[0], &res) < 0)
2445 tprintf("%#lx", tcp->u_arg[0]);
2446 else
2447 tprintf("{aio_return %d aio_errno %d}",
2448 res.aio_return, res.aio_errno);
2449 }
2450 return 0;
2451}
2452
2453#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002454
Roland McGratha4d48532005-06-08 20:45:28 +00002455static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002456#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002457 { XATTR_CREATE, "XATTR_CREATE" },
2458 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002459#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002460 { 0, NULL }
2461};
2462
Roland McGrath3292e222004-08-31 06:30:48 +00002463static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002464print_xattr_val(struct tcb *tcp, int failed,
2465 unsigned long arg,
2466 unsigned long insize,
2467 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002468{
Dmitry V. Levin1f215132012-12-07 21:38:52 +00002469 if (insize == 0)
2470 failed = 1;
Denys Vlasenko1d632462009-04-14 12:51:00 +00002471 if (!failed) {
2472 unsigned long capacity = 4 * size + 1;
2473 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2474 if (buf == NULL || /* probably a bogus size argument */
2475 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2476 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002477 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002478 else {
2479 unsigned char *out = buf;
2480 unsigned char *in = &buf[3 * size];
2481 size_t i;
2482 for (i = 0; i < size; ++i) {
2483 if (isprint(in[i]))
2484 *out++ = in[i];
2485 else {
2486#define tohex(n) "0123456789abcdef"[n]
2487 *out++ = '\\';
2488 *out++ = 'x';
2489 *out++ = tohex(in[i] / 16);
2490 *out++ = tohex(in[i] % 16);
2491 }
2492 }
2493 /* Don't print terminating NUL if there is one. */
2494 if (i > 0 && in[i - 1] == '\0')
2495 out -= 4;
2496 *out = '\0';
2497 tprintf(", \"%s\", %ld", buf, insize);
2498 }
2499 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002500 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002501 if (failed)
2502 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002503}
2504
Roland McGrath186c5ac2002-12-15 23:58:23 +00002505int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002506sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002507{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002508 if (entering(tcp)) {
2509 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002510 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002511 printstr(tcp, tcp->u_arg[1], -1);
2512 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002513 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002514 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2515 }
2516 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002517}
2518
2519int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002520sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002521{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002522 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002523 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002524 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002525 printstr(tcp, tcp->u_arg[1], -1);
2526 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002527 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002528 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2529 }
2530 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002531}
2532
2533int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002534sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002535{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002536 if (entering(tcp)) {
2537 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002538 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002539 printstr(tcp, tcp->u_arg[1], -1);
2540 } else {
2541 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2542 tcp->u_rval);
2543 }
2544 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002545}
2546
2547int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002548sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002549{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002550 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002551 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002552 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002553 printstr(tcp, tcp->u_arg[1], -1);
2554 } else {
2555 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2556 tcp->u_rval);
2557 }
2558 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002559}
2560
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002561static void
2562print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2563{
2564 if (syserror(tcp)) {
2565 tprintf("%#lx", addr);
2566 } else {
2567 if (!addr) {
2568 tprints("NULL");
2569 } else {
2570 unsigned long len =
2571 (size < tcp->u_rval) ? size : tcp->u_rval;
2572 printstr(tcp, addr, len);
2573 }
2574 }
2575 tprintf(", %lu", size);
2576}
2577
Roland McGrath186c5ac2002-12-15 23:58:23 +00002578int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002579sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002580{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002581 if (entering(tcp)) {
2582 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002583 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002584 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002585 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002586 }
2587 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002588}
2589
2590int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002591sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002592{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002593 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002594 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002595 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002596 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002597 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002598 }
2599 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002600}
2601
2602int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002603sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002604{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002605 if (entering(tcp)) {
2606 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002607 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002608 printstr(tcp, tcp->u_arg[1], -1);
2609 }
2610 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002611}
2612
2613int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002614sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002615{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002616 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002617 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002618 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002619 printstr(tcp, tcp->u_arg[1], -1);
2620 }
2621 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002622}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002623
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002624static const struct xlat advise[] = {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002625 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2626 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2627 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2628 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2629 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2630 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2631 { 0, NULL }
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002632};
2633
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002634int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002635sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002636{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002637 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002638 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002639 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002640 argn = printllval(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002641 tprintf(", %ld, ", tcp->u_arg[argn++]);
2642 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002643 }
2644 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002645}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002646
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002647int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002648sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002649{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002650 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002651 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002652 printfd(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002653#if defined ARM || defined POWERPC
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002654 argn = printllval(tcp, ", %lld, ", 2);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002655#else
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002656 argn = printllval(tcp, ", %lld, ", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002657#endif
2658 argn = printllval(tcp, "%lld, ", argn);
2659#if defined ARM || defined POWERPC
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002660 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002661#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002662 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002663#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002664 }
2665 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002666}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002667
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002668static const struct xlat inotify_modes[] = {
Dmitry V. Levind475c062011-03-03 01:02:41 +00002669 { 0x00000001, "IN_ACCESS" },
2670 { 0x00000002, "IN_MODIFY" },
2671 { 0x00000004, "IN_ATTRIB" },
2672 { 0x00000008, "IN_CLOSE_WRITE"},
2673 { 0x00000010, "IN_CLOSE_NOWRITE"},
2674 { 0x00000020, "IN_OPEN" },
2675 { 0x00000040, "IN_MOVED_FROM" },
2676 { 0x00000080, "IN_MOVED_TO" },
2677 { 0x00000100, "IN_CREATE" },
2678 { 0x00000200, "IN_DELETE" },
2679 { 0x00000400, "IN_DELETE_SELF"},
2680 { 0x00000800, "IN_MOVE_SELF" },
2681 { 0x00002000, "IN_UNMOUNT" },
2682 { 0x00004000, "IN_Q_OVERFLOW" },
2683 { 0x00008000, "IN_IGNORED" },
2684 { 0x01000000, "IN_ONLYDIR" },
2685 { 0x02000000, "IN_DONT_FOLLOW"},
2686 { 0x20000000, "IN_MASK_ADD" },
2687 { 0x40000000, "IN_ISDIR" },
2688 { 0x80000000, "IN_ONESHOT" },
2689 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002690};
2691
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002692static const struct xlat inotify_init_flags[] = {
2693 { 0x00000800, "IN_NONBLOCK" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002694 { 0x00080000, "IN_CLOEXEC" },
2695 { 0, NULL }
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002696};
2697
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002698int
2699sys_inotify_add_watch(struct tcb *tcp)
2700{
2701 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002702 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002703 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002704 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002705 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002706 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2707 }
2708 return 0;
2709}
2710
2711int
2712sys_inotify_rm_watch(struct tcb *tcp)
2713{
2714 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002715 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levinab1a70c2012-03-11 15:33:34 +00002716 tprintf(", %d", (int) tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002717 }
2718 return 0;
2719}
Roland McGrath96a96612008-05-20 04:56:18 +00002720
2721int
Mark Wielaardbab89402010-03-21 14:41:26 +01002722sys_inotify_init1(struct tcb *tcp)
2723{
2724 if (entering(tcp))
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002725 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
Mark Wielaardbab89402010-03-21 14:41:26 +01002726 return 0;
2727}
2728
2729int
Roland McGrath96a96612008-05-20 04:56:18 +00002730sys_fallocate(struct tcb *tcp)
2731{
2732 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002733 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002734 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002735 tprintf(", %#lo, ", tcp->u_arg[1]); /* mode */
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002736 argn = printllval(tcp, "%llu, ", 2); /* offset */
2737 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002738 }
2739 return 0;
2740}
Dmitry V. Levin88293652012-03-09 21:02:19 +00002741
Dmitry V. Levinad0c01e2012-03-15 00:52:22 +00002742#ifndef SWAP_FLAG_PREFER
2743# define SWAP_FLAG_PREFER 0x8000
2744#endif
2745#ifndef SWAP_FLAG_DISCARD
2746# define SWAP_FLAG_DISCARD 0x10000
2747#endif
Dmitry V. Levin88293652012-03-09 21:02:19 +00002748static const struct xlat swap_flags[] = {
2749 { SWAP_FLAG_PREFER, "SWAP_FLAG_PREFER" },
2750 { SWAP_FLAG_DISCARD, "SWAP_FLAG_DISCARD" },
2751 { 0, NULL }
2752};
2753
2754int
2755sys_swapon(struct tcb *tcp)
2756{
2757 if (entering(tcp)) {
2758 int flags = tcp->u_arg[1];
2759 printpath(tcp, tcp->u_arg[0]);
2760 tprints(", ");
2761 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2762 "SWAP_FLAG_???");
2763 if (flags & SWAP_FLAG_PREFER)
2764 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);
2765 }
2766 return 0;
2767}
H.J. Lu085e4282012-04-17 11:05:04 -07002768
2769#ifdef X32
2770# undef stat64
2771# undef sys_fstat64
2772# undef sys_stat64
2773
2774static void
2775realprintstat64(struct tcb *tcp, long addr)
2776{
2777 struct stat64 statbuf;
2778
2779 if (!addr) {
2780 tprints("NULL");
2781 return;
2782 }
2783 if (syserror(tcp) || !verbose(tcp)) {
2784 tprintf("%#lx", addr);
2785 return;
2786 }
2787
2788 if (umove(tcp, addr, &statbuf) < 0) {
2789 tprints("{...}");
2790 return;
2791 }
2792
2793 if (!abbrev(tcp)) {
2794 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
2795 (unsigned long) major(statbuf.st_dev),
2796 (unsigned long) minor(statbuf.st_dev),
2797 (unsigned long long) statbuf.st_ino,
2798 sprintmode(statbuf.st_mode));
2799 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
2800 (unsigned long) statbuf.st_nlink,
2801 (unsigned long) statbuf.st_uid,
2802 (unsigned long) statbuf.st_gid);
2803 tprintf("st_blksize=%lu, ",
2804 (unsigned long) statbuf.st_blksize);
2805 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
2806 }
2807 else
2808 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
2809 switch (statbuf.st_mode & S_IFMT) {
2810 case S_IFCHR: case S_IFBLK:
2811 tprintf("st_rdev=makedev(%lu, %lu), ",
2812 (unsigned long) major(statbuf.st_rdev),
2813 (unsigned long) minor(statbuf.st_rdev));
2814 break;
2815 default:
2816 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
2817 break;
2818 }
2819 if (!abbrev(tcp)) {
2820 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
2821 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
2822 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
2823 tprints("}");
2824 }
2825 else
2826 tprints("...}");
2827}
2828
2829int
2830sys_fstat64(struct tcb *tcp)
2831{
2832 if (entering(tcp)) {
2833 printfd(tcp, tcp->u_arg[0]);
2834 tprints(", ");
2835 } else {
2836 realprintstat64(tcp, tcp->u_arg[1]);
2837 }
2838 return 0;
2839}
2840
2841int
2842sys_stat64(struct tcb *tcp)
2843{
2844 if (entering(tcp)) {
2845 printpath(tcp, tcp->u_arg[0]);
2846 tprints(", ");
2847 } else {
2848 realprintstat64(tcp, tcp->u_arg[1]);
2849 }
2850 return 0;
2851}
2852#endif