blob: fb59f0d37fefe027b8a9e32116177c759b0de849 [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{
Denys Vlasenko06121762013-02-17 20:08:50 +0100562 long 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 Vlasenko06121762013-02-17 20:08:50 +0100589 * for hi and lo. We would need to use tcp->ext_arg[N] on x32...
590 * ...however, x32 (and x86_64) does not _have_ llseek syscall as such.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100591 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000592int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000593sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000594{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000595 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300596 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000597 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300598 tprintf(", %llu, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100599 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300600 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000601 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300602 tprintf(", %lld, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100603 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300604 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000605 }
606 else {
Denys Vlasenko386b8712013-02-17 01:38:14 +0100607 long long off;
Denys Vlasenko1d632462009-04-14 12:51:00 +0000608 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
609 tprintf("%#lx, ", tcp->u_arg[3]);
610 else
611 tprintf("[%llu], ", off);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100612 printxval(whence_codes, tcp->u_arg[4], "SEEK_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000613 }
614 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000615}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000616
617int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000618sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000619{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000620 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100621 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300622 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +0200623 argn = printllval(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100624 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000625 }
626 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000627}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000628
John Hughes70623be2001-03-08 13:59:00 +0000629#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000630int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000631sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000632{
633 if (entering(tcp)) {
634 printpath(tcp, tcp->u_arg[0]);
635 tprintf(", %lu", tcp->u_arg[1]);
636 }
637 return 0;
638}
John Hughes5a826b82001-03-07 13:21:24 +0000639#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000640
John Hughes70623be2001-03-08 13:59:00 +0000641#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000642int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000643sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000644{
645 if (entering(tcp)) {
646 printpath(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100647 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000648 }
649 return 0;
650}
651#endif
652
John Hughes70623be2001-03-08 13:59:00 +0000653#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000654int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000655sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000656{
657 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300658 printfd(tcp, tcp->u_arg[0]);
659 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000660 }
661 return 0;
662}
John Hughes5a826b82001-03-07 13:21:24 +0000663#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000664
John Hughes70623be2001-03-08 13:59:00 +0000665#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000666int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000667sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000668{
669 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300670 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +0200671 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000672 }
673 return 0;
674}
675#endif
676
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000677/* several stats */
678
Roland McGrathd9f816f2004-09-04 03:39:20 +0000679static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000680 { S_IFREG, "S_IFREG" },
681 { S_IFSOCK, "S_IFSOCK" },
682 { S_IFIFO, "S_IFIFO" },
683 { S_IFLNK, "S_IFLNK" },
684 { S_IFDIR, "S_IFDIR" },
685 { S_IFBLK, "S_IFBLK" },
686 { S_IFCHR, "S_IFCHR" },
687 { 0, NULL },
688};
689
Roland McGrathf9c49b22004-10-06 22:11:54 +0000690static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000691sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000692{
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100693 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
694 + sizeof(int)*3
695 + /*paranoia:*/ 8];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000696 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000697
698 if ((mode & S_IFMT) == 0)
699 s = "";
700 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
701 sprintf(buf, "%#o", mode);
702 return buf;
703 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100704 s = buf + sprintf(buf, "%s%s%s%s", s,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000705 (mode & S_ISUID) ? "|S_ISUID" : "",
706 (mode & S_ISGID) ? "|S_ISGID" : "",
707 (mode & S_ISVTX) ? "|S_ISVTX" : "");
708 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
709 if (mode)
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100710 sprintf((char*)s, "|%#o", mode);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000711 s = (*buf == '|') ? buf + 1 : buf;
712 return *s ? s : "0";
713}
714
715static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000716sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000717{
718 struct tm *tmp;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100719 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000720
721 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000722 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000723 return buf;
724 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200725 tmp = localtime(&t);
726 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000727 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
728 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
729 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
730 else
731 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
732
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000733 return buf;
734}
735
Denys Vlasenko9472a272013-02-12 11:43:46 +0100736#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000737typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000738 int tv_sec;
739 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000740} timestruct_t;
741
742struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000743 unsigned st_dev;
744 int st_pad1[3]; /* network id */
745 unsigned st_ino;
746 unsigned st_mode;
747 unsigned st_nlink;
748 unsigned st_uid;
749 unsigned st_gid;
750 unsigned st_rdev;
751 int st_pad2[2];
752 int st_size;
753 int st_pad3; /* st_size, off_t expansion */
754 timestruct_t st_atime;
755 timestruct_t st_mtime;
756 timestruct_t st_ctime;
757 int st_blksize;
758 int st_blocks;
759 char st_fstype[16];
760 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000761};
762
763static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000764printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000765{
766 struct solstat statbuf;
767
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000768 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200769 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000770 return;
771 }
772 if (!abbrev(tcp)) {
773 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
774 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
775 (unsigned long) (statbuf.st_dev & 0x3ffff),
776 (unsigned long) statbuf.st_ino,
777 sprintmode(statbuf.st_mode));
778 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
779 (unsigned long) statbuf.st_nlink,
780 (unsigned long) statbuf.st_uid,
781 (unsigned long) statbuf.st_gid);
782 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
783 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
784 }
785 else
786 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
787 switch (statbuf.st_mode & S_IFMT) {
788 case S_IFCHR: case S_IFBLK:
789 tprintf("st_rdev=makedev(%lu, %lu), ",
790 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
791 (unsigned long) (statbuf.st_rdev & 0x3ffff));
792 break;
793 default:
794 tprintf("st_size=%u, ", statbuf.st_size);
795 break;
796 }
797 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000798 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
799 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
800 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000801 }
802 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200803 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000804}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000805
Denys Vlasenko9472a272013-02-12 11:43:46 +0100806# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000807static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000808printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000809{
810 struct stat_sparc64 statbuf;
811
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000812 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200813 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000814 return;
815 }
816
817 if (!abbrev(tcp)) {
818 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
819 (unsigned long) major(statbuf.st_dev),
820 (unsigned long) minor(statbuf.st_dev),
821 (unsigned long) statbuf.st_ino,
822 sprintmode(statbuf.st_mode));
823 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
824 (unsigned long) statbuf.st_nlink,
825 (unsigned long) statbuf.st_uid,
826 (unsigned long) statbuf.st_gid);
827 tprintf("st_blksize=%lu, ",
828 (unsigned long) statbuf.st_blksize);
829 tprintf("st_blocks=%lu, ",
830 (unsigned long) statbuf.st_blocks);
831 }
832 else
833 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
834 switch (statbuf.st_mode & S_IFMT) {
835 case S_IFCHR: case S_IFBLK:
836 tprintf("st_rdev=makedev(%lu, %lu), ",
837 (unsigned long) major(statbuf.st_rdev),
838 (unsigned long) minor(statbuf.st_rdev));
839 break;
840 default:
841 tprintf("st_size=%lu, ", statbuf.st_size);
842 break;
843 }
844 if (!abbrev(tcp)) {
845 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
846 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100847 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000848 }
849 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200850 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000851}
Denys Vlasenko9472a272013-02-12 11:43:46 +0100852# endif /* SPARC64 */
853#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000854
Denys Vlasenko84703742012-02-25 02:38:52 +0100855#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200856struct stat_powerpc32 {
857 unsigned int st_dev;
858 unsigned int st_ino;
859 unsigned int st_mode;
860 unsigned short st_nlink;
861 unsigned int st_uid;
862 unsigned int st_gid;
863 unsigned int st_rdev;
864 unsigned int st_size;
865 unsigned int st_blksize;
866 unsigned int st_blocks;
867 unsigned int st_atime;
868 unsigned int st_atime_nsec;
869 unsigned int st_mtime;
870 unsigned int st_mtime_nsec;
871 unsigned int st_ctime;
872 unsigned int st_ctime_nsec;
873 unsigned int __unused4;
874 unsigned int __unused5;
875};
876
877static void
878printstat_powerpc32(struct tcb *tcp, long addr)
879{
880 struct stat_powerpc32 statbuf;
881
882 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200883 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200884 return;
885 }
886
887 if (!abbrev(tcp)) {
888 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
889 major(statbuf.st_dev), minor(statbuf.st_dev),
890 statbuf.st_ino,
891 sprintmode(statbuf.st_mode));
892 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
893 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
894 tprintf("st_blksize=%u, ", statbuf.st_blksize);
895 tprintf("st_blocks=%u, ", statbuf.st_blocks);
896 }
897 else
898 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
899 switch (statbuf.st_mode & S_IFMT) {
900 case S_IFCHR: case S_IFBLK:
901 tprintf("st_rdev=makedev(%lu, %lu), ",
902 (unsigned long) major(statbuf.st_rdev),
903 (unsigned long) minor(statbuf.st_rdev));
904 break;
905 default:
906 tprintf("st_size=%u, ", statbuf.st_size);
907 break;
908 }
909 if (!abbrev(tcp)) {
910 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
911 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100912 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200913 }
914 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200915 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200916}
Denys Vlasenko84703742012-02-25 02:38:52 +0100917#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200918
Roland McGratha4d48532005-06-08 20:45:28 +0000919static const struct xlat fileflags[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000920 { 0, NULL },
921};
922
John Hughes70623be2001-03-08 13:59:00 +0000923#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000924static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000925realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000926{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000927 if (!abbrev(tcp)) {
928 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
929 (unsigned long) major(statbuf->st_dev),
930 (unsigned long) minor(statbuf->st_dev),
931 (unsigned long) statbuf->st_ino,
932 sprintmode(statbuf->st_mode));
933 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
934 (unsigned long) statbuf->st_nlink,
935 (unsigned long) statbuf->st_uid,
936 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000937#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000938 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
939#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000940#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000941 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
942#endif
943 }
944 else
945 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
946 switch (statbuf->st_mode & S_IFMT) {
947 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000948#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000949 tprintf("st_rdev=makedev(%lu, %lu), ",
950 (unsigned long) major(statbuf->st_rdev),
951 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000952#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000953 tprintf("st_size=makedev(%lu, %lu), ",
954 (unsigned long) major(statbuf->st_size),
955 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000956#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000957 break;
958 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000959 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000960 break;
961 }
962 if (!abbrev(tcp)) {
963 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
964 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
965 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000966#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200967 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000968 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000969#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000970#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000971 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
972#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000973#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000974 tprintf(", st_level=%ld", statbuf->st_level);
975#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000976#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000977 tprintf(", st_fstype=%.*s",
978 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
979#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000980#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000981 tprintf(", st_gen=%u", statbuf->st_gen);
982#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200983 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000984 }
985 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200986 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000987}
988
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000989static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000990printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000991{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000992 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000993
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000994 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200995 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000996 return;
997 }
998 if (syserror(tcp) || !verbose(tcp)) {
999 tprintf("%#lx", addr);
1000 return;
1001 }
1002
Denys Vlasenko9472a272013-02-12 11:43:46 +01001003#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001004 if (current_personality == 1) {
1005 printstatsol(tcp, addr);
1006 return;
1007 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001008#ifdef SPARC64
1009 else if (current_personality == 2) {
1010 printstat_sparc64(tcp, addr);
1011 return;
1012 }
1013#endif
Denys Vlasenko9472a272013-02-12 11:43:46 +01001014#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001015
Denys Vlasenko84703742012-02-25 02:38:52 +01001016#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +02001017 if (current_personality == 1) {
1018 printstat_powerpc32(tcp, addr);
1019 return;
1020 }
1021#endif
1022
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001023 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001024 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001025 return;
1026 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001027
1028 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001029}
John Hughes70623be2001-03-08 13:59:00 +00001030#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001031
Denys Vlasenko84703742012-02-25 02:38:52 +01001032#if !defined HAVE_STAT64 && defined X86_64
Roland McGrathe6d0f712007-08-07 01:22:49 +00001033/*
1034 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1035 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1036 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1037 * __GNUC__ is needed for the required __attribute__ below.
1038 */
1039struct stat64 {
1040 unsigned long long st_dev;
1041 unsigned char __pad0[4];
1042 unsigned int __st_ino;
1043 unsigned int st_mode;
1044 unsigned int st_nlink;
1045 unsigned int st_uid;
1046 unsigned int st_gid;
1047 unsigned long long st_rdev;
1048 unsigned char __pad3[4];
1049 long long st_size;
1050 unsigned int st_blksize;
1051 unsigned long long st_blocks;
1052 unsigned int st_atime;
1053 unsigned int st_atime_nsec;
1054 unsigned int st_mtime;
1055 unsigned int st_mtime_nsec;
1056 unsigned int st_ctime;
1057 unsigned int st_ctime_nsec;
1058 unsigned long long st_ino;
1059} __attribute__((packed));
1060# define HAVE_STAT64 1
1061# define STAT64_SIZE 96
1062#endif
1063
Wichert Akkermanc7926982000-04-10 22:22:31 +00001064#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001065static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001066printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001067{
1068 struct stat64 statbuf;
1069
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001070#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001071 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1072#endif
1073
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001074 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001075 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001076 return;
1077 }
1078 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001079 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001080 return;
1081 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001082
Denys Vlasenko9472a272013-02-12 11:43:46 +01001083#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001084 if (current_personality == 1) {
1085 printstatsol(tcp, addr);
1086 return;
1087 }
1088# ifdef SPARC64
1089 else if (current_personality == 2) {
1090 printstat_sparc64(tcp, addr);
1091 return;
1092 }
1093# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +01001094#endif /* SPARC[64] */
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001095
Denys Vlasenko84703742012-02-25 02:38:52 +01001096#if defined X86_64
H.J. Lu35be5812012-04-16 13:00:01 +02001097 if (current_personality != 1) {
Andreas Schwab61b74352009-10-16 11:37:13 +02001098 printstat(tcp, addr);
1099 return;
1100 }
1101#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +00001102
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001103 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001104 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001105 return;
1106 }
1107
1108 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001109#ifdef HAVE_LONG_LONG
1110 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1111#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001112 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001113#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001114 (unsigned long) major(statbuf.st_dev),
1115 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001116#ifdef HAVE_LONG_LONG
1117 (unsigned long long) statbuf.st_ino,
1118#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001119 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001120#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001121 sprintmode(statbuf.st_mode));
1122 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1123 (unsigned long) statbuf.st_nlink,
1124 (unsigned long) statbuf.st_uid,
1125 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001126#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001127 tprintf("st_blksize=%lu, ",
1128 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001129#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1130#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001131 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001132#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001133 }
1134 else
1135 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1136 switch (statbuf.st_mode & S_IFMT) {
1137 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001138#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001139 tprintf("st_rdev=makedev(%lu, %lu), ",
1140 (unsigned long) major(statbuf.st_rdev),
1141 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001142#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001143 tprintf("st_size=makedev(%lu, %lu), ",
1144 (unsigned long) major(statbuf.st_size),
1145 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001146#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001147 break;
1148 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001149#ifdef HAVE_LONG_LONG
1150 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1151#else
1152 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1153#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001154 break;
1155 }
1156 if (!abbrev(tcp)) {
1157 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1158 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001159 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001160#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001161 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001162 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001163#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001164#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001165 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1166#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001167#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001168 tprintf(", st_level=%ld", statbuf.st_level);
1169#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001170#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001171 tprintf(", st_fstype=%.*s",
1172 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1173#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001174#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001175 tprintf(", st_gen=%u", statbuf.st_gen);
1176#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001177 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001178 }
1179 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001180 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001181}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001182#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001183
Denys Vlasenko84703742012-02-25 02:38:52 +01001184#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001185static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001186convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001187{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001188 newbuf->st_dev = oldbuf->st_dev;
1189 newbuf->st_ino = oldbuf->st_ino;
1190 newbuf->st_mode = oldbuf->st_mode;
1191 newbuf->st_nlink = oldbuf->st_nlink;
1192 newbuf->st_uid = oldbuf->st_uid;
1193 newbuf->st_gid = oldbuf->st_gid;
1194 newbuf->st_rdev = oldbuf->st_rdev;
1195 newbuf->st_size = oldbuf->st_size;
1196 newbuf->st_atime = oldbuf->st_atime;
1197 newbuf->st_mtime = oldbuf->st_mtime;
1198 newbuf->st_ctime = oldbuf->st_ctime;
1199 newbuf->st_blksize = 0; /* not supported in old_stat */
1200 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001201}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001202
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001203static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001204printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001205{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001206 struct __old_kernel_stat statbuf;
1207 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001208
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001209 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001210 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001211 return;
1212 }
1213 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001214 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001215 return;
1216 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001217
Denys Vlasenko9472a272013-02-12 11:43:46 +01001218# if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001219 if (current_personality == 1) {
1220 printstatsol(tcp, addr);
1221 return;
1222 }
Denys Vlasenko84703742012-02-25 02:38:52 +01001223# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001224
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001225 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001226 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001227 return;
1228 }
1229
1230 convertoldstat(&statbuf, &newstatbuf);
1231 realprintstat(tcp, &newstatbuf);
1232}
Denys Vlasenko84703742012-02-25 02:38:52 +01001233#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001234
John Hughes70623be2001-03-08 13:59:00 +00001235#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001236int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001237sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001238{
1239 if (entering(tcp)) {
1240 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001241 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001242 } else {
1243 printstat(tcp, tcp->u_arg[1]);
1244 }
1245 return 0;
1246}
John Hughesb8c9f772001-03-07 16:53:07 +00001247#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001248
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001249int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001250sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001251{
1252#ifdef HAVE_STAT64
1253 if (entering(tcp)) {
1254 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001255 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001256 } else {
1257 printstat64(tcp, tcp->u_arg[1]);
1258 }
1259 return 0;
1260#else
1261 return printargs(tcp);
1262#endif
1263}
1264
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001265#ifndef AT_SYMLINK_NOFOLLOW
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001266# define AT_SYMLINK_NOFOLLOW 0x100
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001267#endif
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001268#ifndef AT_REMOVEDIR
1269# define AT_REMOVEDIR 0x200
1270#endif
1271#ifndef AT_SYMLINK_FOLLOW
1272# define AT_SYMLINK_FOLLOW 0x400
1273#endif
1274#ifndef AT_NO_AUTOMOUNT
1275# define AT_NO_AUTOMOUNT 0x800
1276#endif
1277#ifndef AT_EMPTY_PATH
1278# define AT_EMPTY_PATH 0x1000
1279#endif
1280
1281static const struct xlat at_flags[] = {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001282 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001283 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1284 { AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" },
1285 { AT_NO_AUTOMOUNT, "AT_NO_AUTOMOUNT" },
1286 { AT_EMPTY_PATH, "AT_EMPTY_PATH" },
1287 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001288};
1289
1290int
1291sys_newfstatat(struct tcb *tcp)
1292{
1293 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001294 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001295 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001296 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001297 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001298#ifdef POWERPC64
1299 if (current_personality == 0)
1300 printstat(tcp, tcp->u_arg[2]);
1301 else
1302 printstat64(tcp, tcp->u_arg[2]);
1303#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001304 printstat64(tcp, tcp->u_arg[2]);
1305#else
1306 printstat(tcp, tcp->u_arg[2]);
1307#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001308 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001309 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001310 }
1311 return 0;
1312}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001313
Denys Vlasenko84703742012-02-25 02:38:52 +01001314#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001315int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001316sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001317{
1318 if (entering(tcp)) {
1319 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001320 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001321 } else {
1322 printoldstat(tcp, tcp->u_arg[1]);
1323 }
1324 return 0;
1325}
Denys Vlasenko84703742012-02-25 02:38:52 +01001326#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001327
John Hughes70623be2001-03-08 13:59:00 +00001328#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001329int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001330sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001331{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001332 if (entering(tcp)) {
1333 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001334 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001335 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001336 printstat(tcp, tcp->u_arg[1]);
1337 }
1338 return 0;
1339}
John Hughesb8c9f772001-03-07 16:53:07 +00001340#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001341
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001342int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001343sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001344{
1345#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001346 if (entering(tcp)) {
1347 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001348 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001349 } else {
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001350 printstat64(tcp, tcp->u_arg[1]);
1351 }
1352 return 0;
1353#else
1354 return printargs(tcp);
1355#endif
1356}
1357
Denys Vlasenko84703742012-02-25 02:38:52 +01001358#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001359int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001360sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001361{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001362 if (entering(tcp)) {
1363 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001364 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001365 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001366 printoldstat(tcp, tcp->u_arg[1]);
1367 }
1368 return 0;
1369}
Denys Vlasenko84703742012-02-25 02:38:52 +01001370#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001371
John Hughes70623be2001-03-08 13:59:00 +00001372#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001373int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001374sys_lstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001375{
1376 if (entering(tcp)) {
1377 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001378 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001379 } else {
1380 printstat(tcp, tcp->u_arg[1]);
1381 }
1382 return 0;
1383}
John Hughesb8c9f772001-03-07 16:53:07 +00001384#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001385
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001386int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001387sys_lstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001388{
1389#ifdef HAVE_STAT64
1390 if (entering(tcp)) {
1391 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001392 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001393 } else {
1394 printstat64(tcp, tcp->u_arg[1]);
1395 }
1396 return 0;
1397#else
1398 return printargs(tcp);
1399#endif
1400}
1401
Denys Vlasenko84703742012-02-25 02:38:52 +01001402#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001403int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001404sys_oldlstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001405{
1406 if (entering(tcp)) {
1407 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001408 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001409 } else {
1410 printoldstat(tcp, tcp->u_arg[1]);
1411 }
1412 return 0;
1413}
Denys Vlasenko84703742012-02-25 02:38:52 +01001414#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001415
Denys Vlasenko9472a272013-02-12 11:43:46 +01001416#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001417
1418int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001419sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001420{
1421 if (entering(tcp)) {
1422 tprintf("%ld, ", tcp->u_arg[0]);
1423 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001424 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001425 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001426# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001427 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001428 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001429 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001430# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001431 printstat(tcp, tcp->u_arg[2]);
1432 }
1433 return 0;
1434}
1435
1436int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001437sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001438{
1439 if (entering(tcp))
1440 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1441 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001442# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001443 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001444 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001445 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001446# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001447 printstat(tcp, tcp->u_arg[2]);
1448 }
1449 return 0;
1450}
1451
1452int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001453sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001454{
1455 if (entering(tcp)) {
1456 tprintf("%ld, ", tcp->u_arg[0]);
1457 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001458 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001459 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001460# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001461 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001462 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001463 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001464# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001465 printstat(tcp, tcp->u_arg[2]);
1466 }
1467 return 0;
1468}
1469
1470int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001471sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001472{
1473 int mode = tcp->u_arg[2];
1474
1475 if (entering(tcp)) {
1476 tprintf("%ld, ", tcp->u_arg[0]);
1477 printpath(tcp, tcp->u_arg[1]);
1478 tprintf(", %s", sprintmode(mode));
1479 switch (mode & S_IFMT) {
1480 case S_IFCHR: case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001481 tprintf(", makedev(%lu, %lu)",
1482 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1483 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001484 break;
1485 default:
1486 break;
1487 }
1488 }
1489 return 0;
1490}
1491
Denys Vlasenko84703742012-02-25 02:38:52 +01001492# ifdef HAVE_SYS_ACL_H
Wichert Akkerman8829a551999-06-11 13:18:40 +00001493
Denys Vlasenko84703742012-02-25 02:38:52 +01001494# include <sys/acl.h>
Wichert Akkerman8829a551999-06-11 13:18:40 +00001495
Roland McGratha4d48532005-06-08 20:45:28 +00001496static const struct xlat aclcmds[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001497# ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001498 { SETACL, "SETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001499# endif
1500# ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001501 { GETACL, "GETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001502# endif
1503# ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001504 { GETACLCNT, "GETACLCNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001505# endif
1506# ifdef ACL_GET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001507 { ACL_GET, "ACL_GET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001508# endif
1509# ifdef ACL_SET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001510 { ACL_SET, "ACL_SET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001511# endif
1512# ifdef ACL_CNT
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001513 { ACL_CNT, "ACL_CNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001514# endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001515 { 0, NULL },
1516};
1517
1518int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001519sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001520{
1521 if (entering(tcp)) {
1522 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001523 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001524 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1525 tprintf(", %ld", tcp->u_arg[2]);
1526 /*
1527 * FIXME - dump out the list of aclent_t's pointed to
1528 * by "tcp->u_arg[3]" if it's not NULL.
1529 */
1530 if (tcp->u_arg[3])
1531 tprintf(", %#lx", tcp->u_arg[3]);
1532 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001533 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001534 }
1535 return 0;
1536}
1537
Wichert Akkerman8829a551999-06-11 13:18:40 +00001538int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001539sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001540{
1541 if (entering(tcp)) {
1542 tprintf("%ld, ", tcp->u_arg[0]);
1543 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1544 tprintf(", %ld", tcp->u_arg[2]);
1545 /*
1546 * FIXME - dump out the list of aclent_t's pointed to
1547 * by "tcp->u_arg[3]" if it's not NULL.
1548 */
1549 if (tcp->u_arg[3])
1550 tprintf(", %#lx", tcp->u_arg[3]);
1551 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001552 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001553 }
1554 return 0;
1555}
1556
Roland McGratha4d48532005-06-08 20:45:28 +00001557static const struct xlat aclipc[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001558# ifdef IPC_SHM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001559 { IPC_SHM, "IPC_SHM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001560# endif
1561# ifdef IPC_SEM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001562 { IPC_SEM, "IPC_SEM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001563# endif
1564# ifdef IPC_MSG
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001565 { IPC_MSG, "IPC_MSG" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001566# endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001567 { 0, NULL },
1568};
1569
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001570int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001571sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001572{
1573 if (entering(tcp)) {
1574 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1575 tprintf(", %#lx, ", tcp->u_arg[1]);
1576 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1577 tprintf(", %ld", tcp->u_arg[3]);
1578 /*
1579 * FIXME - dump out the list of aclent_t's pointed to
1580 * by "tcp->u_arg[4]" if it's not NULL.
1581 */
1582 if (tcp->u_arg[4])
1583 tprintf(", %#lx", tcp->u_arg[4]);
1584 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001585 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001586 }
1587 return 0;
1588}
1589
Denys Vlasenko84703742012-02-25 02:38:52 +01001590# endif /* HAVE_SYS_ACL_H */
Wichert Akkerman8829a551999-06-11 13:18:40 +00001591
Denys Vlasenko9472a272013-02-12 11:43:46 +01001592#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001593
Roland McGrathd9f816f2004-09-04 03:39:20 +00001594static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001595 { 0x73757245, "CODA_SUPER_MAGIC" },
1596 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1597 { 0x1373, "DEVFS_SUPER_MAGIC" },
1598 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1599 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001600 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1601 { 0xef53, "EXT2_SUPER_MAGIC" },
1602 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001603 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001604 { 0x9660, "ISOFS_SUPER_MAGIC" },
1605 { 0x137f, "MINIX_SUPER_MAGIC" },
1606 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001607 { 0x2468, "MINIX2_SUPER_MAGIC" },
1608 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001609 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001610 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001611 { 0x6969, "NFS_SUPER_MAGIC" },
1612 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001613 { 0x002f, "QNX4_SUPER_MAGIC" },
1614 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1615 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1616 { 0x517b, "SMB_SUPER_MAGIC" },
1617 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1618 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1619 { 0x00011954, "UFS_MAGIC" },
1620 { 0x54190100, "UFS_CIGAM" },
1621 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001622 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001623 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001624 { 0, NULL },
1625};
1626
Roland McGrathf9c49b22004-10-06 22:11:54 +00001627static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001628sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001629{
1630 static char buf[32];
Roland McGrathf9c49b22004-10-06 22:11:54 +00001631 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001632
1633 s = xlookup(fsmagic, magic);
1634 if (s) {
1635 sprintf(buf, "\"%s\"", s);
1636 return buf;
1637 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001638 sprintf(buf, "%#x", magic);
1639 return buf;
1640}
1641
1642static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001643printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001644{
1645 struct statfs statbuf;
1646
1647 if (syserror(tcp) || !verbose(tcp)) {
1648 tprintf("%#lx", addr);
1649 return;
1650 }
1651 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001652 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001653 return;
1654 }
1655#ifdef ALPHA
1656
1657 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1658 sprintfstype(statbuf.f_type),
1659 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001660 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001661 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001662 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1663 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001664#else /* !ALPHA */
1665 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1666 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001667 (unsigned long)statbuf.f_bsize,
1668 (unsigned long)statbuf.f_blocks,
1669 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001670 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1671 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001672 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001673 (unsigned long)statbuf.f_ffree,
1674 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001675 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001676#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001677#ifdef _STATFS_F_FRSIZE
1678 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1679#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001680 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001681}
1682
1683int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001684sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001685{
1686 if (entering(tcp)) {
1687 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001688 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001689 } else {
1690 printstatfs(tcp, tcp->u_arg[1]);
1691 }
1692 return 0;
1693}
1694
1695int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001696sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001697{
1698 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001699 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001700 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001701 } else {
1702 printstatfs(tcp, tcp->u_arg[1]);
1703 }
1704 return 0;
1705}
1706
Denys Vlasenko84703742012-02-25 02:38:52 +01001707#if defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001708static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001709printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001710{
1711 struct statfs64 statbuf;
1712
1713 if (syserror(tcp) || !verbose(tcp)) {
1714 tprintf("%#lx", addr);
1715 return;
1716 }
1717 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001718 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001719 return;
1720 }
Roland McGrath08738432005-06-03 02:40:39 +00001721 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001722 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001723 (unsigned long long)statbuf.f_bsize,
1724 (unsigned long long)statbuf.f_blocks,
1725 (unsigned long long)statbuf.f_bfree);
1726 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1727 (unsigned long long)statbuf.f_bavail,
1728 (unsigned long long)statbuf.f_files,
1729 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001730 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1731 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001732#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001733 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001734#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001735#ifdef _STATFS_F_FLAGS
1736 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1737#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001738 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001739}
1740
Andreas Schwab7d558012012-01-17 18:14:22 +01001741struct compat_statfs64 {
1742 uint32_t f_type;
1743 uint32_t f_bsize;
1744 uint64_t f_blocks;
1745 uint64_t f_bfree;
1746 uint64_t f_bavail;
1747 uint64_t f_files;
1748 uint64_t f_ffree;
1749 fsid_t f_fsid;
1750 uint32_t f_namelen;
1751 uint32_t f_frsize;
1752 uint32_t f_flags;
1753 uint32_t f_spare[4];
1754}
1755#if defined(X86_64) || defined(IA64)
1756 __attribute__ ((packed, aligned(4)))
1757#endif
1758;
1759
1760static void
1761printcompat_statfs64(struct tcb *tcp, long addr)
1762{
1763 struct compat_statfs64 statbuf;
1764
1765 if (syserror(tcp) || !verbose(tcp)) {
1766 tprintf("%#lx", addr);
1767 return;
1768 }
1769 if (umove(tcp, addr, &statbuf) < 0) {
1770 tprints("{...}");
1771 return;
1772 }
1773 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1774 sprintfstype(statbuf.f_type),
1775 (unsigned long)statbuf.f_bsize,
1776 (unsigned long long)statbuf.f_blocks,
1777 (unsigned long long)statbuf.f_bfree);
1778 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1779 (unsigned long long)statbuf.f_bavail,
1780 (unsigned long long)statbuf.f_files,
1781 (unsigned long long)statbuf.f_ffree,
1782 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1783 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1784 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001785 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
Andreas Schwab7d558012012-01-17 18:14:22 +01001786}
1787
Roland McGrathab147c52003-07-17 09:03:02 +00001788int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001789sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001790{
1791 if (entering(tcp)) {
1792 printpath(tcp, tcp->u_arg[0]);
1793 tprintf(", %lu, ", tcp->u_arg[1]);
1794 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001795 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001796 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001797 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1798 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001799 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001800 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001801 }
1802 return 0;
1803}
1804
1805int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001806sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001807{
1808 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001809 printfd(tcp, tcp->u_arg[0]);
1810 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001811 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001812 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001813 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001814 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1815 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001816 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001817 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001818 }
1819 return 0;
1820}
1821#endif
1822
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001823#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001824int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001825osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001826{
1827 if (entering(tcp)) {
1828 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001829 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001830 } else {
1831 printstatfs(tcp, tcp->u_arg[1]);
1832 tprintf(", %lu", tcp->u_arg[2]);
1833 }
1834 return 0;
1835}
1836
1837int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001838osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001839{
1840 if (entering(tcp)) {
1841 tprintf("%lu, ", tcp->u_arg[0]);
1842 } else {
1843 printstatfs(tcp, tcp->u_arg[1]);
1844 tprintf(", %lu", tcp->u_arg[2]);
1845 }
1846 return 0;
1847}
Denys Vlasenko84703742012-02-25 02:38:52 +01001848#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001849
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001850/* directory */
1851int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001852sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001853{
1854 if (entering(tcp)) {
1855 printpath(tcp, tcp->u_arg[0]);
1856 }
1857 return 0;
1858}
1859
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001860static int
1861decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001862{
1863 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001864 printpath(tcp, tcp->u_arg[offset]);
1865 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001866 }
1867 return 0;
1868}
1869
1870int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001871sys_mkdir(struct tcb *tcp)
1872{
1873 return decode_mkdir(tcp, 0);
1874}
1875
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001876int
1877sys_mkdirat(struct tcb *tcp)
1878{
1879 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001880 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001881 return decode_mkdir(tcp, 1);
1882}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001883
1884int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001885sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001886{
1887 if (entering(tcp)) {
1888 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001889 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001890 printpath(tcp, tcp->u_arg[1]);
1891 }
1892 return 0;
1893}
1894
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001895int
1896sys_linkat(struct tcb *tcp)
1897{
1898 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001899 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001900 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001901 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001902 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001903 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001904 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001905 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001906 }
1907 return 0;
1908}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001909
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001910int
1911sys_unlinkat(struct tcb *tcp)
1912{
1913 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001914 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001915 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001916 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001917 printflags(at_flags, tcp->u_arg[2], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001918 }
1919 return 0;
1920}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001921
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001922int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001923sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001924{
1925 if (entering(tcp)) {
1926 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001927 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001928 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001929 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001930 }
1931 return 0;
1932}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001933
1934static int
1935decode_readlink(struct tcb *tcp, int offset)
1936{
1937 if (entering(tcp)) {
1938 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001939 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001940 } else {
1941 if (syserror(tcp))
1942 tprintf("%#lx", tcp->u_arg[offset + 1]);
1943 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001944 /* Used to use printpathn(), but readlink
1945 * neither includes NUL in the returned count,
1946 * nor actually writes it into memory.
1947 * printpathn() would decide on printing
1948 * "..." continuation based on garbage
1949 * past return buffer's end.
1950 */
1951 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001952 tprintf(", %lu", tcp->u_arg[offset + 2]);
1953 }
1954 return 0;
1955}
1956
1957int
1958sys_readlink(struct tcb *tcp)
1959{
1960 return decode_readlink(tcp, 0);
1961}
1962
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001963int
1964sys_readlinkat(struct tcb *tcp)
1965{
1966 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001967 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001968 return decode_readlink(tcp, 1);
1969}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001970
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001971int
1972sys_renameat(struct tcb *tcp)
1973{
1974 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001975 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001976 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001977 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001978 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001979 printpath(tcp, tcp->u_arg[3]);
1980 }
1981 return 0;
1982}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001983
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001984int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001985sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001986{
1987 if (entering(tcp)) {
1988 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001989 printuid(", ", tcp->u_arg[1]);
1990 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001991 }
1992 return 0;
1993}
1994
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001995int
1996sys_fchownat(struct tcb *tcp)
1997{
1998 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001999 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002000 printpath(tcp, tcp->u_arg[1]);
2001 printuid(", ", tcp->u_arg[2]);
2002 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002003 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00002004 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002005 }
2006 return 0;
2007}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002008
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002009int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002010sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002011{
2012 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002013 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002014 printuid(", ", tcp->u_arg[1]);
2015 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002016 }
2017 return 0;
2018}
2019
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002020static int
2021decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002022{
2023 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002024 printpath(tcp, tcp->u_arg[offset]);
2025 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002026 }
2027 return 0;
2028}
2029
2030int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002031sys_chmod(struct tcb *tcp)
2032{
2033 return decode_chmod(tcp, 0);
2034}
2035
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002036int
2037sys_fchmodat(struct tcb *tcp)
2038{
2039 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002040 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002041 return decode_chmod(tcp, 1);
2042}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002043
2044int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002045sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002046{
2047 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002048 printfd(tcp, tcp->u_arg[0]);
2049 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002050 }
2051 return 0;
2052}
2053
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002054#ifdef ALPHA
2055int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002056sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002057{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002058 if (entering(tcp)) {
2059 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002060 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002061 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2062 }
2063 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002064}
2065#endif
2066
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002067static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002068decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002069{
2070 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002071 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002072 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002073 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002074 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00002075 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002076 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00002077 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2078 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002079 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002080 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002081 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00002082 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002083 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00002084 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002085 }
2086 return 0;
2087}
2088
2089int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002090sys_utimes(struct tcb *tcp)
2091{
Roland McGrath6afc5652007-07-24 01:57:11 +00002092 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002093}
2094
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002095int
2096sys_futimesat(struct tcb *tcp)
2097{
2098 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002099 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002100 return decode_utimes(tcp, 1, 0);
2101}
2102
2103int
2104sys_utimensat(struct tcb *tcp)
2105{
2106 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002107 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002108 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002109 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00002110 printflags(at_flags, tcp->u_arg[3], "AT_???");
Roland McGrath6afc5652007-07-24 01:57:11 +00002111 }
2112 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002113}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002114
2115int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002116sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002117{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002118 union {
2119 long utl[2];
2120 int uti[2];
Denys Vlasenko751acb32013-02-08 15:34:46 +01002121 long paranoia_for_huge_wordsize[4];
Roland McGrath7e9817c2007-07-05 20:31:58 +00002122 } u;
Denys Vlasenko751acb32013-02-08 15:34:46 +01002123 unsigned wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002124
2125 if (entering(tcp)) {
2126 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002127 tprints(", ");
Denys Vlasenko751acb32013-02-08 15:34:46 +01002128
2129 wordsize = current_wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002130 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002131 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002132 else if (!verbose(tcp))
2133 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002134 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002135 tprints("[?, ?]");
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002136 else if (wordsize == sizeof u.utl[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002137 tprintf("[%s,", sprinttime(u.utl[0]));
2138 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002139 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002140 else if (wordsize == sizeof u.uti[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002141 tprintf("[%s,", sprinttime(u.uti[0]));
2142 tprintf(" %s]", sprinttime(u.uti[1]));
2143 }
2144 else
Denys Vlasenko751acb32013-02-08 15:34:46 +01002145 tprintf("<decode error: unsupported wordsize %d>",
2146 wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002147 }
2148 return 0;
2149}
2150
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002151static int
2152decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002153{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002154 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002155
2156 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002157 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002158 tprintf(", %s", sprintmode(mode));
2159 switch (mode & S_IFMT) {
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002160 case S_IFCHR:
2161 case S_IFBLK:
Denys Vlasenko9472a272013-02-12 11:43:46 +01002162#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002163 if (current_personality == 1)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002164 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002165 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2166 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002167 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002168#endif
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002169 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002170 (unsigned long) major(tcp->u_arg[offset + 2]),
2171 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002172 break;
2173 default:
2174 break;
2175 }
2176 }
2177 return 0;
2178}
2179
2180int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002181sys_mknod(struct tcb *tcp)
2182{
2183 return decode_mknod(tcp, 0);
2184}
2185
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002186int
2187sys_mknodat(struct tcb *tcp)
2188{
2189 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002190 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002191 return decode_mknod(tcp, 1);
2192}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002193
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002194static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002195printdir(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002196{
2197 struct dirent d;
2198
2199 if (!verbose(tcp)) {
2200 tprintf("%#lx", addr);
2201 return;
2202 }
2203 if (umove(tcp, addr, &d) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002204 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002205 return;
2206 }
2207 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002208 tprints("d_name=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002209 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002210 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002211}
2212
2213int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002214sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002215{
2216 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002217 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002218 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002219 } else {
2220 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2221 tprintf("%#lx", tcp->u_arg[1]);
2222 else
2223 printdir(tcp, tcp->u_arg[1]);
2224 /* Not much point in printing this out, it is always 1. */
2225 if (tcp->u_arg[2] != 1)
2226 tprintf(", %lu", tcp->u_arg[2]);
2227 }
2228 return 0;
2229}
2230
Roland McGratha4d48532005-06-08 20:45:28 +00002231static const struct xlat direnttypes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002232 { DT_UNKNOWN, "DT_UNKNOWN" },
2233 { DT_FIFO, "DT_FIFO" },
2234 { DT_CHR, "DT_CHR" },
2235 { DT_DIR, "DT_DIR" },
2236 { DT_BLK, "DT_BLK" },
2237 { DT_REG, "DT_REG" },
2238 { DT_LNK, "DT_LNK" },
2239 { DT_SOCK, "DT_SOCK" },
2240 { DT_WHT, "DT_WHT" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002241 { 0, NULL },
2242};
2243
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002244int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002245sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002246{
2247 int i, len, dents = 0;
2248 char *buf;
2249
2250 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002251 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002252 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002253 return 0;
2254 }
2255 if (syserror(tcp) || !verbose(tcp)) {
2256 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2257 return 0;
2258 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002259 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002260 /* Beware of insanely large or negative values in tcp->u_rval */
2261 if (tcp->u_rval > 1024*1024)
2262 len = 1024*1024;
2263 if (tcp->u_rval < 0)
2264 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002265 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002266 if (len && !buf)
2267 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002268 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002269 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002270 free(buf);
2271 return 0;
2272 }
2273 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002274 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002275 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002276 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002277 if (!abbrev(tcp)) {
2278 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2279 i ? " " : "", d->d_ino, d->d_off);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002280 tprintf("d_reclen=%u, d_name=\"%s\", d_type=",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002281 d->d_reclen, d->d_name);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002282 printxval(direnttypes, buf[i + d->d_reclen - 1], "DT_???");
2283 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002284 }
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002285 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002286 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002287 break;
2288 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002289 i += d->d_reclen;
2290 dents++;
2291 }
2292 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002293 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002294 else
2295 tprintf("/* %u entries */", dents);
2296 tprintf(", %lu", tcp->u_arg[2]);
2297 free(buf);
2298 return 0;
2299}
2300
John Hughesbdf48f52001-03-06 15:08:09 +00002301#if _LFS64_LARGEFILE
2302int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002303sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002304{
2305 int i, len, dents = 0;
2306 char *buf;
2307
2308 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002309 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002310 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002311 return 0;
2312 }
2313 if (syserror(tcp) || !verbose(tcp)) {
2314 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2315 return 0;
2316 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002317
John Hughesbdf48f52001-03-06 15:08:09 +00002318 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002319 /* Beware of insanely large or negative tcp->u_rval */
2320 if (tcp->u_rval > 1024*1024)
2321 len = 1024*1024;
2322 if (tcp->u_rval < 0)
2323 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002324 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002325 if (len && !buf)
2326 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002327
John Hughesbdf48f52001-03-06 15:08:09 +00002328 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002329 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002330 free(buf);
2331 return 0;
2332 }
2333 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002334 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002335 for (i = 0; i < len;) {
2336 struct dirent64 *d = (struct dirent64 *) &buf[i];
John Hughesbdf48f52001-03-06 15:08:09 +00002337 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002338 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002339 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002340 d->d_ino,
2341 d->d_off);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002342 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002343 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002344 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002345 tprintf("d_reclen=%u, d_name=\"%s\"}",
2346 d->d_reclen, d->d_name);
2347 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002348 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002349 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002350 break;
2351 }
John Hughesbdf48f52001-03-06 15:08:09 +00002352 i += d->d_reclen;
2353 dents++;
2354 }
2355 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002356 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002357 else
2358 tprintf("/* %u entries */", dents);
2359 tprintf(", %lu", tcp->u_arg[2]);
2360 free(buf);
2361 return 0;
2362}
2363#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002364
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002365int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002366sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002367{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002368 if (exiting(tcp)) {
2369 if (syserror(tcp))
2370 tprintf("%#lx", tcp->u_arg[0]);
2371 else
2372 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2373 tprintf(", %lu", tcp->u_arg[1]);
2374 }
2375 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002376}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002377
2378#ifdef HAVE_SYS_ASYNCH_H
2379
2380int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002381sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002382{
2383 struct aio_result_t res;
2384
2385 if (entering(tcp)) {
2386 tprintf("%lu, ", tcp->u_arg[0]);
2387 } else {
2388 if (syserror(tcp))
2389 tprintf("%#lx", tcp->u_arg[1]);
2390 else
2391 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2392 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2393 printxval(whence, tcp->u_arg[4], "L_???");
2394 if (syserror(tcp) || tcp->u_arg[5] == 0
2395 || umove(tcp, tcp->u_arg[5], &res) < 0)
2396 tprintf(", %#lx", tcp->u_arg[5]);
2397 else
2398 tprintf(", {aio_return %d aio_errno %d}",
2399 res.aio_return, res.aio_errno);
2400 }
2401 return 0;
2402}
2403
2404int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002405sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002406{
2407 struct aio_result_t res;
2408
2409 if (entering(tcp)) {
2410 tprintf("%lu, ", tcp->u_arg[0]);
2411 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2412 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2413 printxval(whence, tcp->u_arg[4], "L_???");
2414 }
2415 else {
2416 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002417 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002418 else if (syserror(tcp)
2419 || umove(tcp, tcp->u_arg[5], &res) < 0)
2420 tprintf(", %#lx", tcp->u_arg[5]);
2421 else
2422 tprintf(", {aio_return %d aio_errno %d}",
2423 res.aio_return, res.aio_errno);
2424 }
2425 return 0;
2426}
2427
2428int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002429sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002430{
2431 if (entering(tcp))
2432 printtv(tcp, tcp->u_arg[0]);
2433 return 0;
2434}
2435
2436int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002437sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002438{
2439 struct aio_result_t res;
2440
2441 if (exiting(tcp)) {
2442 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002443 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002444 else if (syserror(tcp)
2445 || umove(tcp, tcp->u_arg[0], &res) < 0)
2446 tprintf("%#lx", tcp->u_arg[0]);
2447 else
2448 tprintf("{aio_return %d aio_errno %d}",
2449 res.aio_return, res.aio_errno);
2450 }
2451 return 0;
2452}
2453
2454#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002455
Roland McGratha4d48532005-06-08 20:45:28 +00002456static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002457#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002458 { XATTR_CREATE, "XATTR_CREATE" },
2459 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002460#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002461 { 0, NULL }
2462};
2463
Roland McGrath3292e222004-08-31 06:30:48 +00002464static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002465print_xattr_val(struct tcb *tcp, int failed,
2466 unsigned long arg,
2467 unsigned long insize,
2468 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002469{
Dmitry V. Levin1f215132012-12-07 21:38:52 +00002470 if (insize == 0)
2471 failed = 1;
Denys Vlasenko1d632462009-04-14 12:51:00 +00002472 if (!failed) {
2473 unsigned long capacity = 4 * size + 1;
2474 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2475 if (buf == NULL || /* probably a bogus size argument */
2476 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2477 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002478 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002479 else {
2480 unsigned char *out = buf;
2481 unsigned char *in = &buf[3 * size];
2482 size_t i;
2483 for (i = 0; i < size; ++i) {
2484 if (isprint(in[i]))
2485 *out++ = in[i];
2486 else {
2487#define tohex(n) "0123456789abcdef"[n]
2488 *out++ = '\\';
2489 *out++ = 'x';
2490 *out++ = tohex(in[i] / 16);
2491 *out++ = tohex(in[i] % 16);
2492 }
2493 }
2494 /* Don't print terminating NUL if there is one. */
2495 if (i > 0 && in[i - 1] == '\0')
2496 out -= 4;
2497 *out = '\0';
2498 tprintf(", \"%s\", %ld", buf, insize);
2499 }
2500 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002501 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002502 if (failed)
2503 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002504}
2505
Roland McGrath186c5ac2002-12-15 23:58:23 +00002506int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002507sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002508{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002509 if (entering(tcp)) {
2510 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002511 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002512 printstr(tcp, tcp->u_arg[1], -1);
2513 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002514 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002515 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2516 }
2517 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002518}
2519
2520int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002521sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002522{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002523 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002524 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002525 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002526 printstr(tcp, tcp->u_arg[1], -1);
2527 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002528 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002529 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2530 }
2531 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002532}
2533
2534int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002535sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002536{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002537 if (entering(tcp)) {
2538 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002539 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002540 printstr(tcp, tcp->u_arg[1], -1);
2541 } else {
2542 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2543 tcp->u_rval);
2544 }
2545 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002546}
2547
2548int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002549sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002550{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002551 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002552 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002553 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002554 printstr(tcp, tcp->u_arg[1], -1);
2555 } else {
2556 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2557 tcp->u_rval);
2558 }
2559 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002560}
2561
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002562static void
2563print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2564{
2565 if (syserror(tcp)) {
2566 tprintf("%#lx", addr);
2567 } else {
2568 if (!addr) {
2569 tprints("NULL");
2570 } else {
2571 unsigned long len =
2572 (size < tcp->u_rval) ? size : tcp->u_rval;
2573 printstr(tcp, addr, len);
2574 }
2575 }
2576 tprintf(", %lu", size);
2577}
2578
Roland McGrath186c5ac2002-12-15 23:58:23 +00002579int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002580sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002581{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002582 if (entering(tcp)) {
2583 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002584 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002585 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002586 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002587 }
2588 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002589}
2590
2591int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002592sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002593{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002594 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002595 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002596 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002597 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002598 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002599 }
2600 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002601}
2602
2603int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002604sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002605{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002606 if (entering(tcp)) {
2607 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002608 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002609 printstr(tcp, tcp->u_arg[1], -1);
2610 }
2611 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002612}
2613
2614int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002615sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002616{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002617 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002618 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002619 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002620 printstr(tcp, tcp->u_arg[1], -1);
2621 }
2622 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002623}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002624
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002625static const struct xlat advise[] = {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002626 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2627 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2628 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2629 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2630 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2631 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2632 { 0, NULL }
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002633};
2634
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002635int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002636sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002637{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002638 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002639 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002640 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002641 argn = printllval(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002642 tprintf(", %ld, ", tcp->u_arg[argn++]);
2643 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002644 }
2645 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002646}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002647
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002648int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002649sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002650{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002651 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002652 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002653 printfd(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002654#if defined ARM || defined POWERPC
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002655 argn = printllval(tcp, ", %lld, ", 2);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002656#else
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002657 argn = printllval(tcp, ", %lld, ", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002658#endif
2659 argn = printllval(tcp, "%lld, ", argn);
2660#if defined ARM || defined POWERPC
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002661 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002662#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002663 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002664#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002665 }
2666 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002667}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002668
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002669static const struct xlat inotify_modes[] = {
Dmitry V. Levind475c062011-03-03 01:02:41 +00002670 { 0x00000001, "IN_ACCESS" },
2671 { 0x00000002, "IN_MODIFY" },
2672 { 0x00000004, "IN_ATTRIB" },
2673 { 0x00000008, "IN_CLOSE_WRITE"},
2674 { 0x00000010, "IN_CLOSE_NOWRITE"},
2675 { 0x00000020, "IN_OPEN" },
2676 { 0x00000040, "IN_MOVED_FROM" },
2677 { 0x00000080, "IN_MOVED_TO" },
2678 { 0x00000100, "IN_CREATE" },
2679 { 0x00000200, "IN_DELETE" },
2680 { 0x00000400, "IN_DELETE_SELF"},
2681 { 0x00000800, "IN_MOVE_SELF" },
2682 { 0x00002000, "IN_UNMOUNT" },
2683 { 0x00004000, "IN_Q_OVERFLOW" },
2684 { 0x00008000, "IN_IGNORED" },
2685 { 0x01000000, "IN_ONLYDIR" },
2686 { 0x02000000, "IN_DONT_FOLLOW"},
2687 { 0x20000000, "IN_MASK_ADD" },
2688 { 0x40000000, "IN_ISDIR" },
2689 { 0x80000000, "IN_ONESHOT" },
2690 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002691};
2692
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002693static const struct xlat inotify_init_flags[] = {
2694 { 0x00000800, "IN_NONBLOCK" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002695 { 0x00080000, "IN_CLOEXEC" },
2696 { 0, NULL }
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002697};
2698
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002699int
2700sys_inotify_add_watch(struct tcb *tcp)
2701{
2702 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002703 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002704 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002705 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002706 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002707 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2708 }
2709 return 0;
2710}
2711
2712int
2713sys_inotify_rm_watch(struct tcb *tcp)
2714{
2715 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002716 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levinab1a70c2012-03-11 15:33:34 +00002717 tprintf(", %d", (int) tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002718 }
2719 return 0;
2720}
Roland McGrath96a96612008-05-20 04:56:18 +00002721
2722int
Mark Wielaardbab89402010-03-21 14:41:26 +01002723sys_inotify_init1(struct tcb *tcp)
2724{
2725 if (entering(tcp))
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002726 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
Mark Wielaardbab89402010-03-21 14:41:26 +01002727 return 0;
2728}
2729
2730int
Roland McGrath96a96612008-05-20 04:56:18 +00002731sys_fallocate(struct tcb *tcp)
2732{
2733 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002734 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002735 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002736 tprintf(", %#lo, ", tcp->u_arg[1]); /* mode */
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002737 argn = printllval(tcp, "%llu, ", 2); /* offset */
2738 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002739 }
2740 return 0;
2741}
Dmitry V. Levin88293652012-03-09 21:02:19 +00002742
Dmitry V. Levinad0c01e2012-03-15 00:52:22 +00002743#ifndef SWAP_FLAG_PREFER
2744# define SWAP_FLAG_PREFER 0x8000
2745#endif
2746#ifndef SWAP_FLAG_DISCARD
2747# define SWAP_FLAG_DISCARD 0x10000
2748#endif
Dmitry V. Levin88293652012-03-09 21:02:19 +00002749static const struct xlat swap_flags[] = {
2750 { SWAP_FLAG_PREFER, "SWAP_FLAG_PREFER" },
2751 { SWAP_FLAG_DISCARD, "SWAP_FLAG_DISCARD" },
2752 { 0, NULL }
2753};
2754
2755int
2756sys_swapon(struct tcb *tcp)
2757{
2758 if (entering(tcp)) {
2759 int flags = tcp->u_arg[1];
2760 printpath(tcp, tcp->u_arg[0]);
2761 tprints(", ");
2762 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2763 "SWAP_FLAG_???");
2764 if (flags & SWAP_FLAG_PREFER)
2765 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);
2766 }
2767 return 0;
2768}
H.J. Lu085e4282012-04-17 11:05:04 -07002769
2770#ifdef X32
2771# undef stat64
2772# undef sys_fstat64
2773# undef sys_stat64
2774
2775static void
2776realprintstat64(struct tcb *tcp, long addr)
2777{
2778 struct stat64 statbuf;
2779
2780 if (!addr) {
2781 tprints("NULL");
2782 return;
2783 }
2784 if (syserror(tcp) || !verbose(tcp)) {
2785 tprintf("%#lx", addr);
2786 return;
2787 }
2788
2789 if (umove(tcp, addr, &statbuf) < 0) {
2790 tprints("{...}");
2791 return;
2792 }
2793
2794 if (!abbrev(tcp)) {
2795 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
2796 (unsigned long) major(statbuf.st_dev),
2797 (unsigned long) minor(statbuf.st_dev),
2798 (unsigned long long) statbuf.st_ino,
2799 sprintmode(statbuf.st_mode));
2800 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
2801 (unsigned long) statbuf.st_nlink,
2802 (unsigned long) statbuf.st_uid,
2803 (unsigned long) statbuf.st_gid);
2804 tprintf("st_blksize=%lu, ",
2805 (unsigned long) statbuf.st_blksize);
2806 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
2807 }
2808 else
2809 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
2810 switch (statbuf.st_mode & S_IFMT) {
2811 case S_IFCHR: case S_IFBLK:
2812 tprintf("st_rdev=makedev(%lu, %lu), ",
2813 (unsigned long) major(statbuf.st_rdev),
2814 (unsigned long) minor(statbuf.st_rdev));
2815 break;
2816 default:
2817 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
2818 break;
2819 }
2820 if (!abbrev(tcp)) {
2821 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
2822 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
2823 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
2824 tprints("}");
2825 }
2826 else
2827 tprints("...}");
2828}
2829
2830int
2831sys_fstat64(struct tcb *tcp)
2832{
2833 if (entering(tcp)) {
2834 printfd(tcp, tcp->u_arg[0]);
2835 tprints(", ");
2836 } else {
2837 realprintstat64(tcp, tcp->u_arg[1]);
2838 }
2839 return 0;
2840}
2841
2842int
2843sys_stat64(struct tcb *tcp)
2844{
2845 if (entering(tcp)) {
2846 printpath(tcp, tcp->u_arg[0]);
2847 tprints(", ");
2848 } else {
2849 realprintstat64(tcp, tcp->u_arg[1]);
2850 }
2851 return 0;
2852}
2853#endif