blob: e5354487d1fd4f1af3d1d1f80709b0abfaf784d6 [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 Vlasenko782d90f2013-02-17 12:47:44 +0100519static const 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" },
523 { 0, NULL },
524};
525
Denys Vlasenko386b8712013-02-17 01:38:14 +0100526/* Linux kernel has exactly one version of lseek:
527 * fs/read_write.c::SYSCALL_DEFINE3(lseek, unsigned, fd, off_t, offset, unsigned, origin)
528 * In kernel, off_t is always the same as (kernel's) long
529 * (see include/uapi/asm-generic/posix_types.h),
530 * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument.
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100531 * Use test/x32_lseek.c to test lseek decoding.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100532 */
H.J. Luc933f272012-04-16 17:41:13 +0200533#if defined(LINUX_MIPSN32) || defined(X32)
Roland McGrath542c2c62008-05-20 01:11:56 +0000534int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000535sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000536{
537 long long offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100538 int whence;
Roland McGrath542c2c62008-05-20 01:11:56 +0000539
540 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300541 printfd(tcp, tcp->u_arg[0]);
Roland McGrath542c2c62008-05-20 01:11:56 +0000542 offset = tcp->ext_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100543 whence = tcp->u_arg[2];
544 if (whence == SEEK_SET)
545 tprintf(", %llu, ", offset);
Roland McGrath542c2c62008-05-20 01:11:56 +0000546 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100547 tprintf(", %lld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100548 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath542c2c62008-05-20 01:11:56 +0000549 }
H.J. Ludd0130b2012-04-16 12:16:45 +0200550 return RVAL_LUDECIMAL;
Roland McGrath542c2c62008-05-20 01:11:56 +0000551}
H.J. Ludd0130b2012-04-16 12:16:45 +0200552#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000553int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000554sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000555{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000556 off_t offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100557 int whence;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000558
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000559 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300560 printfd(tcp, tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000561 offset = tcp->u_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100562 whence = tcp->u_arg[2];
563 if (whence == SEEK_SET)
564 tprintf(", %lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000565 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100566 tprintf(", %ld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100567 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000568 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000569 return RVAL_UDECIMAL;
570}
John Hughes5a826b82001-03-07 13:21:24 +0000571#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000572
Denys Vlasenko386b8712013-02-17 01:38:14 +0100573/* llseek syscall takes explicitly two ulong arguments hi, lo,
574 * rather than one 64-bit argument for which LONG_LONG works
575 * appropriate for the native byte order.
576 *
577 * See kernel's fs/read_write.c::SYSCALL_DEFINE5(llseek, ...)
578 *
579 * hi,lo are "unsigned longs" and combined exactly this way in kernel:
580 * ((loff_t) hi << 32) | lo
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100581 * Note that for architectures with kernel's long wider than userspace long
Denys Vlasenko386b8712013-02-17 01:38:14 +0100582 * (such as x32), combining code will use *kernel's*, i.e. *wide* longs
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100583 * for hi and lo. We may need to use tcp->ext_arg[N]!
Denys Vlasenko386b8712013-02-17 01:38:14 +0100584 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000585int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000586sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000587{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000588 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300589 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000590 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300591 tprintf(", %llu, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100592 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300593 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000594 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300595 tprintf(", %lld, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100596 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300597 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000598 }
599 else {
Denys Vlasenko386b8712013-02-17 01:38:14 +0100600 long long off;
Denys Vlasenko1d632462009-04-14 12:51:00 +0000601 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
602 tprintf("%#lx, ", tcp->u_arg[3]);
603 else
604 tprintf("[%llu], ", off);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100605 printxval(whence_codes, tcp->u_arg[4], "SEEK_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000606 }
607 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000608}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000609
610int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000611sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000612{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000613 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100614 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300615 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +0200616 argn = printllval(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100617 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000618 }
619 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000620}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000621
John Hughes70623be2001-03-08 13:59:00 +0000622#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000623int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000624sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000625{
626 if (entering(tcp)) {
627 printpath(tcp, tcp->u_arg[0]);
628 tprintf(", %lu", tcp->u_arg[1]);
629 }
630 return 0;
631}
John Hughes5a826b82001-03-07 13:21:24 +0000632#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000633
John Hughes70623be2001-03-08 13:59:00 +0000634#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000635int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000636sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000637{
638 if (entering(tcp)) {
639 printpath(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100640 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000641 }
642 return 0;
643}
644#endif
645
John Hughes70623be2001-03-08 13:59:00 +0000646#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000647int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000648sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000649{
650 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300651 printfd(tcp, tcp->u_arg[0]);
652 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000653 }
654 return 0;
655}
John Hughes5a826b82001-03-07 13:21:24 +0000656#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000657
John Hughes70623be2001-03-08 13:59:00 +0000658#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000659int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000660sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000661{
662 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300663 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +0200664 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000665 }
666 return 0;
667}
668#endif
669
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000670/* several stats */
671
Roland McGrathd9f816f2004-09-04 03:39:20 +0000672static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000673 { S_IFREG, "S_IFREG" },
674 { S_IFSOCK, "S_IFSOCK" },
675 { S_IFIFO, "S_IFIFO" },
676 { S_IFLNK, "S_IFLNK" },
677 { S_IFDIR, "S_IFDIR" },
678 { S_IFBLK, "S_IFBLK" },
679 { S_IFCHR, "S_IFCHR" },
680 { 0, NULL },
681};
682
Roland McGrathf9c49b22004-10-06 22:11:54 +0000683static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000684sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000685{
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100686 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
687 + sizeof(int)*3
688 + /*paranoia:*/ 8];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000689 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000690
691 if ((mode & S_IFMT) == 0)
692 s = "";
693 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
694 sprintf(buf, "%#o", mode);
695 return buf;
696 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100697 s = buf + sprintf(buf, "%s%s%s%s", s,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000698 (mode & S_ISUID) ? "|S_ISUID" : "",
699 (mode & S_ISGID) ? "|S_ISGID" : "",
700 (mode & S_ISVTX) ? "|S_ISVTX" : "");
701 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
702 if (mode)
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100703 sprintf((char*)s, "|%#o", mode);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000704 s = (*buf == '|') ? buf + 1 : buf;
705 return *s ? s : "0";
706}
707
708static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000709sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000710{
711 struct tm *tmp;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100712 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000713
714 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000715 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000716 return buf;
717 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200718 tmp = localtime(&t);
719 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000720 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
721 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
722 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
723 else
724 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
725
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000726 return buf;
727}
728
Denys Vlasenko9472a272013-02-12 11:43:46 +0100729#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000730typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000731 int tv_sec;
732 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000733} timestruct_t;
734
735struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000736 unsigned st_dev;
737 int st_pad1[3]; /* network id */
738 unsigned st_ino;
739 unsigned st_mode;
740 unsigned st_nlink;
741 unsigned st_uid;
742 unsigned st_gid;
743 unsigned st_rdev;
744 int st_pad2[2];
745 int st_size;
746 int st_pad3; /* st_size, off_t expansion */
747 timestruct_t st_atime;
748 timestruct_t st_mtime;
749 timestruct_t st_ctime;
750 int st_blksize;
751 int st_blocks;
752 char st_fstype[16];
753 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000754};
755
756static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000757printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000758{
759 struct solstat statbuf;
760
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000761 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200762 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000763 return;
764 }
765 if (!abbrev(tcp)) {
766 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
767 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
768 (unsigned long) (statbuf.st_dev & 0x3ffff),
769 (unsigned long) statbuf.st_ino,
770 sprintmode(statbuf.st_mode));
771 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
772 (unsigned long) statbuf.st_nlink,
773 (unsigned long) statbuf.st_uid,
774 (unsigned long) statbuf.st_gid);
775 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
776 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
777 }
778 else
779 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
780 switch (statbuf.st_mode & S_IFMT) {
781 case S_IFCHR: case S_IFBLK:
782 tprintf("st_rdev=makedev(%lu, %lu), ",
783 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
784 (unsigned long) (statbuf.st_rdev & 0x3ffff));
785 break;
786 default:
787 tprintf("st_size=%u, ", statbuf.st_size);
788 break;
789 }
790 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000791 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
792 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
793 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000794 }
795 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200796 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000797}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000798
Denys Vlasenko9472a272013-02-12 11:43:46 +0100799# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000800static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000801printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000802{
803 struct stat_sparc64 statbuf;
804
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000805 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200806 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000807 return;
808 }
809
810 if (!abbrev(tcp)) {
811 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
812 (unsigned long) major(statbuf.st_dev),
813 (unsigned long) minor(statbuf.st_dev),
814 (unsigned long) statbuf.st_ino,
815 sprintmode(statbuf.st_mode));
816 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
817 (unsigned long) statbuf.st_nlink,
818 (unsigned long) statbuf.st_uid,
819 (unsigned long) statbuf.st_gid);
820 tprintf("st_blksize=%lu, ",
821 (unsigned long) statbuf.st_blksize);
822 tprintf("st_blocks=%lu, ",
823 (unsigned long) statbuf.st_blocks);
824 }
825 else
826 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
827 switch (statbuf.st_mode & S_IFMT) {
828 case S_IFCHR: case S_IFBLK:
829 tprintf("st_rdev=makedev(%lu, %lu), ",
830 (unsigned long) major(statbuf.st_rdev),
831 (unsigned long) minor(statbuf.st_rdev));
832 break;
833 default:
834 tprintf("st_size=%lu, ", statbuf.st_size);
835 break;
836 }
837 if (!abbrev(tcp)) {
838 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
839 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100840 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000841 }
842 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200843 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000844}
Denys Vlasenko9472a272013-02-12 11:43:46 +0100845# endif /* SPARC64 */
846#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000847
Denys Vlasenko84703742012-02-25 02:38:52 +0100848#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200849struct stat_powerpc32 {
850 unsigned int st_dev;
851 unsigned int st_ino;
852 unsigned int st_mode;
853 unsigned short st_nlink;
854 unsigned int st_uid;
855 unsigned int st_gid;
856 unsigned int st_rdev;
857 unsigned int st_size;
858 unsigned int st_blksize;
859 unsigned int st_blocks;
860 unsigned int st_atime;
861 unsigned int st_atime_nsec;
862 unsigned int st_mtime;
863 unsigned int st_mtime_nsec;
864 unsigned int st_ctime;
865 unsigned int st_ctime_nsec;
866 unsigned int __unused4;
867 unsigned int __unused5;
868};
869
870static void
871printstat_powerpc32(struct tcb *tcp, long addr)
872{
873 struct stat_powerpc32 statbuf;
874
875 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200876 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200877 return;
878 }
879
880 if (!abbrev(tcp)) {
881 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
882 major(statbuf.st_dev), minor(statbuf.st_dev),
883 statbuf.st_ino,
884 sprintmode(statbuf.st_mode));
885 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
886 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
887 tprintf("st_blksize=%u, ", statbuf.st_blksize);
888 tprintf("st_blocks=%u, ", statbuf.st_blocks);
889 }
890 else
891 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
892 switch (statbuf.st_mode & S_IFMT) {
893 case S_IFCHR: case S_IFBLK:
894 tprintf("st_rdev=makedev(%lu, %lu), ",
895 (unsigned long) major(statbuf.st_rdev),
896 (unsigned long) minor(statbuf.st_rdev));
897 break;
898 default:
899 tprintf("st_size=%u, ", statbuf.st_size);
900 break;
901 }
902 if (!abbrev(tcp)) {
903 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
904 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100905 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200906 }
907 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200908 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200909}
Denys Vlasenko84703742012-02-25 02:38:52 +0100910#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200911
Roland McGratha4d48532005-06-08 20:45:28 +0000912static const struct xlat fileflags[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000913 { 0, NULL },
914};
915
John Hughes70623be2001-03-08 13:59:00 +0000916#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000917static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000918realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000919{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000920 if (!abbrev(tcp)) {
921 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
922 (unsigned long) major(statbuf->st_dev),
923 (unsigned long) minor(statbuf->st_dev),
924 (unsigned long) statbuf->st_ino,
925 sprintmode(statbuf->st_mode));
926 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
927 (unsigned long) statbuf->st_nlink,
928 (unsigned long) statbuf->st_uid,
929 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000930#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000931 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
932#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000933#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000934 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
935#endif
936 }
937 else
938 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
939 switch (statbuf->st_mode & S_IFMT) {
940 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000941#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000942 tprintf("st_rdev=makedev(%lu, %lu), ",
943 (unsigned long) major(statbuf->st_rdev),
944 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000945#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000946 tprintf("st_size=makedev(%lu, %lu), ",
947 (unsigned long) major(statbuf->st_size),
948 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000949#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000950 break;
951 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000952 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000953 break;
954 }
955 if (!abbrev(tcp)) {
956 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
957 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
958 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000959#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200960 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000961 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000962#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000963#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000964 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
965#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000966#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000967 tprintf(", st_level=%ld", statbuf->st_level);
968#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000969#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000970 tprintf(", st_fstype=%.*s",
971 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
972#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000973#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000974 tprintf(", st_gen=%u", statbuf->st_gen);
975#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200976 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000977 }
978 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200979 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000980}
981
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000982static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000983printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000984{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000985 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000986
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000987 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200988 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000989 return;
990 }
991 if (syserror(tcp) || !verbose(tcp)) {
992 tprintf("%#lx", addr);
993 return;
994 }
995
Denys Vlasenko9472a272013-02-12 11:43:46 +0100996#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000997 if (current_personality == 1) {
998 printstatsol(tcp, addr);
999 return;
1000 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001001#ifdef SPARC64
1002 else if (current_personality == 2) {
1003 printstat_sparc64(tcp, addr);
1004 return;
1005 }
1006#endif
Denys Vlasenko9472a272013-02-12 11:43:46 +01001007#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001008
Denys Vlasenko84703742012-02-25 02:38:52 +01001009#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +02001010 if (current_personality == 1) {
1011 printstat_powerpc32(tcp, addr);
1012 return;
1013 }
1014#endif
1015
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001016 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001017 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001018 return;
1019 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001020
1021 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001022}
John Hughes70623be2001-03-08 13:59:00 +00001023#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001024
Denys Vlasenko84703742012-02-25 02:38:52 +01001025#if !defined HAVE_STAT64 && defined X86_64
Roland McGrathe6d0f712007-08-07 01:22:49 +00001026/*
1027 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1028 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1029 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1030 * __GNUC__ is needed for the required __attribute__ below.
1031 */
1032struct stat64 {
1033 unsigned long long st_dev;
1034 unsigned char __pad0[4];
1035 unsigned int __st_ino;
1036 unsigned int st_mode;
1037 unsigned int st_nlink;
1038 unsigned int st_uid;
1039 unsigned int st_gid;
1040 unsigned long long st_rdev;
1041 unsigned char __pad3[4];
1042 long long st_size;
1043 unsigned int st_blksize;
1044 unsigned long long st_blocks;
1045 unsigned int st_atime;
1046 unsigned int st_atime_nsec;
1047 unsigned int st_mtime;
1048 unsigned int st_mtime_nsec;
1049 unsigned int st_ctime;
1050 unsigned int st_ctime_nsec;
1051 unsigned long long st_ino;
1052} __attribute__((packed));
1053# define HAVE_STAT64 1
1054# define STAT64_SIZE 96
1055#endif
1056
Wichert Akkermanc7926982000-04-10 22:22:31 +00001057#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001058static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001059printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001060{
1061 struct stat64 statbuf;
1062
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001063#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001064 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1065#endif
1066
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001067 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001068 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001069 return;
1070 }
1071 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001072 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001073 return;
1074 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001075
Denys Vlasenko9472a272013-02-12 11:43:46 +01001076#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001077 if (current_personality == 1) {
1078 printstatsol(tcp, addr);
1079 return;
1080 }
1081# ifdef SPARC64
1082 else if (current_personality == 2) {
1083 printstat_sparc64(tcp, addr);
1084 return;
1085 }
1086# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +01001087#endif /* SPARC[64] */
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001088
Denys Vlasenko84703742012-02-25 02:38:52 +01001089#if defined X86_64
H.J. Lu35be5812012-04-16 13:00:01 +02001090 if (current_personality != 1) {
Andreas Schwab61b74352009-10-16 11:37:13 +02001091 printstat(tcp, addr);
1092 return;
1093 }
1094#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +00001095
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001096 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001097 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001098 return;
1099 }
1100
1101 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001102#ifdef HAVE_LONG_LONG
1103 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1104#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001105 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001106#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001107 (unsigned long) major(statbuf.st_dev),
1108 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001109#ifdef HAVE_LONG_LONG
1110 (unsigned long long) statbuf.st_ino,
1111#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001112 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001113#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001114 sprintmode(statbuf.st_mode));
1115 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1116 (unsigned long) statbuf.st_nlink,
1117 (unsigned long) statbuf.st_uid,
1118 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001119#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001120 tprintf("st_blksize=%lu, ",
1121 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001122#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1123#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001124 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001125#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001126 }
1127 else
1128 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1129 switch (statbuf.st_mode & S_IFMT) {
1130 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001131#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001132 tprintf("st_rdev=makedev(%lu, %lu), ",
1133 (unsigned long) major(statbuf.st_rdev),
1134 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001135#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001136 tprintf("st_size=makedev(%lu, %lu), ",
1137 (unsigned long) major(statbuf.st_size),
1138 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001139#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001140 break;
1141 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001142#ifdef HAVE_LONG_LONG
1143 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1144#else
1145 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1146#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001147 break;
1148 }
1149 if (!abbrev(tcp)) {
1150 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1151 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001152 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001153#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001154 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001155 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001156#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001157#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001158 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1159#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001160#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001161 tprintf(", st_level=%ld", statbuf.st_level);
1162#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001163#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001164 tprintf(", st_fstype=%.*s",
1165 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1166#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001167#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001168 tprintf(", st_gen=%u", statbuf.st_gen);
1169#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001170 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001171 }
1172 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001173 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001174}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001175#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001176
Denys Vlasenko84703742012-02-25 02:38:52 +01001177#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001178static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001179convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001180{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001181 newbuf->st_dev = oldbuf->st_dev;
1182 newbuf->st_ino = oldbuf->st_ino;
1183 newbuf->st_mode = oldbuf->st_mode;
1184 newbuf->st_nlink = oldbuf->st_nlink;
1185 newbuf->st_uid = oldbuf->st_uid;
1186 newbuf->st_gid = oldbuf->st_gid;
1187 newbuf->st_rdev = oldbuf->st_rdev;
1188 newbuf->st_size = oldbuf->st_size;
1189 newbuf->st_atime = oldbuf->st_atime;
1190 newbuf->st_mtime = oldbuf->st_mtime;
1191 newbuf->st_ctime = oldbuf->st_ctime;
1192 newbuf->st_blksize = 0; /* not supported in old_stat */
1193 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001194}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001195
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001196static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001197printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001198{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001199 struct __old_kernel_stat statbuf;
1200 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001201
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001202 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001203 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001204 return;
1205 }
1206 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001207 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001208 return;
1209 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001210
Denys Vlasenko9472a272013-02-12 11:43:46 +01001211# if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001212 if (current_personality == 1) {
1213 printstatsol(tcp, addr);
1214 return;
1215 }
Denys Vlasenko84703742012-02-25 02:38:52 +01001216# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001217
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001218 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001219 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001220 return;
1221 }
1222
1223 convertoldstat(&statbuf, &newstatbuf);
1224 realprintstat(tcp, &newstatbuf);
1225}
Denys Vlasenko84703742012-02-25 02:38:52 +01001226#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001227
John Hughes70623be2001-03-08 13:59:00 +00001228#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001229int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001230sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001231{
1232 if (entering(tcp)) {
1233 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001234 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001235 } else {
1236 printstat(tcp, tcp->u_arg[1]);
1237 }
1238 return 0;
1239}
John Hughesb8c9f772001-03-07 16:53:07 +00001240#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001241
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001242int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001243sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001244{
1245#ifdef HAVE_STAT64
1246 if (entering(tcp)) {
1247 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001248 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001249 } else {
1250 printstat64(tcp, tcp->u_arg[1]);
1251 }
1252 return 0;
1253#else
1254 return printargs(tcp);
1255#endif
1256}
1257
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001258#ifndef AT_SYMLINK_NOFOLLOW
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001259# define AT_SYMLINK_NOFOLLOW 0x100
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001260#endif
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001261#ifndef AT_REMOVEDIR
1262# define AT_REMOVEDIR 0x200
1263#endif
1264#ifndef AT_SYMLINK_FOLLOW
1265# define AT_SYMLINK_FOLLOW 0x400
1266#endif
1267#ifndef AT_NO_AUTOMOUNT
1268# define AT_NO_AUTOMOUNT 0x800
1269#endif
1270#ifndef AT_EMPTY_PATH
1271# define AT_EMPTY_PATH 0x1000
1272#endif
1273
1274static const struct xlat at_flags[] = {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001275 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001276 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1277 { AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" },
1278 { AT_NO_AUTOMOUNT, "AT_NO_AUTOMOUNT" },
1279 { AT_EMPTY_PATH, "AT_EMPTY_PATH" },
1280 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001281};
1282
1283int
1284sys_newfstatat(struct tcb *tcp)
1285{
1286 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001287 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001288 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001289 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001290 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001291#ifdef POWERPC64
1292 if (current_personality == 0)
1293 printstat(tcp, tcp->u_arg[2]);
1294 else
1295 printstat64(tcp, tcp->u_arg[2]);
1296#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001297 printstat64(tcp, tcp->u_arg[2]);
1298#else
1299 printstat(tcp, tcp->u_arg[2]);
1300#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001301 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001302 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001303 }
1304 return 0;
1305}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001306
Denys Vlasenko84703742012-02-25 02:38:52 +01001307#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001308int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001309sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001310{
1311 if (entering(tcp)) {
1312 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001313 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001314 } else {
1315 printoldstat(tcp, tcp->u_arg[1]);
1316 }
1317 return 0;
1318}
Denys Vlasenko84703742012-02-25 02:38:52 +01001319#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001320
John Hughes70623be2001-03-08 13:59:00 +00001321#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001322int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001323sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001324{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001325 if (entering(tcp)) {
1326 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001327 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001328 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001329 printstat(tcp, tcp->u_arg[1]);
1330 }
1331 return 0;
1332}
John Hughesb8c9f772001-03-07 16:53:07 +00001333#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001334
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001335int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001336sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001337{
1338#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001339 if (entering(tcp)) {
1340 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001341 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001342 } else {
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001343 printstat64(tcp, tcp->u_arg[1]);
1344 }
1345 return 0;
1346#else
1347 return printargs(tcp);
1348#endif
1349}
1350
Denys Vlasenko84703742012-02-25 02:38:52 +01001351#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001352int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001353sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001354{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001355 if (entering(tcp)) {
1356 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001357 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001358 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001359 printoldstat(tcp, tcp->u_arg[1]);
1360 }
1361 return 0;
1362}
Denys Vlasenko84703742012-02-25 02:38:52 +01001363#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001364
John Hughes70623be2001-03-08 13:59:00 +00001365#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001366int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001367sys_lstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001368{
1369 if (entering(tcp)) {
1370 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001371 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001372 } else {
1373 printstat(tcp, tcp->u_arg[1]);
1374 }
1375 return 0;
1376}
John Hughesb8c9f772001-03-07 16:53:07 +00001377#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001378
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001379int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001380sys_lstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001381{
1382#ifdef HAVE_STAT64
1383 if (entering(tcp)) {
1384 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001385 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001386 } else {
1387 printstat64(tcp, tcp->u_arg[1]);
1388 }
1389 return 0;
1390#else
1391 return printargs(tcp);
1392#endif
1393}
1394
Denys Vlasenko84703742012-02-25 02:38:52 +01001395#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001396int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001397sys_oldlstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001398{
1399 if (entering(tcp)) {
1400 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001401 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001402 } else {
1403 printoldstat(tcp, tcp->u_arg[1]);
1404 }
1405 return 0;
1406}
Denys Vlasenko84703742012-02-25 02:38:52 +01001407#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001408
Denys Vlasenko9472a272013-02-12 11:43:46 +01001409#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001410
1411int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001412sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413{
1414 if (entering(tcp)) {
1415 tprintf("%ld, ", tcp->u_arg[0]);
1416 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001417 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001418 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001419# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001420 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001421 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001422 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001423# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001424 printstat(tcp, tcp->u_arg[2]);
1425 }
1426 return 0;
1427}
1428
1429int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001430sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001431{
1432 if (entering(tcp))
1433 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1434 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001435# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001436 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001437 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001438 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001439# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001440 printstat(tcp, tcp->u_arg[2]);
1441 }
1442 return 0;
1443}
1444
1445int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001446sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001447{
1448 if (entering(tcp)) {
1449 tprintf("%ld, ", tcp->u_arg[0]);
1450 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001451 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001452 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001453# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001454 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001455 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001456 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001457# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001458 printstat(tcp, tcp->u_arg[2]);
1459 }
1460 return 0;
1461}
1462
1463int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001464sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001465{
1466 int mode = tcp->u_arg[2];
1467
1468 if (entering(tcp)) {
1469 tprintf("%ld, ", tcp->u_arg[0]);
1470 printpath(tcp, tcp->u_arg[1]);
1471 tprintf(", %s", sprintmode(mode));
1472 switch (mode & S_IFMT) {
1473 case S_IFCHR: case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001474 tprintf(", makedev(%lu, %lu)",
1475 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1476 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001477 break;
1478 default:
1479 break;
1480 }
1481 }
1482 return 0;
1483}
1484
Denys Vlasenko84703742012-02-25 02:38:52 +01001485# ifdef HAVE_SYS_ACL_H
Wichert Akkerman8829a551999-06-11 13:18:40 +00001486
Denys Vlasenko84703742012-02-25 02:38:52 +01001487# include <sys/acl.h>
Wichert Akkerman8829a551999-06-11 13:18:40 +00001488
Roland McGratha4d48532005-06-08 20:45:28 +00001489static const struct xlat aclcmds[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001490# ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001491 { SETACL, "SETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001492# endif
1493# ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001494 { GETACL, "GETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001495# endif
1496# ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001497 { GETACLCNT, "GETACLCNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001498# endif
1499# ifdef ACL_GET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001500 { ACL_GET, "ACL_GET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001501# endif
1502# ifdef ACL_SET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001503 { ACL_SET, "ACL_SET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001504# endif
1505# ifdef ACL_CNT
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001506 { ACL_CNT, "ACL_CNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001507# endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001508 { 0, NULL },
1509};
1510
1511int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001512sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001513{
1514 if (entering(tcp)) {
1515 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001516 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001517 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1518 tprintf(", %ld", tcp->u_arg[2]);
1519 /*
1520 * FIXME - dump out the list of aclent_t's pointed to
1521 * by "tcp->u_arg[3]" if it's not NULL.
1522 */
1523 if (tcp->u_arg[3])
1524 tprintf(", %#lx", tcp->u_arg[3]);
1525 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001526 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001527 }
1528 return 0;
1529}
1530
Wichert Akkerman8829a551999-06-11 13:18:40 +00001531int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001532sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001533{
1534 if (entering(tcp)) {
1535 tprintf("%ld, ", tcp->u_arg[0]);
1536 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1537 tprintf(", %ld", tcp->u_arg[2]);
1538 /*
1539 * FIXME - dump out the list of aclent_t's pointed to
1540 * by "tcp->u_arg[3]" if it's not NULL.
1541 */
1542 if (tcp->u_arg[3])
1543 tprintf(", %#lx", tcp->u_arg[3]);
1544 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001545 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001546 }
1547 return 0;
1548}
1549
Roland McGratha4d48532005-06-08 20:45:28 +00001550static const struct xlat aclipc[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001551# ifdef IPC_SHM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001552 { IPC_SHM, "IPC_SHM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001553# endif
1554# ifdef IPC_SEM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001555 { IPC_SEM, "IPC_SEM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001556# endif
1557# ifdef IPC_MSG
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001558 { IPC_MSG, "IPC_MSG" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001559# endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001560 { 0, NULL },
1561};
1562
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001563int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001564sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001565{
1566 if (entering(tcp)) {
1567 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1568 tprintf(", %#lx, ", tcp->u_arg[1]);
1569 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1570 tprintf(", %ld", tcp->u_arg[3]);
1571 /*
1572 * FIXME - dump out the list of aclent_t's pointed to
1573 * by "tcp->u_arg[4]" if it's not NULL.
1574 */
1575 if (tcp->u_arg[4])
1576 tprintf(", %#lx", tcp->u_arg[4]);
1577 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001578 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001579 }
1580 return 0;
1581}
1582
Denys Vlasenko84703742012-02-25 02:38:52 +01001583# endif /* HAVE_SYS_ACL_H */
Wichert Akkerman8829a551999-06-11 13:18:40 +00001584
Denys Vlasenko9472a272013-02-12 11:43:46 +01001585#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001586
Roland McGrathd9f816f2004-09-04 03:39:20 +00001587static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001588 { 0x73757245, "CODA_SUPER_MAGIC" },
1589 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1590 { 0x1373, "DEVFS_SUPER_MAGIC" },
1591 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1592 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001593 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1594 { 0xef53, "EXT2_SUPER_MAGIC" },
1595 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001596 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001597 { 0x9660, "ISOFS_SUPER_MAGIC" },
1598 { 0x137f, "MINIX_SUPER_MAGIC" },
1599 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001600 { 0x2468, "MINIX2_SUPER_MAGIC" },
1601 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001602 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001603 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001604 { 0x6969, "NFS_SUPER_MAGIC" },
1605 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001606 { 0x002f, "QNX4_SUPER_MAGIC" },
1607 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1608 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1609 { 0x517b, "SMB_SUPER_MAGIC" },
1610 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1611 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1612 { 0x00011954, "UFS_MAGIC" },
1613 { 0x54190100, "UFS_CIGAM" },
1614 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001615 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001616 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001617 { 0, NULL },
1618};
1619
Roland McGrathf9c49b22004-10-06 22:11:54 +00001620static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001621sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001622{
1623 static char buf[32];
Roland McGrathf9c49b22004-10-06 22:11:54 +00001624 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001625
1626 s = xlookup(fsmagic, magic);
1627 if (s) {
1628 sprintf(buf, "\"%s\"", s);
1629 return buf;
1630 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001631 sprintf(buf, "%#x", magic);
1632 return buf;
1633}
1634
1635static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001636printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001637{
1638 struct statfs statbuf;
1639
1640 if (syserror(tcp) || !verbose(tcp)) {
1641 tprintf("%#lx", addr);
1642 return;
1643 }
1644 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001645 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001646 return;
1647 }
1648#ifdef ALPHA
1649
1650 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1651 sprintfstype(statbuf.f_type),
1652 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001653 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001654 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001655 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1656 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001657#else /* !ALPHA */
1658 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1659 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001660 (unsigned long)statbuf.f_bsize,
1661 (unsigned long)statbuf.f_blocks,
1662 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001663 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1664 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001665 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001666 (unsigned long)statbuf.f_ffree,
1667 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001668 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001669#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001670#ifdef _STATFS_F_FRSIZE
1671 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1672#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001673 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001674}
1675
1676int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001677sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001678{
1679 if (entering(tcp)) {
1680 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001681 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001682 } else {
1683 printstatfs(tcp, tcp->u_arg[1]);
1684 }
1685 return 0;
1686}
1687
1688int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001689sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001690{
1691 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001692 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001693 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001694 } else {
1695 printstatfs(tcp, tcp->u_arg[1]);
1696 }
1697 return 0;
1698}
1699
Denys Vlasenko84703742012-02-25 02:38:52 +01001700#if defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001701static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001702printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001703{
1704 struct statfs64 statbuf;
1705
1706 if (syserror(tcp) || !verbose(tcp)) {
1707 tprintf("%#lx", addr);
1708 return;
1709 }
1710 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001711 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001712 return;
1713 }
Roland McGrath08738432005-06-03 02:40:39 +00001714 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001715 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001716 (unsigned long long)statbuf.f_bsize,
1717 (unsigned long long)statbuf.f_blocks,
1718 (unsigned long long)statbuf.f_bfree);
1719 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1720 (unsigned long long)statbuf.f_bavail,
1721 (unsigned long long)statbuf.f_files,
1722 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001723 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1724 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001725#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001726 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001727#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001728#ifdef _STATFS_F_FLAGS
1729 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1730#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001731 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001732}
1733
Andreas Schwab7d558012012-01-17 18:14:22 +01001734struct compat_statfs64 {
1735 uint32_t f_type;
1736 uint32_t f_bsize;
1737 uint64_t f_blocks;
1738 uint64_t f_bfree;
1739 uint64_t f_bavail;
1740 uint64_t f_files;
1741 uint64_t f_ffree;
1742 fsid_t f_fsid;
1743 uint32_t f_namelen;
1744 uint32_t f_frsize;
1745 uint32_t f_flags;
1746 uint32_t f_spare[4];
1747}
1748#if defined(X86_64) || defined(IA64)
1749 __attribute__ ((packed, aligned(4)))
1750#endif
1751;
1752
1753static void
1754printcompat_statfs64(struct tcb *tcp, long addr)
1755{
1756 struct compat_statfs64 statbuf;
1757
1758 if (syserror(tcp) || !verbose(tcp)) {
1759 tprintf("%#lx", addr);
1760 return;
1761 }
1762 if (umove(tcp, addr, &statbuf) < 0) {
1763 tprints("{...}");
1764 return;
1765 }
1766 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1767 sprintfstype(statbuf.f_type),
1768 (unsigned long)statbuf.f_bsize,
1769 (unsigned long long)statbuf.f_blocks,
1770 (unsigned long long)statbuf.f_bfree);
1771 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1772 (unsigned long long)statbuf.f_bavail,
1773 (unsigned long long)statbuf.f_files,
1774 (unsigned long long)statbuf.f_ffree,
1775 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1776 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1777 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001778 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
Andreas Schwab7d558012012-01-17 18:14:22 +01001779}
1780
Roland McGrathab147c52003-07-17 09:03:02 +00001781int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001782sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001783{
1784 if (entering(tcp)) {
1785 printpath(tcp, tcp->u_arg[0]);
1786 tprintf(", %lu, ", tcp->u_arg[1]);
1787 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001788 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001789 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001790 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1791 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001792 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001793 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001794 }
1795 return 0;
1796}
1797
1798int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001799sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001800{
1801 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001802 printfd(tcp, tcp->u_arg[0]);
1803 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001804 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001805 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001806 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001807 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1808 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001809 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001810 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001811 }
1812 return 0;
1813}
1814#endif
1815
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001816#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001817int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001818osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001819{
1820 if (entering(tcp)) {
1821 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001822 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001823 } else {
1824 printstatfs(tcp, tcp->u_arg[1]);
1825 tprintf(", %lu", tcp->u_arg[2]);
1826 }
1827 return 0;
1828}
1829
1830int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001831osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001832{
1833 if (entering(tcp)) {
1834 tprintf("%lu, ", tcp->u_arg[0]);
1835 } else {
1836 printstatfs(tcp, tcp->u_arg[1]);
1837 tprintf(", %lu", tcp->u_arg[2]);
1838 }
1839 return 0;
1840}
Denys Vlasenko84703742012-02-25 02:38:52 +01001841#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001842
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001843/* directory */
1844int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001845sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001846{
1847 if (entering(tcp)) {
1848 printpath(tcp, tcp->u_arg[0]);
1849 }
1850 return 0;
1851}
1852
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001853static int
1854decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001855{
1856 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001857 printpath(tcp, tcp->u_arg[offset]);
1858 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001859 }
1860 return 0;
1861}
1862
1863int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001864sys_mkdir(struct tcb *tcp)
1865{
1866 return decode_mkdir(tcp, 0);
1867}
1868
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001869int
1870sys_mkdirat(struct tcb *tcp)
1871{
1872 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001873 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001874 return decode_mkdir(tcp, 1);
1875}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001876
1877int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001878sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001879{
1880 if (entering(tcp)) {
1881 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001882 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001883 printpath(tcp, tcp->u_arg[1]);
1884 }
1885 return 0;
1886}
1887
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001888int
1889sys_linkat(struct tcb *tcp)
1890{
1891 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001892 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001893 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001894 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001895 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001896 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001897 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001898 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001899 }
1900 return 0;
1901}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001902
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001903int
1904sys_unlinkat(struct tcb *tcp)
1905{
1906 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001907 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001908 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001909 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001910 printflags(at_flags, tcp->u_arg[2], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001911 }
1912 return 0;
1913}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001914
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001915int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001916sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001917{
1918 if (entering(tcp)) {
1919 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001920 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001921 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001922 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001923 }
1924 return 0;
1925}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001926
1927static int
1928decode_readlink(struct tcb *tcp, int offset)
1929{
1930 if (entering(tcp)) {
1931 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001932 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001933 } else {
1934 if (syserror(tcp))
1935 tprintf("%#lx", tcp->u_arg[offset + 1]);
1936 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001937 /* Used to use printpathn(), but readlink
1938 * neither includes NUL in the returned count,
1939 * nor actually writes it into memory.
1940 * printpathn() would decide on printing
1941 * "..." continuation based on garbage
1942 * past return buffer's end.
1943 */
1944 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001945 tprintf(", %lu", tcp->u_arg[offset + 2]);
1946 }
1947 return 0;
1948}
1949
1950int
1951sys_readlink(struct tcb *tcp)
1952{
1953 return decode_readlink(tcp, 0);
1954}
1955
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001956int
1957sys_readlinkat(struct tcb *tcp)
1958{
1959 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001960 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001961 return decode_readlink(tcp, 1);
1962}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001963
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001964int
1965sys_renameat(struct tcb *tcp)
1966{
1967 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001968 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001969 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001970 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001971 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001972 printpath(tcp, tcp->u_arg[3]);
1973 }
1974 return 0;
1975}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001976
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001977int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001978sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001979{
1980 if (entering(tcp)) {
1981 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001982 printuid(", ", tcp->u_arg[1]);
1983 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001984 }
1985 return 0;
1986}
1987
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001988int
1989sys_fchownat(struct tcb *tcp)
1990{
1991 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001992 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001993 printpath(tcp, tcp->u_arg[1]);
1994 printuid(", ", tcp->u_arg[2]);
1995 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001996 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001997 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001998 }
1999 return 0;
2000}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002001
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002002int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002003sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002004{
2005 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002006 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002007 printuid(", ", tcp->u_arg[1]);
2008 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002009 }
2010 return 0;
2011}
2012
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002013static int
2014decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002015{
2016 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002017 printpath(tcp, tcp->u_arg[offset]);
2018 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002019 }
2020 return 0;
2021}
2022
2023int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002024sys_chmod(struct tcb *tcp)
2025{
2026 return decode_chmod(tcp, 0);
2027}
2028
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002029int
2030sys_fchmodat(struct tcb *tcp)
2031{
2032 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002033 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002034 return decode_chmod(tcp, 1);
2035}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002036
2037int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002038sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002039{
2040 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002041 printfd(tcp, tcp->u_arg[0]);
2042 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002043 }
2044 return 0;
2045}
2046
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002047#ifdef ALPHA
2048int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002049sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002050{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002051 if (entering(tcp)) {
2052 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002053 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002054 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2055 }
2056 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002057}
2058#endif
2059
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002060static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002061decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002062{
2063 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002064 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002065 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002066 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002067 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00002068 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002069 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00002070 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2071 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002072 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002073 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002074 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00002075 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002076 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00002077 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002078 }
2079 return 0;
2080}
2081
2082int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002083sys_utimes(struct tcb *tcp)
2084{
Roland McGrath6afc5652007-07-24 01:57:11 +00002085 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002086}
2087
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002088int
2089sys_futimesat(struct tcb *tcp)
2090{
2091 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002092 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002093 return decode_utimes(tcp, 1, 0);
2094}
2095
2096int
2097sys_utimensat(struct tcb *tcp)
2098{
2099 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002100 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002101 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002102 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00002103 printflags(at_flags, tcp->u_arg[3], "AT_???");
Roland McGrath6afc5652007-07-24 01:57:11 +00002104 }
2105 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002106}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002107
2108int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002109sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002110{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002111 union {
2112 long utl[2];
2113 int uti[2];
Denys Vlasenko751acb32013-02-08 15:34:46 +01002114 long paranoia_for_huge_wordsize[4];
Roland McGrath7e9817c2007-07-05 20:31:58 +00002115 } u;
Denys Vlasenko751acb32013-02-08 15:34:46 +01002116 unsigned wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002117
2118 if (entering(tcp)) {
2119 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002120 tprints(", ");
Denys Vlasenko751acb32013-02-08 15:34:46 +01002121
2122 wordsize = current_wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002123 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002124 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002125 else if (!verbose(tcp))
2126 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002127 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002128 tprints("[?, ?]");
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002129 else if (wordsize == sizeof u.utl[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002130 tprintf("[%s,", sprinttime(u.utl[0]));
2131 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002132 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002133 else if (wordsize == sizeof u.uti[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002134 tprintf("[%s,", sprinttime(u.uti[0]));
2135 tprintf(" %s]", sprinttime(u.uti[1]));
2136 }
2137 else
Denys Vlasenko751acb32013-02-08 15:34:46 +01002138 tprintf("<decode error: unsupported wordsize %d>",
2139 wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002140 }
2141 return 0;
2142}
2143
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002144static int
2145decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002146{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002147 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002148
2149 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002150 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002151 tprintf(", %s", sprintmode(mode));
2152 switch (mode & S_IFMT) {
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002153 case S_IFCHR:
2154 case S_IFBLK:
Denys Vlasenko9472a272013-02-12 11:43:46 +01002155#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002156 if (current_personality == 1)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002157 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002158 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2159 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002160 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002161#endif
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002162 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002163 (unsigned long) major(tcp->u_arg[offset + 2]),
2164 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002165 break;
2166 default:
2167 break;
2168 }
2169 }
2170 return 0;
2171}
2172
2173int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002174sys_mknod(struct tcb *tcp)
2175{
2176 return decode_mknod(tcp, 0);
2177}
2178
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002179int
2180sys_mknodat(struct tcb *tcp)
2181{
2182 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002183 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002184 return decode_mknod(tcp, 1);
2185}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002186
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002187static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002188printdir(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002189{
2190 struct dirent d;
2191
2192 if (!verbose(tcp)) {
2193 tprintf("%#lx", addr);
2194 return;
2195 }
2196 if (umove(tcp, addr, &d) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002197 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002198 return;
2199 }
2200 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002201 tprints("d_name=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002202 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002203 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002204}
2205
2206int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002207sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002208{
2209 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002210 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002211 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002212 } else {
2213 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2214 tprintf("%#lx", tcp->u_arg[1]);
2215 else
2216 printdir(tcp, tcp->u_arg[1]);
2217 /* Not much point in printing this out, it is always 1. */
2218 if (tcp->u_arg[2] != 1)
2219 tprintf(", %lu", tcp->u_arg[2]);
2220 }
2221 return 0;
2222}
2223
Roland McGratha4d48532005-06-08 20:45:28 +00002224static const struct xlat direnttypes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002225 { DT_UNKNOWN, "DT_UNKNOWN" },
2226 { DT_FIFO, "DT_FIFO" },
2227 { DT_CHR, "DT_CHR" },
2228 { DT_DIR, "DT_DIR" },
2229 { DT_BLK, "DT_BLK" },
2230 { DT_REG, "DT_REG" },
2231 { DT_LNK, "DT_LNK" },
2232 { DT_SOCK, "DT_SOCK" },
2233 { DT_WHT, "DT_WHT" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002234 { 0, NULL },
2235};
2236
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002237int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002238sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002239{
2240 int i, len, dents = 0;
2241 char *buf;
2242
2243 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002244 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002245 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002246 return 0;
2247 }
2248 if (syserror(tcp) || !verbose(tcp)) {
2249 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2250 return 0;
2251 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002252 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002253 /* Beware of insanely large or negative values in tcp->u_rval */
2254 if (tcp->u_rval > 1024*1024)
2255 len = 1024*1024;
2256 if (tcp->u_rval < 0)
2257 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002258 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002259 if (len && !buf)
2260 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002261 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002262 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002263 free(buf);
2264 return 0;
2265 }
2266 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002267 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002268 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002269 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002270 if (!abbrev(tcp)) {
2271 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2272 i ? " " : "", d->d_ino, d->d_off);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002273 tprintf("d_reclen=%u, d_name=\"%s\", d_type=",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002274 d->d_reclen, d->d_name);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002275 printxval(direnttypes, buf[i + d->d_reclen - 1], "DT_???");
2276 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002277 }
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002278 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002279 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002280 break;
2281 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002282 i += d->d_reclen;
2283 dents++;
2284 }
2285 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002286 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002287 else
2288 tprintf("/* %u entries */", dents);
2289 tprintf(", %lu", tcp->u_arg[2]);
2290 free(buf);
2291 return 0;
2292}
2293
John Hughesbdf48f52001-03-06 15:08:09 +00002294#if _LFS64_LARGEFILE
2295int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002296sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002297{
2298 int i, len, dents = 0;
2299 char *buf;
2300
2301 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002302 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002303 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002304 return 0;
2305 }
2306 if (syserror(tcp) || !verbose(tcp)) {
2307 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2308 return 0;
2309 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002310
John Hughesbdf48f52001-03-06 15:08:09 +00002311 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002312 /* Beware of insanely large or negative tcp->u_rval */
2313 if (tcp->u_rval > 1024*1024)
2314 len = 1024*1024;
2315 if (tcp->u_rval < 0)
2316 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002317 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002318 if (len && !buf)
2319 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002320
John Hughesbdf48f52001-03-06 15:08:09 +00002321 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002322 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002323 free(buf);
2324 return 0;
2325 }
2326 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002327 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002328 for (i = 0; i < len;) {
2329 struct dirent64 *d = (struct dirent64 *) &buf[i];
John Hughesbdf48f52001-03-06 15:08:09 +00002330 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002331 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002332 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002333 d->d_ino,
2334 d->d_off);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002335 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002336 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002337 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002338 tprintf("d_reclen=%u, d_name=\"%s\"}",
2339 d->d_reclen, d->d_name);
2340 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002341 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002342 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002343 break;
2344 }
John Hughesbdf48f52001-03-06 15:08:09 +00002345 i += d->d_reclen;
2346 dents++;
2347 }
2348 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002349 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002350 else
2351 tprintf("/* %u entries */", dents);
2352 tprintf(", %lu", tcp->u_arg[2]);
2353 free(buf);
2354 return 0;
2355}
2356#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002357
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002358int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002359sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002360{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002361 if (exiting(tcp)) {
2362 if (syserror(tcp))
2363 tprintf("%#lx", tcp->u_arg[0]);
2364 else
2365 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2366 tprintf(", %lu", tcp->u_arg[1]);
2367 }
2368 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002369}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002370
2371#ifdef HAVE_SYS_ASYNCH_H
2372
2373int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002374sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002375{
2376 struct aio_result_t res;
2377
2378 if (entering(tcp)) {
2379 tprintf("%lu, ", tcp->u_arg[0]);
2380 } else {
2381 if (syserror(tcp))
2382 tprintf("%#lx", tcp->u_arg[1]);
2383 else
2384 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2385 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2386 printxval(whence, tcp->u_arg[4], "L_???");
2387 if (syserror(tcp) || tcp->u_arg[5] == 0
2388 || umove(tcp, tcp->u_arg[5], &res) < 0)
2389 tprintf(", %#lx", tcp->u_arg[5]);
2390 else
2391 tprintf(", {aio_return %d aio_errno %d}",
2392 res.aio_return, res.aio_errno);
2393 }
2394 return 0;
2395}
2396
2397int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002398sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002399{
2400 struct aio_result_t res;
2401
2402 if (entering(tcp)) {
2403 tprintf("%lu, ", tcp->u_arg[0]);
2404 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2405 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2406 printxval(whence, tcp->u_arg[4], "L_???");
2407 }
2408 else {
2409 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002410 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002411 else if (syserror(tcp)
2412 || umove(tcp, tcp->u_arg[5], &res) < 0)
2413 tprintf(", %#lx", tcp->u_arg[5]);
2414 else
2415 tprintf(", {aio_return %d aio_errno %d}",
2416 res.aio_return, res.aio_errno);
2417 }
2418 return 0;
2419}
2420
2421int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002422sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002423{
2424 if (entering(tcp))
2425 printtv(tcp, tcp->u_arg[0]);
2426 return 0;
2427}
2428
2429int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002430sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002431{
2432 struct aio_result_t res;
2433
2434 if (exiting(tcp)) {
2435 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002436 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002437 else if (syserror(tcp)
2438 || umove(tcp, tcp->u_arg[0], &res) < 0)
2439 tprintf("%#lx", tcp->u_arg[0]);
2440 else
2441 tprintf("{aio_return %d aio_errno %d}",
2442 res.aio_return, res.aio_errno);
2443 }
2444 return 0;
2445}
2446
2447#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002448
Roland McGratha4d48532005-06-08 20:45:28 +00002449static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002450#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002451 { XATTR_CREATE, "XATTR_CREATE" },
2452 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002453#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002454 { 0, NULL }
2455};
2456
Roland McGrath3292e222004-08-31 06:30:48 +00002457static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002458print_xattr_val(struct tcb *tcp, int failed,
2459 unsigned long arg,
2460 unsigned long insize,
2461 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002462{
Dmitry V. Levin1f215132012-12-07 21:38:52 +00002463 if (insize == 0)
2464 failed = 1;
Denys Vlasenko1d632462009-04-14 12:51:00 +00002465 if (!failed) {
2466 unsigned long capacity = 4 * size + 1;
2467 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2468 if (buf == NULL || /* probably a bogus size argument */
2469 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2470 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002471 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002472 else {
2473 unsigned char *out = buf;
2474 unsigned char *in = &buf[3 * size];
2475 size_t i;
2476 for (i = 0; i < size; ++i) {
2477 if (isprint(in[i]))
2478 *out++ = in[i];
2479 else {
2480#define tohex(n) "0123456789abcdef"[n]
2481 *out++ = '\\';
2482 *out++ = 'x';
2483 *out++ = tohex(in[i] / 16);
2484 *out++ = tohex(in[i] % 16);
2485 }
2486 }
2487 /* Don't print terminating NUL if there is one. */
2488 if (i > 0 && in[i - 1] == '\0')
2489 out -= 4;
2490 *out = '\0';
2491 tprintf(", \"%s\", %ld", buf, insize);
2492 }
2493 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002494 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002495 if (failed)
2496 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002497}
2498
Roland McGrath186c5ac2002-12-15 23:58:23 +00002499int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002500sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002501{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002502 if (entering(tcp)) {
2503 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002504 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002505 printstr(tcp, tcp->u_arg[1], -1);
2506 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002507 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002508 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2509 }
2510 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002511}
2512
2513int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002514sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002515{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002516 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002517 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002518 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002519 printstr(tcp, tcp->u_arg[1], -1);
2520 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002521 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002522 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2523 }
2524 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002525}
2526
2527int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002528sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002529{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002530 if (entering(tcp)) {
2531 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002532 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002533 printstr(tcp, tcp->u_arg[1], -1);
2534 } else {
2535 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2536 tcp->u_rval);
2537 }
2538 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002539}
2540
2541int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002542sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002543{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002544 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002545 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002546 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002547 printstr(tcp, tcp->u_arg[1], -1);
2548 } else {
2549 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2550 tcp->u_rval);
2551 }
2552 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002553}
2554
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002555static void
2556print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2557{
2558 if (syserror(tcp)) {
2559 tprintf("%#lx", addr);
2560 } else {
2561 if (!addr) {
2562 tprints("NULL");
2563 } else {
2564 unsigned long len =
2565 (size < tcp->u_rval) ? size : tcp->u_rval;
2566 printstr(tcp, addr, len);
2567 }
2568 }
2569 tprintf(", %lu", size);
2570}
2571
Roland McGrath186c5ac2002-12-15 23:58:23 +00002572int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002573sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002574{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002575 if (entering(tcp)) {
2576 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002577 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002578 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002579 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002580 }
2581 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002582}
2583
2584int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002585sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002586{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002587 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002588 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002589 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002590 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002591 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002592 }
2593 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002594}
2595
2596int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002597sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002598{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002599 if (entering(tcp)) {
2600 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002601 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002602 printstr(tcp, tcp->u_arg[1], -1);
2603 }
2604 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002605}
2606
2607int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002608sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002609{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002610 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002611 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002612 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002613 printstr(tcp, tcp->u_arg[1], -1);
2614 }
2615 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002616}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002617
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002618static const struct xlat advise[] = {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002619 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2620 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2621 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2622 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2623 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2624 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2625 { 0, NULL }
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002626};
2627
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002628int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002629sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002630{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002631 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002632 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002633 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002634 argn = printllval(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002635 tprintf(", %ld, ", tcp->u_arg[argn++]);
2636 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002637 }
2638 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002639}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002640
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002641int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002642sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002643{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002644 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002645 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002646 printfd(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002647#if defined ARM || defined POWERPC
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002648 argn = printllval(tcp, ", %lld, ", 2);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002649#else
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002650 argn = printllval(tcp, ", %lld, ", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002651#endif
2652 argn = printllval(tcp, "%lld, ", argn);
2653#if defined ARM || defined POWERPC
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002654 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002655#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002656 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002657#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002658 }
2659 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002660}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002661
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002662static const struct xlat inotify_modes[] = {
Dmitry V. Levind475c062011-03-03 01:02:41 +00002663 { 0x00000001, "IN_ACCESS" },
2664 { 0x00000002, "IN_MODIFY" },
2665 { 0x00000004, "IN_ATTRIB" },
2666 { 0x00000008, "IN_CLOSE_WRITE"},
2667 { 0x00000010, "IN_CLOSE_NOWRITE"},
2668 { 0x00000020, "IN_OPEN" },
2669 { 0x00000040, "IN_MOVED_FROM" },
2670 { 0x00000080, "IN_MOVED_TO" },
2671 { 0x00000100, "IN_CREATE" },
2672 { 0x00000200, "IN_DELETE" },
2673 { 0x00000400, "IN_DELETE_SELF"},
2674 { 0x00000800, "IN_MOVE_SELF" },
2675 { 0x00002000, "IN_UNMOUNT" },
2676 { 0x00004000, "IN_Q_OVERFLOW" },
2677 { 0x00008000, "IN_IGNORED" },
2678 { 0x01000000, "IN_ONLYDIR" },
2679 { 0x02000000, "IN_DONT_FOLLOW"},
2680 { 0x20000000, "IN_MASK_ADD" },
2681 { 0x40000000, "IN_ISDIR" },
2682 { 0x80000000, "IN_ONESHOT" },
2683 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002684};
2685
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002686static const struct xlat inotify_init_flags[] = {
2687 { 0x00000800, "IN_NONBLOCK" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002688 { 0x00080000, "IN_CLOEXEC" },
2689 { 0, NULL }
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002690};
2691
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002692int
2693sys_inotify_add_watch(struct tcb *tcp)
2694{
2695 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002696 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002697 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002698 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002699 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002700 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2701 }
2702 return 0;
2703}
2704
2705int
2706sys_inotify_rm_watch(struct tcb *tcp)
2707{
2708 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002709 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levinab1a70c2012-03-11 15:33:34 +00002710 tprintf(", %d", (int) tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002711 }
2712 return 0;
2713}
Roland McGrath96a96612008-05-20 04:56:18 +00002714
2715int
Mark Wielaardbab89402010-03-21 14:41:26 +01002716sys_inotify_init1(struct tcb *tcp)
2717{
2718 if (entering(tcp))
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002719 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
Mark Wielaardbab89402010-03-21 14:41:26 +01002720 return 0;
2721}
2722
2723int
Roland McGrath96a96612008-05-20 04:56:18 +00002724sys_fallocate(struct tcb *tcp)
2725{
2726 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002727 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002728 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002729 tprintf(", %#lo, ", tcp->u_arg[1]); /* mode */
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002730 argn = printllval(tcp, "%llu, ", 2); /* offset */
2731 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002732 }
2733 return 0;
2734}
Dmitry V. Levin88293652012-03-09 21:02:19 +00002735
Dmitry V. Levinad0c01e2012-03-15 00:52:22 +00002736#ifndef SWAP_FLAG_PREFER
2737# define SWAP_FLAG_PREFER 0x8000
2738#endif
2739#ifndef SWAP_FLAG_DISCARD
2740# define SWAP_FLAG_DISCARD 0x10000
2741#endif
Dmitry V. Levin88293652012-03-09 21:02:19 +00002742static const struct xlat swap_flags[] = {
2743 { SWAP_FLAG_PREFER, "SWAP_FLAG_PREFER" },
2744 { SWAP_FLAG_DISCARD, "SWAP_FLAG_DISCARD" },
2745 { 0, NULL }
2746};
2747
2748int
2749sys_swapon(struct tcb *tcp)
2750{
2751 if (entering(tcp)) {
2752 int flags = tcp->u_arg[1];
2753 printpath(tcp, tcp->u_arg[0]);
2754 tprints(", ");
2755 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2756 "SWAP_FLAG_???");
2757 if (flags & SWAP_FLAG_PREFER)
2758 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);
2759 }
2760 return 0;
2761}
H.J. Lu085e4282012-04-17 11:05:04 -07002762
2763#ifdef X32
2764# undef stat64
2765# undef sys_fstat64
2766# undef sys_stat64
2767
2768static void
2769realprintstat64(struct tcb *tcp, long addr)
2770{
2771 struct stat64 statbuf;
2772
2773 if (!addr) {
2774 tprints("NULL");
2775 return;
2776 }
2777 if (syserror(tcp) || !verbose(tcp)) {
2778 tprintf("%#lx", addr);
2779 return;
2780 }
2781
2782 if (umove(tcp, addr, &statbuf) < 0) {
2783 tprints("{...}");
2784 return;
2785 }
2786
2787 if (!abbrev(tcp)) {
2788 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
2789 (unsigned long) major(statbuf.st_dev),
2790 (unsigned long) minor(statbuf.st_dev),
2791 (unsigned long long) statbuf.st_ino,
2792 sprintmode(statbuf.st_mode));
2793 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
2794 (unsigned long) statbuf.st_nlink,
2795 (unsigned long) statbuf.st_uid,
2796 (unsigned long) statbuf.st_gid);
2797 tprintf("st_blksize=%lu, ",
2798 (unsigned long) statbuf.st_blksize);
2799 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
2800 }
2801 else
2802 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
2803 switch (statbuf.st_mode & S_IFMT) {
2804 case S_IFCHR: case S_IFBLK:
2805 tprintf("st_rdev=makedev(%lu, %lu), ",
2806 (unsigned long) major(statbuf.st_rdev),
2807 (unsigned long) minor(statbuf.st_rdev));
2808 break;
2809 default:
2810 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
2811 break;
2812 }
2813 if (!abbrev(tcp)) {
2814 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
2815 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
2816 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
2817 tprints("}");
2818 }
2819 else
2820 tprints("...}");
2821}
2822
2823int
2824sys_fstat64(struct tcb *tcp)
2825{
2826 if (entering(tcp)) {
2827 printfd(tcp, tcp->u_arg[0]);
2828 tprints(", ");
2829 } else {
2830 realprintstat64(tcp, tcp->u_arg[1]);
2831 }
2832 return 0;
2833}
2834
2835int
2836sys_stat64(struct tcb *tcp)
2837{
2838 if (entering(tcp)) {
2839 printpath(tcp, tcp->u_arg[0]);
2840 tprints(", ");
2841 } else {
2842 realprintstat64(tcp, tcp->u_arg[1]);
2843 }
2844 return 0;
2845}
2846#endif