blob: 25152f0d4a07da743bbfb29bd2b4b2694e39d2c5 [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;
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000120} __attribute__((packed));
121# define HAVE_STAT64 1
Dmitry V. Levinbd2e28a2013-05-01 15:14:25 +0000122
123struct __old_kernel_stat {
124 unsigned short st_dev;
125 unsigned short st_ino;
126 unsigned short st_mode;
127 unsigned short st_nlink;
128 unsigned short st_uid;
129 unsigned short st_gid;
130 unsigned short st_rdev;
131 unsigned int st_size;
132 unsigned int st_atime;
133 unsigned int st_mtime;
134 unsigned int st_ctime;
135};
Denys Vlasenko84703742012-02-25 02:38:52 +0100136#else
137# undef dev_t
138# undef ino_t
139# undef mode_t
140# undef nlink_t
141# undef uid_t
142# undef gid_t
143# undef off_t
144# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100145# define dev_t __kernel_dev_t
146# define ino_t __kernel_ino_t
147# define mode_t __kernel_mode_t
148# define nlink_t __kernel_nlink_t
149# define uid_t __kernel_uid_t
150# define gid_t __kernel_gid_t
151# define off_t __kernel_off_t
152# define loff_t __kernel_loff_t
Wichert Akkermana6013701999-07-08 14:00:58 +0000153
Denys Vlasenko84703742012-02-25 02:38:52 +0100154# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +0000155
Denys Vlasenko84703742012-02-25 02:38:52 +0100156# undef dev_t
157# undef ino_t
158# undef mode_t
159# undef nlink_t
160# undef uid_t
161# undef gid_t
162# undef off_t
163# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100164# define dev_t dev_t
165# define ino_t ino_t
166# define mode_t mode_t
167# define nlink_t nlink_t
168# define uid_t uid_t
169# define gid_t gid_t
170# define off_t off_t
171# define loff_t loff_t
172#endif
173
Denys Vlasenko84703742012-02-25 02:38:52 +0100174#define stat libc_stat
175#define stat64 libc_stat64
176#include <sys/stat.h>
177#undef stat
178#undef stat64
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100179/* These might be macros. */
Denys Vlasenko84703742012-02-25 02:38:52 +0100180#undef st_atime
181#undef st_mtime
182#undef st_ctime
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000183
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000184#include <fcntl.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000185#ifdef HAVE_SYS_VFS_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100186# include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000187#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +0000188#ifdef HAVE_LINUX_XATTR_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100189# include <linux/xattr.h>
Denys Vlasenkoed720fd2012-02-25 02:24:03 +0100190#else
Denys Vlasenko84703742012-02-25 02:38:52 +0100191# define XATTR_CREATE 1
192# define XATTR_REPLACE 2
Roland McGrath186c5ac2002-12-15 23:58:23 +0000193#endif
194
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000195#ifdef MAJOR_IN_SYSMACROS
Denys Vlasenko84703742012-02-25 02:38:52 +0100196# include <sys/sysmacros.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000197#endif
198
199#ifdef MAJOR_IN_MKDEV
Denys Vlasenko84703742012-02-25 02:38:52 +0100200# include <sys/mkdev.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000201#endif
202
203#ifdef HAVE_SYS_ASYNCH_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100204# include <sys/asynch.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205#endif
206
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100207struct kernel_dirent {
208 unsigned long d_ino;
209 unsigned long d_off;
210 unsigned short d_reclen;
211 char d_name[1];
212};
213
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000214const struct xlat open_access_modes[] = {
215 { O_RDONLY, "O_RDONLY" },
216 { O_WRONLY, "O_WRONLY" },
217 { O_RDWR, "O_RDWR" },
218#ifdef O_ACCMODE
219 { O_ACCMODE, "O_ACCMODE" },
220#endif
221 { 0, NULL },
222};
223
224const struct xlat open_mode_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000225 { O_CREAT, "O_CREAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000226 { O_EXCL, "O_EXCL" },
227 { O_NOCTTY, "O_NOCTTY" },
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000228 { O_TRUNC, "O_TRUNC" },
229 { O_APPEND, "O_APPEND" },
230 { O_NONBLOCK, "O_NONBLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000231#ifdef O_SYNC
232 { O_SYNC, "O_SYNC" },
233#endif
234#ifdef O_ASYNC
235 { O_ASYNC, "O_ASYNC" },
236#endif
237#ifdef O_DSYNC
238 { O_DSYNC, "O_DSYNC" },
239#endif
240#ifdef O_RSYNC
241 { O_RSYNC, "O_RSYNC" },
242#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000243#if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000244 { O_NDELAY, "O_NDELAY" },
245#endif
246#ifdef O_PRIV
247 { O_PRIV, "O_PRIV" },
248#endif
249#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000250 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000251#endif
252#ifdef O_LARGEFILE
Roland McGrathfee836e2005-02-02 22:11:32 +0000253# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
254# undef O_LARGEFILE
255# ifdef SPARC64
256# define O_LARGEFILE 0x40000
257# elif defined X86_64 || defined S390X
258# define O_LARGEFILE 0100000
259# endif
260# endif
Roland McGrath663a8a02005-02-04 09:49:56 +0000261# ifdef O_LARGEFILE
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200262 { O_LARGEFILE, "O_LARGEFILE" },
Roland McGrath663a8a02005-02-04 09:49:56 +0000263# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000264#endif
265#ifdef O_DIRECTORY
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200266 { O_DIRECTORY, "O_DIRECTORY" },
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000267#endif
268#ifdef O_NOFOLLOW
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200269 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000270#endif
Roland McGrath1025c3e2005-05-09 07:40:35 +0000271#ifdef O_NOATIME
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200272 { O_NOATIME, "O_NOATIME" },
Roland McGrath1025c3e2005-05-09 07:40:35 +0000273#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000274#ifdef O_CLOEXEC
275 { O_CLOEXEC, "O_CLOEXEC" },
276#endif
Mike Frysinger5e747032013-12-31 01:13:27 -0500277#ifdef O_PATH
278 { O_PATH, "O_PATH" },
279#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000280#ifdef FNDELAY
281 { FNDELAY, "FNDELAY" },
282#endif
283#ifdef FAPPEND
284 { FAPPEND, "FAPPEND" },
285#endif
286#ifdef FMARK
287 { FMARK, "FMARK" },
288#endif
289#ifdef FDEFER
290 { FDEFER, "FDEFER" },
291#endif
292#ifdef FASYNC
293 { FASYNC, "FASYNC" },
294#endif
295#ifdef FSHLOCK
296 { FSHLOCK, "FSHLOCK" },
297#endif
298#ifdef FEXLOCK
299 { FEXLOCK, "FEXLOCK" },
300#endif
301#ifdef FCREAT
302 { FCREAT, "FCREAT" },
303#endif
304#ifdef FTRUNC
305 { FTRUNC, "FTRUNC" },
306#endif
307#ifdef FEXCL
308 { FEXCL, "FEXCL" },
309#endif
310#ifdef FNBIO
311 { FNBIO, "FNBIO" },
312#endif
313#ifdef FSYNC
314 { FSYNC, "FSYNC" },
315#endif
316#ifdef FNOCTTY
317 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000318#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000319#ifdef O_SHLOCK
320 { O_SHLOCK, "O_SHLOCK" },
321#endif
322#ifdef O_EXLOCK
323 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000324#endif
325 { 0, NULL },
326};
327
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000328#ifndef AT_FDCWD
329# define AT_FDCWD -100
330#endif
331
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000332/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
333 * extension to get the right value. We do this by declaring fd as int here.
334 */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000335static void
Dmitry V. Levin31382132011-03-04 05:08:02 +0300336print_dirfd(struct tcb *tcp, int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000337{
338 if (fd == AT_FDCWD)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200339 tprints("AT_FDCWD, ");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200340 else {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300341 printfd(tcp, fd);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200342 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300343 }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000344}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000345
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000346/*
347 * low bits of the open(2) flags define access mode,
348 * other bits are real flags.
349 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000350const char *
351sprint_open_modes(mode_t flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000352{
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100353 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000354 char *p;
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100355 char sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000356 const char *str;
357 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000358
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100359 sep = ' ';
360 p = stpcpy(outstr, "flags");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000361 str = xlookup(open_access_modes, flags & 3);
362 if (str) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100363 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200364 p = stpcpy(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000365 flags &= ~3;
366 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000367 return outstr;
368 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000369 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000370
371 for (x = open_mode_flags; x->str; x++) {
372 if ((flags & x->val) == x->val) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100373 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200374 p = stpcpy(p, x->str);
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000375 flags &= ~x->val;
376 if (!flags)
377 return outstr;
378 sep = '|';
379 }
380 }
381 /* flags is still nonzero */
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100382 *p++ = sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000383 sprintf(p, "%#x", flags);
384 return outstr;
385}
386
387void
388tprint_open_modes(mode_t flags)
389{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200390 tprints(sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000391}
392
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000393static int
394decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000395{
396 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000397 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200398 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000399 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000400 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000401 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000402 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000403 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000404 }
405 }
406 return 0;
407}
408
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000409int
410sys_open(struct tcb *tcp)
411{
412 return decode_open(tcp, 0);
413}
414
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000415int
416sys_openat(struct tcb *tcp)
417{
418 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300419 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000420 return decode_open(tcp, 1);
421}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000422
Denys Vlasenko9472a272013-02-12 11:43:46 +0100423#if defined(SPARC) || defined(SPARC64)
Roland McGratha4d48532005-06-08 20:45:28 +0000424static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000425 { 0, "O_RDWR" },
426 { 1, "O_RDONLY" },
427 { 2, "O_WRONLY" },
428 { 0x80, "O_NONBLOCK" },
429 { 8, "O_APPEND" },
430 { 0x100, "O_CREAT" },
431 { 0x200, "O_TRUNC" },
432 { 0x400, "O_EXCL" },
433 { 0x800, "O_NOCTTY" },
434 { 0x10, "O_SYNC" },
435 { 0x40, "O_DSYNC" },
436 { 0x8000, "O_RSYNC" },
437 { 4, "O_NDELAY" },
438 { 0x1000, "O_PRIV" },
439 { 0, NULL },
440};
441
442int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000443solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000444{
445 if (entering(tcp)) {
446 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200447 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000448 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000449 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000450 if (tcp->u_arg[1] & 0x100) {
451 /* mode */
452 tprintf(", %#lo", tcp->u_arg[2]);
453 }
454 }
455 return 0;
456}
457
458#endif
459
460int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000461sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000462{
463 if (entering(tcp)) {
464 printpath(tcp, tcp->u_arg[0]);
465 tprintf(", %#lo", tcp->u_arg[1]);
466 }
467 return 0;
468}
469
Roland McGrathd9f816f2004-09-04 03:39:20 +0000470static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000471 { F_OK, "F_OK", },
472 { R_OK, "R_OK" },
473 { W_OK, "W_OK" },
474 { X_OK, "X_OK" },
475#ifdef EFF_ONLY_OK
476 { EFF_ONLY_OK, "EFF_ONLY_OK" },
477#endif
478#ifdef EX_OK
479 { EX_OK, "EX_OK" },
480#endif
481 { 0, NULL },
482};
483
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000484static int
485decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000486{
487 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000488 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200489 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000490 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000491 }
492 return 0;
493}
494
495int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000496sys_access(struct tcb *tcp)
497{
498 return decode_access(tcp, 0);
499}
500
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000501int
502sys_faccessat(struct tcb *tcp)
503{
504 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300505 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000506 return decode_access(tcp, 1);
507}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000508
509int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000510sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000511{
512 if (entering(tcp)) {
513 tprintf("%#lo", tcp->u_arg[0]);
514 }
515 return RVAL_OCTAL;
516}
517
Denys Vlasenko86738a22013-02-17 14:31:55 +0100518const struct xlat whence_codes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000519 { SEEK_SET, "SEEK_SET" },
520 { SEEK_CUR, "SEEK_CUR" },
521 { SEEK_END, "SEEK_END" },
Denys Vlasenko86738a22013-02-17 14:31:55 +0100522#ifdef SEEK_DATA
523 { SEEK_DATA, "SEEK_DATA" },
524#endif
525#ifdef SEEK_HOLE
526 { SEEK_HOLE, "SEEK_HOLE" },
527#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000528 { 0, NULL },
529};
530
Denys Vlasenko386b8712013-02-17 01:38:14 +0100531/* Linux kernel has exactly one version of lseek:
532 * fs/read_write.c::SYSCALL_DEFINE3(lseek, unsigned, fd, off_t, offset, unsigned, origin)
533 * In kernel, off_t is always the same as (kernel's) long
534 * (see include/uapi/asm-generic/posix_types.h),
535 * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument.
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100536 * Use test/x32_lseek.c to test lseek decoding.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100537 */
H.J. Luc933f272012-04-16 17:41:13 +0200538#if defined(LINUX_MIPSN32) || defined(X32)
Roland McGrath542c2c62008-05-20 01:11:56 +0000539int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000540sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000541{
542 long long offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100543 int whence;
Roland McGrath542c2c62008-05-20 01:11:56 +0000544
545 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300546 printfd(tcp, tcp->u_arg[0]);
Roland McGrath542c2c62008-05-20 01:11:56 +0000547 offset = tcp->ext_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100548 whence = tcp->u_arg[2];
549 if (whence == SEEK_SET)
550 tprintf(", %llu, ", offset);
Roland McGrath542c2c62008-05-20 01:11:56 +0000551 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100552 tprintf(", %lld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100553 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath542c2c62008-05-20 01:11:56 +0000554 }
H.J. Ludd0130b2012-04-16 12:16:45 +0200555 return RVAL_LUDECIMAL;
Roland McGrath542c2c62008-05-20 01:11:56 +0000556}
H.J. Ludd0130b2012-04-16 12:16:45 +0200557#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000559sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000560{
Denys Vlasenko06121762013-02-17 20:08:50 +0100561 long offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100562 int whence;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000563
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300565 printfd(tcp, tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000566 offset = tcp->u_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100567 whence = tcp->u_arg[2];
568 if (whence == SEEK_SET)
569 tprintf(", %lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000570 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100571 tprintf(", %ld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100572 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000573 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000574 return RVAL_UDECIMAL;
575}
John Hughes5a826b82001-03-07 13:21:24 +0000576#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000577
Denys Vlasenko386b8712013-02-17 01:38:14 +0100578/* llseek syscall takes explicitly two ulong arguments hi, lo,
579 * rather than one 64-bit argument for which LONG_LONG works
580 * appropriate for the native byte order.
581 *
582 * See kernel's fs/read_write.c::SYSCALL_DEFINE5(llseek, ...)
583 *
584 * hi,lo are "unsigned longs" and combined exactly this way in kernel:
585 * ((loff_t) hi << 32) | lo
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100586 * Note that for architectures with kernel's long wider than userspace long
Denys Vlasenko386b8712013-02-17 01:38:14 +0100587 * (such as x32), combining code will use *kernel's*, i.e. *wide* longs
Denys Vlasenko06121762013-02-17 20:08:50 +0100588 * for hi and lo. We would need to use tcp->ext_arg[N] on x32...
589 * ...however, x32 (and x86_64) does not _have_ llseek syscall as such.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100590 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000591int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000592sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000593{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000594 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300595 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000596 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300597 tprintf(", %llu, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100598 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300599 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000600 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300601 tprintf(", %lld, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100602 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300603 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000604 }
605 else {
Denys Vlasenko386b8712013-02-17 01:38:14 +0100606 long long off;
Denys Vlasenko1d632462009-04-14 12:51:00 +0000607 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
608 tprintf("%#lx, ", tcp->u_arg[3]);
609 else
610 tprintf("[%llu], ", off);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100611 printxval(whence_codes, tcp->u_arg[4], "SEEK_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000612 }
613 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000614}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000615
616int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000617sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000618{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000619 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100620 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300621 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +0200622 argn = printllval(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100623 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000624 }
625 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000626}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000627
628int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000629sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000630{
631 if (entering(tcp)) {
632 printpath(tcp, tcp->u_arg[0]);
633 tprintf(", %lu", tcp->u_arg[1]);
634 }
635 return 0;
636}
637
John Hughes96f51472001-03-06 16:50:41 +0000638int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000639sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000640{
641 if (entering(tcp)) {
642 printpath(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100643 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000644 }
645 return 0;
646}
John Hughes96f51472001-03-06 16:50:41 +0000647
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000648int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000649sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000650{
651 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300652 printfd(tcp, tcp->u_arg[0]);
653 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000654 }
655 return 0;
656}
657
John Hughes96f51472001-03-06 16:50:41 +0000658int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000659sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000660{
661 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300662 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +0200663 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000664 }
665 return 0;
666}
John Hughes96f51472001-03-06 16:50:41 +0000667
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000668/* several stats */
669
Roland McGrathd9f816f2004-09-04 03:39:20 +0000670static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000671 { S_IFREG, "S_IFREG" },
672 { S_IFSOCK, "S_IFSOCK" },
673 { S_IFIFO, "S_IFIFO" },
674 { S_IFLNK, "S_IFLNK" },
675 { S_IFDIR, "S_IFDIR" },
676 { S_IFBLK, "S_IFBLK" },
677 { S_IFCHR, "S_IFCHR" },
678 { 0, NULL },
679};
680
Roland McGrathf9c49b22004-10-06 22:11:54 +0000681static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000682sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000683{
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100684 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
685 + sizeof(int)*3
686 + /*paranoia:*/ 8];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000687 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000688
689 if ((mode & S_IFMT) == 0)
690 s = "";
691 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
692 sprintf(buf, "%#o", mode);
693 return buf;
694 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100695 s = buf + sprintf(buf, "%s%s%s%s", s,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000696 (mode & S_ISUID) ? "|S_ISUID" : "",
697 (mode & S_ISGID) ? "|S_ISGID" : "",
698 (mode & S_ISVTX) ? "|S_ISVTX" : "");
699 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
700 if (mode)
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100701 sprintf((char*)s, "|%#o", mode);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000702 s = (*buf == '|') ? buf + 1 : buf;
703 return *s ? s : "0";
704}
705
706static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000707sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000708{
709 struct tm *tmp;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100710 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000711
712 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000713 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000714 return buf;
715 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200716 tmp = localtime(&t);
717 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000718 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
719 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
720 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
721 else
722 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
723
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000724 return buf;
725}
726
Denys Vlasenko9472a272013-02-12 11:43:46 +0100727#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000728typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000729 int tv_sec;
730 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000731} timestruct_t;
732
733struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000734 unsigned st_dev;
735 int st_pad1[3]; /* network id */
736 unsigned st_ino;
737 unsigned st_mode;
738 unsigned st_nlink;
739 unsigned st_uid;
740 unsigned st_gid;
741 unsigned st_rdev;
742 int st_pad2[2];
743 int st_size;
744 int st_pad3; /* st_size, off_t expansion */
745 timestruct_t st_atime;
746 timestruct_t st_mtime;
747 timestruct_t st_ctime;
748 int st_blksize;
749 int st_blocks;
750 char st_fstype[16];
751 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000752};
753
754static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000755printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000756{
757 struct solstat statbuf;
758
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000759 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200760 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000761 return;
762 }
763 if (!abbrev(tcp)) {
764 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
765 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
766 (unsigned long) (statbuf.st_dev & 0x3ffff),
767 (unsigned long) statbuf.st_ino,
768 sprintmode(statbuf.st_mode));
769 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
770 (unsigned long) statbuf.st_nlink,
771 (unsigned long) statbuf.st_uid,
772 (unsigned long) statbuf.st_gid);
773 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
774 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
775 }
776 else
777 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
778 switch (statbuf.st_mode & S_IFMT) {
779 case S_IFCHR: case S_IFBLK:
780 tprintf("st_rdev=makedev(%lu, %lu), ",
781 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
782 (unsigned long) (statbuf.st_rdev & 0x3ffff));
783 break;
784 default:
785 tprintf("st_size=%u, ", statbuf.st_size);
786 break;
787 }
788 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000789 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
790 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
791 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000792 }
793 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200794 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000795}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000796
Denys Vlasenko9472a272013-02-12 11:43:46 +0100797# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000798static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000799printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000800{
801 struct stat_sparc64 statbuf;
802
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000803 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200804 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000805 return;
806 }
807
808 if (!abbrev(tcp)) {
809 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
810 (unsigned long) major(statbuf.st_dev),
811 (unsigned long) minor(statbuf.st_dev),
812 (unsigned long) statbuf.st_ino,
813 sprintmode(statbuf.st_mode));
814 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
815 (unsigned long) statbuf.st_nlink,
816 (unsigned long) statbuf.st_uid,
817 (unsigned long) statbuf.st_gid);
818 tprintf("st_blksize=%lu, ",
819 (unsigned long) statbuf.st_blksize);
820 tprintf("st_blocks=%lu, ",
821 (unsigned long) statbuf.st_blocks);
822 }
823 else
824 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
825 switch (statbuf.st_mode & S_IFMT) {
826 case S_IFCHR: case S_IFBLK:
827 tprintf("st_rdev=makedev(%lu, %lu), ",
828 (unsigned long) major(statbuf.st_rdev),
829 (unsigned long) minor(statbuf.st_rdev));
830 break;
831 default:
832 tprintf("st_size=%lu, ", statbuf.st_size);
833 break;
834 }
835 if (!abbrev(tcp)) {
836 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
837 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100838 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000839 }
840 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200841 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000842}
Denys Vlasenko9472a272013-02-12 11:43:46 +0100843# endif /* SPARC64 */
844#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000845
Denys Vlasenko84703742012-02-25 02:38:52 +0100846#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200847struct stat_powerpc32 {
848 unsigned int st_dev;
849 unsigned int st_ino;
850 unsigned int st_mode;
851 unsigned short st_nlink;
852 unsigned int st_uid;
853 unsigned int st_gid;
854 unsigned int st_rdev;
855 unsigned int st_size;
856 unsigned int st_blksize;
857 unsigned int st_blocks;
858 unsigned int st_atime;
859 unsigned int st_atime_nsec;
860 unsigned int st_mtime;
861 unsigned int st_mtime_nsec;
862 unsigned int st_ctime;
863 unsigned int st_ctime_nsec;
864 unsigned int __unused4;
865 unsigned int __unused5;
866};
867
868static void
869printstat_powerpc32(struct tcb *tcp, long addr)
870{
871 struct stat_powerpc32 statbuf;
872
873 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200874 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200875 return;
876 }
877
878 if (!abbrev(tcp)) {
879 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
880 major(statbuf.st_dev), minor(statbuf.st_dev),
881 statbuf.st_ino,
882 sprintmode(statbuf.st_mode));
883 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
884 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
885 tprintf("st_blksize=%u, ", statbuf.st_blksize);
886 tprintf("st_blocks=%u, ", statbuf.st_blocks);
887 }
888 else
889 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
890 switch (statbuf.st_mode & S_IFMT) {
891 case S_IFCHR: case S_IFBLK:
892 tprintf("st_rdev=makedev(%lu, %lu), ",
893 (unsigned long) major(statbuf.st_rdev),
894 (unsigned long) minor(statbuf.st_rdev));
895 break;
896 default:
897 tprintf("st_size=%u, ", statbuf.st_size);
898 break;
899 }
900 if (!abbrev(tcp)) {
901 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
902 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100903 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200904 }
905 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200906 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200907}
Denys Vlasenko84703742012-02-25 02:38:52 +0100908#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200909
Roland McGratha4d48532005-06-08 20:45:28 +0000910static const struct xlat fileflags[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000911 { 0, NULL },
912};
913
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000914static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000915realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000916{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000917 if (!abbrev(tcp)) {
918 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
919 (unsigned long) major(statbuf->st_dev),
920 (unsigned long) minor(statbuf->st_dev),
921 (unsigned long) statbuf->st_ino,
922 sprintmode(statbuf->st_mode));
923 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
924 (unsigned long) statbuf->st_nlink,
925 (unsigned long) statbuf->st_uid,
926 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000927#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000928 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
929#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000930#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000931 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
932#endif
933 }
934 else
935 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
936 switch (statbuf->st_mode & S_IFMT) {
937 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000938#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000939 tprintf("st_rdev=makedev(%lu, %lu), ",
940 (unsigned long) major(statbuf->st_rdev),
941 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000942#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000943 tprintf("st_size=makedev(%lu, %lu), ",
944 (unsigned long) major(statbuf->st_size),
945 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000946#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000947 break;
948 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000949 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000950 break;
951 }
952 if (!abbrev(tcp)) {
953 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
954 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
955 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000956#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200957 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000958 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000959#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000960#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000961 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
962#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000963#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000964 tprintf(", st_level=%ld", statbuf->st_level);
965#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000966#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000967 tprintf(", st_fstype=%.*s",
968 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
969#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000970#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000971 tprintf(", st_gen=%u", statbuf->st_gen);
972#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200973 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000974 }
975 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200976 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000977}
978
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000979#ifndef X32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000980static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000981printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000982{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000983 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000984
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000985 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200986 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000987 return;
988 }
989 if (syserror(tcp) || !verbose(tcp)) {
990 tprintf("%#lx", addr);
991 return;
992 }
993
Denys Vlasenko9472a272013-02-12 11:43:46 +0100994#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000995 if (current_personality == 1) {
996 printstatsol(tcp, addr);
997 return;
998 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000999#ifdef SPARC64
1000 else if (current_personality == 2) {
1001 printstat_sparc64(tcp, addr);
1002 return;
1003 }
1004#endif
Denys Vlasenko9472a272013-02-12 11:43:46 +01001005#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001006
Denys Vlasenko84703742012-02-25 02:38:52 +01001007#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +02001008 if (current_personality == 1) {
1009 printstat_powerpc32(tcp, addr);
1010 return;
1011 }
1012#endif
1013
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001014 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001015 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001016 return;
1017 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001018
1019 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001020}
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001021#else /* X32 */
1022# define printstat printstat64
1023#endif
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{
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001061#ifdef X32
1062 struct stat statbuf;
1063#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001064 struct stat64 statbuf;
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001065#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001066
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001067#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001068 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1069#endif
1070
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001071 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001072 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001073 return;
1074 }
1075 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001076 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001077 return;
1078 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001079
Denys Vlasenko9472a272013-02-12 11:43:46 +01001080#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001081 if (current_personality == 1) {
1082 printstatsol(tcp, addr);
1083 return;
1084 }
1085# ifdef SPARC64
1086 else if (current_personality == 2) {
1087 printstat_sparc64(tcp, addr);
1088 return;
1089 }
1090# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +01001091#endif /* SPARC[64] */
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001092
Denys Vlasenko84703742012-02-25 02:38:52 +01001093#if defined X86_64
H.J. Lu35be5812012-04-16 13:00:01 +02001094 if (current_personality != 1) {
Andreas Schwab61b74352009-10-16 11:37:13 +02001095 printstat(tcp, addr);
1096 return;
1097 }
1098#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +00001099
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001100 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001101 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001102 return;
1103 }
1104
1105 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001106 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
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 (unsigned long long) statbuf.st_ino,
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001110 sprintmode(statbuf.st_mode));
1111 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1112 (unsigned long) statbuf.st_nlink,
1113 (unsigned long) statbuf.st_uid,
1114 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001115#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001116 tprintf("st_blksize=%lu, ",
1117 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001118#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1119#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001120 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001121#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001122 }
1123 else
1124 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1125 switch (statbuf.st_mode & S_IFMT) {
1126 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001127#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001128 tprintf("st_rdev=makedev(%lu, %lu), ",
1129 (unsigned long) major(statbuf.st_rdev),
1130 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001131#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001132 tprintf("st_size=makedev(%lu, %lu), ",
1133 (unsigned long) major(statbuf.st_size),
1134 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001135#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001136 break;
1137 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001138 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001139 break;
1140 }
1141 if (!abbrev(tcp)) {
1142 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1143 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001144 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001145#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001146 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001147 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001148#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001149#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001150 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1151#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001152#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001153 tprintf(", st_level=%ld", statbuf.st_level);
1154#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001155#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001156 tprintf(", st_fstype=%.*s",
1157 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1158#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001159#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001160 tprintf(", st_gen=%u", statbuf.st_gen);
1161#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001162 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001163 }
1164 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001165 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001166}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001167#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001168
Denys Vlasenko8435d672013-02-18 15:47:57 +01001169#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001170static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001171convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001172{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001173 newbuf->st_dev = oldbuf->st_dev;
1174 newbuf->st_ino = oldbuf->st_ino;
1175 newbuf->st_mode = oldbuf->st_mode;
1176 newbuf->st_nlink = oldbuf->st_nlink;
1177 newbuf->st_uid = oldbuf->st_uid;
1178 newbuf->st_gid = oldbuf->st_gid;
1179 newbuf->st_rdev = oldbuf->st_rdev;
1180 newbuf->st_size = oldbuf->st_size;
1181 newbuf->st_atime = oldbuf->st_atime;
1182 newbuf->st_mtime = oldbuf->st_mtime;
1183 newbuf->st_ctime = oldbuf->st_ctime;
1184 newbuf->st_blksize = 0; /* not supported in old_stat */
1185 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001186}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001187
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001188static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001189printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001190{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001191 struct __old_kernel_stat statbuf;
1192 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001193
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001194 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001195 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001196 return;
1197 }
1198 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001199 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001200 return;
1201 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001202
Denys Vlasenko9472a272013-02-12 11:43:46 +01001203# if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001204 if (current_personality == 1) {
1205 printstatsol(tcp, addr);
1206 return;
1207 }
Denys Vlasenko84703742012-02-25 02:38:52 +01001208# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001209
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001210 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001211 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001212 return;
1213 }
1214
1215 convertoldstat(&statbuf, &newstatbuf);
1216 realprintstat(tcp, &newstatbuf);
1217}
Denys Vlasenko84703742012-02-25 02:38:52 +01001218#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001219
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001220int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001221sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001222{
1223 if (entering(tcp)) {
1224 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001225 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001226 } else {
1227 printstat(tcp, tcp->u_arg[1]);
1228 }
1229 return 0;
1230}
1231
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001232#ifdef X32
1233static void
1234printstat64_x32(struct tcb *tcp, long addr)
1235{
1236 struct stat64 statbuf;
1237
1238 if (!addr) {
1239 tprints("NULL");
1240 return;
1241 }
1242 if (syserror(tcp) || !verbose(tcp)) {
1243 tprintf("%#lx", addr);
1244 return;
1245 }
1246
1247 if (umove(tcp, addr, &statbuf) < 0) {
1248 tprints("{...}");
1249 return;
1250 }
1251
1252 if (!abbrev(tcp)) {
1253 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1254 (unsigned long) major(statbuf.st_dev),
1255 (unsigned long) minor(statbuf.st_dev),
1256 (unsigned long long) statbuf.st_ino,
1257 sprintmode(statbuf.st_mode));
1258 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1259 (unsigned long) statbuf.st_nlink,
1260 (unsigned long) statbuf.st_uid,
1261 (unsigned long) statbuf.st_gid);
1262 tprintf("st_blksize=%lu, ",
1263 (unsigned long) statbuf.st_blksize);
1264 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1265 }
1266 else
1267 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1268 switch (statbuf.st_mode & S_IFMT) {
1269 case S_IFCHR: case S_IFBLK:
1270 tprintf("st_rdev=makedev(%lu, %lu), ",
1271 (unsigned long) major(statbuf.st_rdev),
1272 (unsigned long) minor(statbuf.st_rdev));
1273 break;
1274 default:
1275 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1276 break;
1277 }
1278 if (!abbrev(tcp)) {
1279 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1280 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1281 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1282 tprints("}");
1283 }
1284 else
1285 tprints("...}");
1286}
1287#endif /* X32 */
1288
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001289int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001290sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001291{
1292#ifdef HAVE_STAT64
1293 if (entering(tcp)) {
1294 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001295 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001296 } else {
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001297# ifdef X32
1298 printstat64_x32(tcp, tcp->u_arg[1]);
1299# else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001300 printstat64(tcp, tcp->u_arg[1]);
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001301# endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001302 }
1303 return 0;
1304#else
1305 return printargs(tcp);
1306#endif
1307}
1308
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001309#ifndef AT_SYMLINK_NOFOLLOW
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001310# define AT_SYMLINK_NOFOLLOW 0x100
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001311#endif
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001312#ifndef AT_REMOVEDIR
1313# define AT_REMOVEDIR 0x200
1314#endif
1315#ifndef AT_SYMLINK_FOLLOW
1316# define AT_SYMLINK_FOLLOW 0x400
1317#endif
1318#ifndef AT_NO_AUTOMOUNT
1319# define AT_NO_AUTOMOUNT 0x800
1320#endif
1321#ifndef AT_EMPTY_PATH
1322# define AT_EMPTY_PATH 0x1000
1323#endif
1324
1325static const struct xlat at_flags[] = {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001326 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001327 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1328 { AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" },
1329 { AT_NO_AUTOMOUNT, "AT_NO_AUTOMOUNT" },
1330 { AT_EMPTY_PATH, "AT_EMPTY_PATH" },
1331 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001332};
1333
1334int
1335sys_newfstatat(struct tcb *tcp)
1336{
1337 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001338 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001339 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001340 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001341 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001342#ifdef POWERPC64
1343 if (current_personality == 0)
1344 printstat(tcp, tcp->u_arg[2]);
1345 else
1346 printstat64(tcp, tcp->u_arg[2]);
1347#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001348 printstat64(tcp, tcp->u_arg[2]);
1349#else
1350 printstat(tcp, tcp->u_arg[2]);
1351#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001352 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001353 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001354 }
1355 return 0;
1356}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001357
Denys Vlasenko8435d672013-02-18 15:47:57 +01001358#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001359int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001360sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001361{
1362 if (entering(tcp)) {
1363 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001364 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001365 } else {
1366 printoldstat(tcp, tcp->u_arg[1]);
1367 }
1368 return 0;
1369}
Denys Vlasenko84703742012-02-25 02:38:52 +01001370#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001371
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001372int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001373sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001374{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001375 if (entering(tcp)) {
1376 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001377 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001378 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001379 printstat(tcp, tcp->u_arg[1]);
1380 }
1381 return 0;
1382}
1383
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001384int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001385sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001386{
1387#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001388 if (entering(tcp)) {
1389 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001390 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001391 } else {
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001392# ifdef X32
1393 printstat64_x32(tcp, tcp->u_arg[1]);
1394# else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001395 printstat64(tcp, tcp->u_arg[1]);
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001396# endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001397 }
1398 return 0;
1399#else
1400 return printargs(tcp);
1401#endif
1402}
1403
Denys Vlasenko8435d672013-02-18 15:47:57 +01001404#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001405int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001406sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001407{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001408 if (entering(tcp)) {
1409 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001410 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001411 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001412 printoldstat(tcp, tcp->u_arg[1]);
1413 }
1414 return 0;
1415}
Denys Vlasenko84703742012-02-25 02:38:52 +01001416#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001417
Denys Vlasenko9472a272013-02-12 11:43:46 +01001418#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001419
1420int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001421sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001422{
1423 if (entering(tcp)) {
1424 tprintf("%ld, ", tcp->u_arg[0]);
1425 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001426 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001427 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001428# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001429 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001430 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001431 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001432# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001433 printstat(tcp, tcp->u_arg[2]);
1434 }
1435 return 0;
1436}
1437
1438int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001439sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001440{
1441 if (entering(tcp))
1442 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1443 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001444# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001445 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001446 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001447 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001448# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001449 printstat(tcp, tcp->u_arg[2]);
1450 }
1451 return 0;
1452}
1453
1454int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001455sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001456{
1457 if (entering(tcp)) {
1458 tprintf("%ld, ", tcp->u_arg[0]);
1459 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001460 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001461 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001462# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001463 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001464 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001465 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001466# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001467 printstat(tcp, tcp->u_arg[2]);
1468 }
1469 return 0;
1470}
1471
1472int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001473sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001474{
1475 int mode = tcp->u_arg[2];
1476
1477 if (entering(tcp)) {
1478 tprintf("%ld, ", tcp->u_arg[0]);
1479 printpath(tcp, tcp->u_arg[1]);
1480 tprintf(", %s", sprintmode(mode));
1481 switch (mode & S_IFMT) {
1482 case S_IFCHR: case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001483 tprintf(", makedev(%lu, %lu)",
1484 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1485 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001486 break;
1487 default:
1488 break;
1489 }
1490 }
1491 return 0;
1492}
1493
Denys Vlasenko84703742012-02-25 02:38:52 +01001494# ifdef HAVE_SYS_ACL_H
Wichert Akkerman8829a551999-06-11 13:18:40 +00001495
Denys Vlasenko84703742012-02-25 02:38:52 +01001496# include <sys/acl.h>
Wichert Akkerman8829a551999-06-11 13:18:40 +00001497
Roland McGratha4d48532005-06-08 20:45:28 +00001498static const struct xlat aclcmds[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001499# ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001500 { SETACL, "SETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001501# endif
1502# ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001503 { GETACL, "GETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001504# endif
1505# ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001506 { GETACLCNT, "GETACLCNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001507# endif
1508# ifdef ACL_GET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001509 { ACL_GET, "ACL_GET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001510# endif
1511# ifdef ACL_SET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001512 { ACL_SET, "ACL_SET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001513# endif
1514# ifdef ACL_CNT
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001515 { ACL_CNT, "ACL_CNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001516# endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001517 { 0, NULL },
1518};
1519
1520int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001521sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001522{
1523 if (entering(tcp)) {
1524 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001525 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001526 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1527 tprintf(", %ld", tcp->u_arg[2]);
1528 /*
1529 * FIXME - dump out the list of aclent_t's pointed to
1530 * by "tcp->u_arg[3]" if it's not NULL.
1531 */
1532 if (tcp->u_arg[3])
1533 tprintf(", %#lx", tcp->u_arg[3]);
1534 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001535 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001536 }
1537 return 0;
1538}
1539
Wichert Akkerman8829a551999-06-11 13:18:40 +00001540int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001541sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001542{
1543 if (entering(tcp)) {
1544 tprintf("%ld, ", tcp->u_arg[0]);
1545 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1546 tprintf(", %ld", tcp->u_arg[2]);
1547 /*
1548 * FIXME - dump out the list of aclent_t's pointed to
1549 * by "tcp->u_arg[3]" if it's not NULL.
1550 */
1551 if (tcp->u_arg[3])
1552 tprintf(", %#lx", tcp->u_arg[3]);
1553 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001554 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001555 }
1556 return 0;
1557}
1558
Roland McGratha4d48532005-06-08 20:45:28 +00001559static const struct xlat aclipc[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001560# ifdef IPC_SHM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001561 { IPC_SHM, "IPC_SHM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001562# endif
1563# ifdef IPC_SEM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001564 { IPC_SEM, "IPC_SEM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001565# endif
1566# ifdef IPC_MSG
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001567 { IPC_MSG, "IPC_MSG" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001568# endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001569 { 0, NULL },
1570};
1571
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001572int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001573sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001574{
1575 if (entering(tcp)) {
1576 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1577 tprintf(", %#lx, ", tcp->u_arg[1]);
1578 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1579 tprintf(", %ld", tcp->u_arg[3]);
1580 /*
1581 * FIXME - dump out the list of aclent_t's pointed to
1582 * by "tcp->u_arg[4]" if it's not NULL.
1583 */
1584 if (tcp->u_arg[4])
1585 tprintf(", %#lx", tcp->u_arg[4]);
1586 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001587 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001588 }
1589 return 0;
1590}
1591
Denys Vlasenko84703742012-02-25 02:38:52 +01001592# endif /* HAVE_SYS_ACL_H */
Wichert Akkerman8829a551999-06-11 13:18:40 +00001593
Denys Vlasenko9472a272013-02-12 11:43:46 +01001594#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001595
Roland McGrathd9f816f2004-09-04 03:39:20 +00001596static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001597 { 0x73757245, "CODA_SUPER_MAGIC" },
1598 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1599 { 0x1373, "DEVFS_SUPER_MAGIC" },
1600 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1601 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001602 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1603 { 0xef53, "EXT2_SUPER_MAGIC" },
1604 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001605 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001606 { 0x9660, "ISOFS_SUPER_MAGIC" },
1607 { 0x137f, "MINIX_SUPER_MAGIC" },
1608 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001609 { 0x2468, "MINIX2_SUPER_MAGIC" },
1610 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001611 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001612 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001613 { 0x6969, "NFS_SUPER_MAGIC" },
1614 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001615 { 0x002f, "QNX4_SUPER_MAGIC" },
1616 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1617 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1618 { 0x517b, "SMB_SUPER_MAGIC" },
1619 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1620 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1621 { 0x00011954, "UFS_MAGIC" },
1622 { 0x54190100, "UFS_CIGAM" },
1623 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001624 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001625 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001626 { 0, NULL },
1627};
1628
Roland McGrathf9c49b22004-10-06 22:11:54 +00001629static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001630sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001631{
1632 static char buf[32];
Roland McGrathf9c49b22004-10-06 22:11:54 +00001633 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001634
1635 s = xlookup(fsmagic, magic);
1636 if (s) {
1637 sprintf(buf, "\"%s\"", s);
1638 return buf;
1639 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001640 sprintf(buf, "%#x", magic);
1641 return buf;
1642}
1643
1644static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001645printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001646{
1647 struct statfs statbuf;
1648
1649 if (syserror(tcp) || !verbose(tcp)) {
1650 tprintf("%#lx", addr);
1651 return;
1652 }
1653 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001654 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001655 return;
1656 }
1657#ifdef ALPHA
1658
1659 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1660 sprintfstype(statbuf.f_type),
1661 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001662 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001663 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001664 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1665 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001666#else /* !ALPHA */
1667 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1668 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001669 (unsigned long)statbuf.f_bsize,
1670 (unsigned long)statbuf.f_blocks,
1671 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001672 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1673 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001674 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001675 (unsigned long)statbuf.f_ffree,
1676 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001677 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001678#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001679#ifdef _STATFS_F_FRSIZE
1680 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1681#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001682 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001683}
1684
1685int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001686sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001687{
1688 if (entering(tcp)) {
1689 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001690 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001691 } else {
1692 printstatfs(tcp, tcp->u_arg[1]);
1693 }
1694 return 0;
1695}
1696
1697int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001698sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001699{
1700 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001701 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001702 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001703 } else {
1704 printstatfs(tcp, tcp->u_arg[1]);
1705 }
1706 return 0;
1707}
1708
Denys Vlasenko84703742012-02-25 02:38:52 +01001709#if defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001710static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001711printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001712{
1713 struct statfs64 statbuf;
1714
1715 if (syserror(tcp) || !verbose(tcp)) {
1716 tprintf("%#lx", addr);
1717 return;
1718 }
1719 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001720 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001721 return;
1722 }
Roland McGrath08738432005-06-03 02:40:39 +00001723 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001724 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001725 (unsigned long long)statbuf.f_bsize,
1726 (unsigned long long)statbuf.f_blocks,
1727 (unsigned long long)statbuf.f_bfree);
1728 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1729 (unsigned long long)statbuf.f_bavail,
1730 (unsigned long long)statbuf.f_files,
1731 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001732 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1733 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001734#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001735 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001736#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001737#ifdef _STATFS_F_FLAGS
1738 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1739#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001740 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001741}
1742
Andreas Schwab7d558012012-01-17 18:14:22 +01001743struct compat_statfs64 {
1744 uint32_t f_type;
1745 uint32_t f_bsize;
1746 uint64_t f_blocks;
1747 uint64_t f_bfree;
1748 uint64_t f_bavail;
1749 uint64_t f_files;
1750 uint64_t f_ffree;
1751 fsid_t f_fsid;
1752 uint32_t f_namelen;
1753 uint32_t f_frsize;
1754 uint32_t f_flags;
1755 uint32_t f_spare[4];
1756}
1757#if defined(X86_64) || defined(IA64)
1758 __attribute__ ((packed, aligned(4)))
1759#endif
1760;
1761
1762static void
1763printcompat_statfs64(struct tcb *tcp, long addr)
1764{
1765 struct compat_statfs64 statbuf;
1766
1767 if (syserror(tcp) || !verbose(tcp)) {
1768 tprintf("%#lx", addr);
1769 return;
1770 }
1771 if (umove(tcp, addr, &statbuf) < 0) {
1772 tprints("{...}");
1773 return;
1774 }
1775 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1776 sprintfstype(statbuf.f_type),
1777 (unsigned long)statbuf.f_bsize,
1778 (unsigned long long)statbuf.f_blocks,
1779 (unsigned long long)statbuf.f_bfree);
1780 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1781 (unsigned long long)statbuf.f_bavail,
1782 (unsigned long long)statbuf.f_files,
1783 (unsigned long long)statbuf.f_ffree,
1784 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1785 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1786 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001787 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
Andreas Schwab7d558012012-01-17 18:14:22 +01001788}
1789
Roland McGrathab147c52003-07-17 09:03:02 +00001790int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001791sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001792{
1793 if (entering(tcp)) {
1794 printpath(tcp, tcp->u_arg[0]);
1795 tprintf(", %lu, ", tcp->u_arg[1]);
1796 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001797 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001798 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001799 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1800 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001801 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001802 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001803 }
1804 return 0;
1805}
1806
1807int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001808sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001809{
1810 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001811 printfd(tcp, tcp->u_arg[0]);
1812 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001813 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001814 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001815 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001816 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1817 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001818 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001819 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001820 }
1821 return 0;
1822}
1823#endif
1824
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001825#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001826int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001827osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001828{
1829 if (entering(tcp)) {
1830 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001831 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001832 } else {
1833 printstatfs(tcp, tcp->u_arg[1]);
1834 tprintf(", %lu", tcp->u_arg[2]);
1835 }
1836 return 0;
1837}
1838
1839int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001840osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001841{
1842 if (entering(tcp)) {
1843 tprintf("%lu, ", tcp->u_arg[0]);
1844 } else {
1845 printstatfs(tcp, tcp->u_arg[1]);
1846 tprintf(", %lu", tcp->u_arg[2]);
1847 }
1848 return 0;
1849}
Denys Vlasenko84703742012-02-25 02:38:52 +01001850#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001851
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001852/* directory */
1853int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001854sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001855{
1856 if (entering(tcp)) {
1857 printpath(tcp, tcp->u_arg[0]);
1858 }
1859 return 0;
1860}
1861
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001862static int
1863decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001864{
1865 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001866 printpath(tcp, tcp->u_arg[offset]);
1867 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001868 }
1869 return 0;
1870}
1871
1872int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001873sys_mkdir(struct tcb *tcp)
1874{
1875 return decode_mkdir(tcp, 0);
1876}
1877
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001878int
1879sys_mkdirat(struct tcb *tcp)
1880{
1881 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001882 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001883 return decode_mkdir(tcp, 1);
1884}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001885
1886int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001887sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001888{
1889 if (entering(tcp)) {
1890 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001891 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001892 printpath(tcp, tcp->u_arg[1]);
1893 }
1894 return 0;
1895}
1896
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001897int
1898sys_linkat(struct tcb *tcp)
1899{
1900 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001901 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001902 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001903 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001904 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001905 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001906 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001907 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001908 }
1909 return 0;
1910}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001911
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001912int
1913sys_unlinkat(struct tcb *tcp)
1914{
1915 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001916 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001917 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001918 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001919 printflags(at_flags, tcp->u_arg[2], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001920 }
1921 return 0;
1922}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001923
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001924int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001925sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001926{
1927 if (entering(tcp)) {
1928 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001929 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001930 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001931 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001932 }
1933 return 0;
1934}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001935
1936static int
1937decode_readlink(struct tcb *tcp, int offset)
1938{
1939 if (entering(tcp)) {
1940 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001941 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001942 } else {
1943 if (syserror(tcp))
1944 tprintf("%#lx", tcp->u_arg[offset + 1]);
1945 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001946 /* Used to use printpathn(), but readlink
1947 * neither includes NUL in the returned count,
1948 * nor actually writes it into memory.
1949 * printpathn() would decide on printing
1950 * "..." continuation based on garbage
1951 * past return buffer's end.
1952 */
1953 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001954 tprintf(", %lu", tcp->u_arg[offset + 2]);
1955 }
1956 return 0;
1957}
1958
1959int
1960sys_readlink(struct tcb *tcp)
1961{
1962 return decode_readlink(tcp, 0);
1963}
1964
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001965int
1966sys_readlinkat(struct tcb *tcp)
1967{
1968 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001969 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001970 return decode_readlink(tcp, 1);
1971}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001972
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001973int
1974sys_renameat(struct tcb *tcp)
1975{
1976 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001977 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001978 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001979 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001980 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001981 printpath(tcp, tcp->u_arg[3]);
1982 }
1983 return 0;
1984}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001985
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001986int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001987sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001988{
1989 if (entering(tcp)) {
1990 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001991 printuid(", ", tcp->u_arg[1]);
1992 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001993 }
1994 return 0;
1995}
1996
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001997int
1998sys_fchownat(struct tcb *tcp)
1999{
2000 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002001 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002002 printpath(tcp, tcp->u_arg[1]);
2003 printuid(", ", tcp->u_arg[2]);
2004 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002005 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00002006 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002007 }
2008 return 0;
2009}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002010
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002011int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002012sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002013{
2014 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002015 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002016 printuid(", ", tcp->u_arg[1]);
2017 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002018 }
2019 return 0;
2020}
2021
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002022static int
2023decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002024{
2025 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002026 printpath(tcp, tcp->u_arg[offset]);
2027 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002028 }
2029 return 0;
2030}
2031
2032int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002033sys_chmod(struct tcb *tcp)
2034{
2035 return decode_chmod(tcp, 0);
2036}
2037
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002038int
2039sys_fchmodat(struct tcb *tcp)
2040{
2041 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002042 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002043 return decode_chmod(tcp, 1);
2044}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002045
2046int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002047sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002048{
2049 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002050 printfd(tcp, tcp->u_arg[0]);
2051 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002052 }
2053 return 0;
2054}
2055
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002056#ifdef ALPHA
2057int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002058sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002059{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002060 if (entering(tcp)) {
2061 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002062 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002063 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2064 }
2065 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002066}
2067#endif
2068
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002069static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002070decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002071{
2072 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002073 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002074 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002075 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002076 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00002077 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002078 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00002079 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2080 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002081 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002082 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002083 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00002084 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002085 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00002086 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002087 }
2088 return 0;
2089}
2090
2091int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002092sys_utimes(struct tcb *tcp)
2093{
Roland McGrath6afc5652007-07-24 01:57:11 +00002094 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002095}
2096
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002097int
2098sys_futimesat(struct tcb *tcp)
2099{
2100 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002101 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002102 return decode_utimes(tcp, 1, 0);
2103}
2104
2105int
2106sys_utimensat(struct tcb *tcp)
2107{
2108 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002109 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002110 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002111 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00002112 printflags(at_flags, tcp->u_arg[3], "AT_???");
Roland McGrath6afc5652007-07-24 01:57:11 +00002113 }
2114 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002115}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002116
2117int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002118sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002119{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002120 union {
2121 long utl[2];
2122 int uti[2];
Denys Vlasenko751acb32013-02-08 15:34:46 +01002123 long paranoia_for_huge_wordsize[4];
Roland McGrath7e9817c2007-07-05 20:31:58 +00002124 } u;
Denys Vlasenko751acb32013-02-08 15:34:46 +01002125 unsigned wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002126
2127 if (entering(tcp)) {
2128 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002129 tprints(", ");
Denys Vlasenko751acb32013-02-08 15:34:46 +01002130
2131 wordsize = current_wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002132 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002133 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002134 else if (!verbose(tcp))
2135 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002136 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002137 tprints("[?, ?]");
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002138 else if (wordsize == sizeof u.utl[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002139 tprintf("[%s,", sprinttime(u.utl[0]));
2140 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002141 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002142 else if (wordsize == sizeof u.uti[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002143 tprintf("[%s,", sprinttime(u.uti[0]));
2144 tprintf(" %s]", sprinttime(u.uti[1]));
2145 }
2146 else
Denys Vlasenko751acb32013-02-08 15:34:46 +01002147 tprintf("<decode error: unsupported wordsize %d>",
2148 wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002149 }
2150 return 0;
2151}
2152
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002153static int
2154decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002155{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002156 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002157
2158 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002159 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002160 tprintf(", %s", sprintmode(mode));
2161 switch (mode & S_IFMT) {
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002162 case S_IFCHR:
2163 case S_IFBLK:
Denys Vlasenko9472a272013-02-12 11:43:46 +01002164#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002165 if (current_personality == 1)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002166 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002167 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2168 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002169 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002170#endif
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002171 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002172 (unsigned long) major(tcp->u_arg[offset + 2]),
2173 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002174 break;
2175 default:
2176 break;
2177 }
2178 }
2179 return 0;
2180}
2181
2182int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002183sys_mknod(struct tcb *tcp)
2184{
2185 return decode_mknod(tcp, 0);
2186}
2187
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002188int
2189sys_mknodat(struct tcb *tcp)
2190{
2191 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002192 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002193 return decode_mknod(tcp, 1);
2194}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002195
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002196static void
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002197print_old_dirent(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002198{
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002199#ifdef SH64
2200 typedef struct kernel_dirent old_dirent_t;
2201#else
2202 typedef struct {
2203 uint32_t d_ino;
2204 uint32_t d_off;
2205 unsigned short d_reclen;
2206 char d_name[1];
2207 } old_dirent_t;
2208#endif
2209 old_dirent_t d;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002210
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002211 if (!verbose(tcp) || umove(tcp, addr, &d) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002212 tprintf("%#lx", addr);
2213 return;
2214 }
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002215
2216 tprintf("{d_ino=%lu, d_off=%lu, d_reclen=%u, d_name=\"",
2217 (unsigned long) d.d_ino, (unsigned long) d.d_off, d.d_reclen);
2218 if (d.d_reclen > 256)
2219 d.d_reclen = 256;
2220 printpathn(tcp, addr + offsetof(old_dirent_t, d_name), d.d_reclen);
2221 tprints("\"}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002222}
2223
2224int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002225sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002226{
2227 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002228 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002229 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002230 } else {
2231 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2232 tprintf("%#lx", tcp->u_arg[1]);
2233 else
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002234 print_old_dirent(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002235 /* Not much point in printing this out, it is always 1. */
2236 if (tcp->u_arg[2] != 1)
2237 tprintf(", %lu", tcp->u_arg[2]);
2238 }
2239 return 0;
2240}
2241
Roland McGratha4d48532005-06-08 20:45:28 +00002242static const struct xlat direnttypes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002243 { DT_UNKNOWN, "DT_UNKNOWN" },
2244 { DT_FIFO, "DT_FIFO" },
2245 { DT_CHR, "DT_CHR" },
2246 { DT_DIR, "DT_DIR" },
2247 { DT_BLK, "DT_BLK" },
2248 { DT_REG, "DT_REG" },
2249 { DT_LNK, "DT_LNK" },
2250 { DT_SOCK, "DT_SOCK" },
2251 { DT_WHT, "DT_WHT" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002252 { 0, NULL },
2253};
2254
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002255int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002256sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002257{
2258 int i, len, dents = 0;
2259 char *buf;
2260
2261 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002262 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002263 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002264 return 0;
2265 }
2266 if (syserror(tcp) || !verbose(tcp)) {
2267 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2268 return 0;
2269 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002270 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002271 /* Beware of insanely large or negative values in tcp->u_rval */
2272 if (tcp->u_rval > 1024*1024)
2273 len = 1024*1024;
2274 if (tcp->u_rval < 0)
2275 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002276 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002277 if (len && !buf)
2278 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002279 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002280 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002281 free(buf);
2282 return 0;
2283 }
2284 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002285 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002286 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002287 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002288 if (!abbrev(tcp)) {
2289 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2290 i ? " " : "", d->d_ino, d->d_off);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002291 tprintf("d_reclen=%u, d_name=\"%s\", d_type=",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002292 d->d_reclen, d->d_name);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002293 printxval(direnttypes, buf[i + d->d_reclen - 1], "DT_???");
2294 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002295 }
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002296 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002297 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002298 break;
2299 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002300 i += d->d_reclen;
2301 dents++;
2302 }
2303 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002304 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002305 else
2306 tprintf("/* %u entries */", dents);
2307 tprintf(", %lu", tcp->u_arg[2]);
2308 free(buf);
2309 return 0;
2310}
2311
John Hughesbdf48f52001-03-06 15:08:09 +00002312int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002313sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002314{
2315 int i, len, dents = 0;
2316 char *buf;
2317
2318 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002319 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002320 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002321 return 0;
2322 }
2323 if (syserror(tcp) || !verbose(tcp)) {
2324 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2325 return 0;
2326 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002327
John Hughesbdf48f52001-03-06 15:08:09 +00002328 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002329 /* Beware of insanely large or negative tcp->u_rval */
2330 if (tcp->u_rval > 1024*1024)
2331 len = 1024*1024;
2332 if (tcp->u_rval < 0)
2333 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002334 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002335 if (len && !buf)
2336 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002337
John Hughesbdf48f52001-03-06 15:08:09 +00002338 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002339 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002340 free(buf);
2341 return 0;
2342 }
2343 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002344 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002345 for (i = 0; i < len;) {
2346 struct dirent64 *d = (struct dirent64 *) &buf[i];
John Hughesbdf48f52001-03-06 15:08:09 +00002347 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002348 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002349 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002350 d->d_ino,
2351 d->d_off);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002352 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002353 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002354 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002355 tprintf("d_reclen=%u, d_name=\"%s\"}",
2356 d->d_reclen, d->d_name);
2357 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002358 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002359 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002360 break;
2361 }
John Hughesbdf48f52001-03-06 15:08:09 +00002362 i += d->d_reclen;
2363 dents++;
2364 }
2365 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002366 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002367 else
2368 tprintf("/* %u entries */", dents);
2369 tprintf(", %lu", tcp->u_arg[2]);
2370 free(buf);
2371 return 0;
2372}
Roland McGrath186c5ac2002-12-15 23:58:23 +00002373
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002374int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002375sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002376{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002377 if (exiting(tcp)) {
2378 if (syserror(tcp))
2379 tprintf("%#lx", tcp->u_arg[0]);
2380 else
2381 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2382 tprintf(", %lu", tcp->u_arg[1]);
2383 }
2384 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002385}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002386
2387#ifdef HAVE_SYS_ASYNCH_H
2388
2389int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002390sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002391{
2392 struct aio_result_t res;
2393
2394 if (entering(tcp)) {
2395 tprintf("%lu, ", tcp->u_arg[0]);
2396 } else {
2397 if (syserror(tcp))
2398 tprintf("%#lx", tcp->u_arg[1]);
2399 else
2400 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2401 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2402 printxval(whence, tcp->u_arg[4], "L_???");
2403 if (syserror(tcp) || tcp->u_arg[5] == 0
2404 || umove(tcp, tcp->u_arg[5], &res) < 0)
2405 tprintf(", %#lx", tcp->u_arg[5]);
2406 else
2407 tprintf(", {aio_return %d aio_errno %d}",
2408 res.aio_return, res.aio_errno);
2409 }
2410 return 0;
2411}
2412
2413int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002414sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002415{
2416 struct aio_result_t res;
2417
2418 if (entering(tcp)) {
2419 tprintf("%lu, ", tcp->u_arg[0]);
2420 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2421 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2422 printxval(whence, tcp->u_arg[4], "L_???");
2423 }
2424 else {
2425 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002426 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002427 else if (syserror(tcp)
2428 || umove(tcp, tcp->u_arg[5], &res) < 0)
2429 tprintf(", %#lx", tcp->u_arg[5]);
2430 else
2431 tprintf(", {aio_return %d aio_errno %d}",
2432 res.aio_return, res.aio_errno);
2433 }
2434 return 0;
2435}
2436
2437int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002438sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002439{
2440 if (entering(tcp))
2441 printtv(tcp, tcp->u_arg[0]);
2442 return 0;
2443}
2444
2445int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002446sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002447{
2448 struct aio_result_t res;
2449
2450 if (exiting(tcp)) {
2451 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002452 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002453 else if (syserror(tcp)
2454 || umove(tcp, tcp->u_arg[0], &res) < 0)
2455 tprintf("%#lx", tcp->u_arg[0]);
2456 else
2457 tprintf("{aio_return %d aio_errno %d}",
2458 res.aio_return, res.aio_errno);
2459 }
2460 return 0;
2461}
2462
2463#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002464
Roland McGratha4d48532005-06-08 20:45:28 +00002465static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002466#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002467 { XATTR_CREATE, "XATTR_CREATE" },
2468 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002469#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002470 { 0, NULL }
2471};
2472
Roland McGrath3292e222004-08-31 06:30:48 +00002473static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002474print_xattr_val(struct tcb *tcp, int failed,
2475 unsigned long arg,
2476 unsigned long insize,
2477 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002478{
Dmitry V. Levin1f215132012-12-07 21:38:52 +00002479 if (insize == 0)
2480 failed = 1;
Denys Vlasenko1d632462009-04-14 12:51:00 +00002481 if (!failed) {
2482 unsigned long capacity = 4 * size + 1;
2483 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2484 if (buf == NULL || /* probably a bogus size argument */
2485 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2486 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002487 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002488 else {
2489 unsigned char *out = buf;
2490 unsigned char *in = &buf[3 * size];
2491 size_t i;
2492 for (i = 0; i < size; ++i) {
Denys Vlasenko5198ed42013-03-06 23:44:23 +01002493 if (in[i] >= ' ' && in[i] <= 0x7e)
Denys Vlasenko1d632462009-04-14 12:51:00 +00002494 *out++ = in[i];
2495 else {
2496#define tohex(n) "0123456789abcdef"[n]
2497 *out++ = '\\';
2498 *out++ = 'x';
2499 *out++ = tohex(in[i] / 16);
2500 *out++ = tohex(in[i] % 16);
2501 }
2502 }
2503 /* Don't print terminating NUL if there is one. */
2504 if (i > 0 && in[i - 1] == '\0')
2505 out -= 4;
2506 *out = '\0';
2507 tprintf(", \"%s\", %ld", buf, insize);
2508 }
2509 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002510 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002511 if (failed)
2512 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002513}
2514
Roland McGrath186c5ac2002-12-15 23:58:23 +00002515int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002516sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002517{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002518 if (entering(tcp)) {
2519 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002520 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002521 printstr(tcp, tcp->u_arg[1], -1);
2522 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002523 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002524 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2525 }
2526 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002527}
2528
2529int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002530sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002531{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002532 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002533 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002534 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002535 printstr(tcp, tcp->u_arg[1], -1);
2536 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002537 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002538 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2539 }
2540 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002541}
2542
2543int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002544sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002545{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002546 if (entering(tcp)) {
2547 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002548 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002549 printstr(tcp, tcp->u_arg[1], -1);
2550 } else {
2551 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2552 tcp->u_rval);
2553 }
2554 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002555}
2556
2557int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002558sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002559{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002560 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002561 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002562 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002563 printstr(tcp, tcp->u_arg[1], -1);
2564 } else {
2565 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2566 tcp->u_rval);
2567 }
2568 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002569}
2570
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002571static void
2572print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2573{
2574 if (syserror(tcp)) {
2575 tprintf("%#lx", addr);
2576 } else {
2577 if (!addr) {
2578 tprints("NULL");
2579 } else {
2580 unsigned long len =
2581 (size < tcp->u_rval) ? size : tcp->u_rval;
2582 printstr(tcp, addr, len);
2583 }
2584 }
2585 tprintf(", %lu", size);
2586}
2587
Roland McGrath186c5ac2002-12-15 23:58:23 +00002588int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002589sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002590{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002591 if (entering(tcp)) {
2592 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002593 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002594 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002595 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002596 }
2597 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002598}
2599
2600int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002601sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002602{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002603 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002604 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002605 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002606 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002607 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002608 }
2609 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002610}
2611
2612int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002613sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002614{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002615 if (entering(tcp)) {
2616 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002617 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002618 printstr(tcp, tcp->u_arg[1], -1);
2619 }
2620 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002621}
2622
2623int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002624sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002625{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002626 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002627 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002628 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002629 printstr(tcp, tcp->u_arg[1], -1);
2630 }
2631 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002632}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002633
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002634static const struct xlat advise[] = {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002635 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2636 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2637 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2638 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2639 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2640 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2641 { 0, NULL }
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002642};
2643
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002644int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002645sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002646{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002647 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002648 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002649 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002650 argn = printllval(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002651 tprintf(", %ld, ", tcp->u_arg[argn++]);
2652 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002653 }
2654 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002655}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002656
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002657int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002658sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002659{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002660 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002661 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002662 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002663 argn = printllval(tcp, ", %lld, ", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002664 argn = printllval(tcp, "%lld, ", argn);
Dmitry V. Levin8e096c42013-05-06 18:23:01 +00002665#if defined __ARM_EABI__ || defined AARCH64 || defined POWERPC || defined XTENSA
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002666 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002667#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002668 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002669#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002670 }
2671 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002672}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002673
William Manley16b9dcf2013-08-09 18:04:11 +01002674static const struct xlat sync_file_range_flags[] = {
2675 { SYNC_FILE_RANGE_WAIT_BEFORE, "SYNC_FILE_RANGE_WAIT_BEFORE" },
2676 { SYNC_FILE_RANGE_WRITE, "SYNC_FILE_RANGE_WRITE" },
2677 { SYNC_FILE_RANGE_WAIT_AFTER, "SYNC_FILE_RANGE_WAIT_AFTER" },
2678 { 0, NULL }
2679};
2680
2681int
2682sys_sync_file_range(struct tcb *tcp)
2683{
2684 if (entering(tcp)) {
2685 int argn;
2686 printfd(tcp, tcp->u_arg[0]);
2687 argn = printllval(tcp, ", %lld, ", 1);
2688 argn = printllval(tcp, "%lld, ", argn);
2689 printflags(sync_file_range_flags, tcp->u_arg[argn],
2690 "SYNC_FILE_RANGE_???");
2691 }
2692 return 0;
2693}
2694
2695int
2696sys_sync_file_range2(struct tcb *tcp)
2697{
2698 if (entering(tcp)) {
2699 int argn;
2700 printfd(tcp, tcp->u_arg[0]);
2701 printflags(sync_file_range_flags, 1,
2702 "SYNC_FILE_RANGE_???");
2703 argn = printllval(tcp, ", %lld, ", 2);
2704 argn = printllval(tcp, "%lld, ", argn);
2705 }
2706 return 0;
2707}
2708
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002709static const struct xlat inotify_modes[] = {
Dmitry V. Levind475c062011-03-03 01:02:41 +00002710 { 0x00000001, "IN_ACCESS" },
2711 { 0x00000002, "IN_MODIFY" },
2712 { 0x00000004, "IN_ATTRIB" },
2713 { 0x00000008, "IN_CLOSE_WRITE"},
2714 { 0x00000010, "IN_CLOSE_NOWRITE"},
2715 { 0x00000020, "IN_OPEN" },
2716 { 0x00000040, "IN_MOVED_FROM" },
2717 { 0x00000080, "IN_MOVED_TO" },
2718 { 0x00000100, "IN_CREATE" },
2719 { 0x00000200, "IN_DELETE" },
2720 { 0x00000400, "IN_DELETE_SELF"},
2721 { 0x00000800, "IN_MOVE_SELF" },
2722 { 0x00002000, "IN_UNMOUNT" },
2723 { 0x00004000, "IN_Q_OVERFLOW" },
2724 { 0x00008000, "IN_IGNORED" },
2725 { 0x01000000, "IN_ONLYDIR" },
2726 { 0x02000000, "IN_DONT_FOLLOW"},
2727 { 0x20000000, "IN_MASK_ADD" },
2728 { 0x40000000, "IN_ISDIR" },
2729 { 0x80000000, "IN_ONESHOT" },
2730 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002731};
2732
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002733static const struct xlat inotify_init_flags[] = {
2734 { 0x00000800, "IN_NONBLOCK" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002735 { 0x00080000, "IN_CLOEXEC" },
2736 { 0, NULL }
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002737};
2738
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002739int
2740sys_inotify_add_watch(struct tcb *tcp)
2741{
2742 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002743 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002744 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002745 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002746 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002747 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2748 }
2749 return 0;
2750}
2751
2752int
2753sys_inotify_rm_watch(struct tcb *tcp)
2754{
2755 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002756 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levinab1a70c2012-03-11 15:33:34 +00002757 tprintf(", %d", (int) tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002758 }
2759 return 0;
2760}
Roland McGrath96a96612008-05-20 04:56:18 +00002761
2762int
Mark Wielaardbab89402010-03-21 14:41:26 +01002763sys_inotify_init1(struct tcb *tcp)
2764{
2765 if (entering(tcp))
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002766 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
Mark Wielaardbab89402010-03-21 14:41:26 +01002767 return 0;
2768}
2769
2770int
Roland McGrath96a96612008-05-20 04:56:18 +00002771sys_fallocate(struct tcb *tcp)
2772{
2773 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002774 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002775 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002776 tprintf(", %#lo, ", tcp->u_arg[1]); /* mode */
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002777 argn = printllval(tcp, "%llu, ", 2); /* offset */
2778 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002779 }
2780 return 0;
2781}
Dmitry V. Levin88293652012-03-09 21:02:19 +00002782
Dmitry V. Levinad0c01e2012-03-15 00:52:22 +00002783#ifndef SWAP_FLAG_PREFER
2784# define SWAP_FLAG_PREFER 0x8000
2785#endif
2786#ifndef SWAP_FLAG_DISCARD
2787# define SWAP_FLAG_DISCARD 0x10000
2788#endif
Dmitry V. Levin88293652012-03-09 21:02:19 +00002789static const struct xlat swap_flags[] = {
2790 { SWAP_FLAG_PREFER, "SWAP_FLAG_PREFER" },
2791 { SWAP_FLAG_DISCARD, "SWAP_FLAG_DISCARD" },
2792 { 0, NULL }
2793};
2794
2795int
2796sys_swapon(struct tcb *tcp)
2797{
2798 if (entering(tcp)) {
2799 int flags = tcp->u_arg[1];
2800 printpath(tcp, tcp->u_arg[0]);
2801 tprints(", ");
2802 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2803 "SWAP_FLAG_???");
2804 if (flags & SWAP_FLAG_PREFER)
2805 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);
2806 }
2807 return 0;
2808}