blob: 016fc94daf9a86c0772c2801c15004c2c4d17c1c [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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000277#ifdef FNDELAY
278 { FNDELAY, "FNDELAY" },
279#endif
280#ifdef FAPPEND
281 { FAPPEND, "FAPPEND" },
282#endif
283#ifdef FMARK
284 { FMARK, "FMARK" },
285#endif
286#ifdef FDEFER
287 { FDEFER, "FDEFER" },
288#endif
289#ifdef FASYNC
290 { FASYNC, "FASYNC" },
291#endif
292#ifdef FSHLOCK
293 { FSHLOCK, "FSHLOCK" },
294#endif
295#ifdef FEXLOCK
296 { FEXLOCK, "FEXLOCK" },
297#endif
298#ifdef FCREAT
299 { FCREAT, "FCREAT" },
300#endif
301#ifdef FTRUNC
302 { FTRUNC, "FTRUNC" },
303#endif
304#ifdef FEXCL
305 { FEXCL, "FEXCL" },
306#endif
307#ifdef FNBIO
308 { FNBIO, "FNBIO" },
309#endif
310#ifdef FSYNC
311 { FSYNC, "FSYNC" },
312#endif
313#ifdef FNOCTTY
314 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000315#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000316#ifdef O_SHLOCK
317 { O_SHLOCK, "O_SHLOCK" },
318#endif
319#ifdef O_EXLOCK
320 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000321#endif
322 { 0, NULL },
323};
324
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000325#ifndef AT_FDCWD
326# define AT_FDCWD -100
327#endif
328
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000329/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
330 * extension to get the right value. We do this by declaring fd as int here.
331 */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000332static void
Dmitry V. Levin31382132011-03-04 05:08:02 +0300333print_dirfd(struct tcb *tcp, int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000334{
335 if (fd == AT_FDCWD)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200336 tprints("AT_FDCWD, ");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200337 else {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300338 printfd(tcp, fd);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200339 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300340 }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000341}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000342
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000343/*
344 * low bits of the open(2) flags define access mode,
345 * other bits are real flags.
346 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000347const char *
348sprint_open_modes(mode_t flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000349{
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100350 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000351 char *p;
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100352 char sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000353 const char *str;
354 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000355
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100356 sep = ' ';
357 p = stpcpy(outstr, "flags");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000358 str = xlookup(open_access_modes, flags & 3);
359 if (str) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100360 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200361 p = stpcpy(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000362 flags &= ~3;
363 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000364 return outstr;
365 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000366 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000367
368 for (x = open_mode_flags; x->str; x++) {
369 if ((flags & x->val) == x->val) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100370 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200371 p = stpcpy(p, x->str);
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000372 flags &= ~x->val;
373 if (!flags)
374 return outstr;
375 sep = '|';
376 }
377 }
378 /* flags is still nonzero */
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100379 *p++ = sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000380 sprintf(p, "%#x", flags);
381 return outstr;
382}
383
384void
385tprint_open_modes(mode_t flags)
386{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200387 tprints(sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000388}
389
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000390static int
391decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000392{
393 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000394 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200395 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000396 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000397 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000398 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000399 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000400 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000401 }
402 }
403 return 0;
404}
405
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000406int
407sys_open(struct tcb *tcp)
408{
409 return decode_open(tcp, 0);
410}
411
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000412int
413sys_openat(struct tcb *tcp)
414{
415 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300416 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000417 return decode_open(tcp, 1);
418}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000419
Denys Vlasenko9472a272013-02-12 11:43:46 +0100420#if defined(SPARC) || defined(SPARC64)
Roland McGratha4d48532005-06-08 20:45:28 +0000421static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000422 { 0, "O_RDWR" },
423 { 1, "O_RDONLY" },
424 { 2, "O_WRONLY" },
425 { 0x80, "O_NONBLOCK" },
426 { 8, "O_APPEND" },
427 { 0x100, "O_CREAT" },
428 { 0x200, "O_TRUNC" },
429 { 0x400, "O_EXCL" },
430 { 0x800, "O_NOCTTY" },
431 { 0x10, "O_SYNC" },
432 { 0x40, "O_DSYNC" },
433 { 0x8000, "O_RSYNC" },
434 { 4, "O_NDELAY" },
435 { 0x1000, "O_PRIV" },
436 { 0, NULL },
437};
438
439int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000440solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000441{
442 if (entering(tcp)) {
443 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200444 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000445 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000446 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000447 if (tcp->u_arg[1] & 0x100) {
448 /* mode */
449 tprintf(", %#lo", tcp->u_arg[2]);
450 }
451 }
452 return 0;
453}
454
455#endif
456
457int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000458sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000459{
460 if (entering(tcp)) {
461 printpath(tcp, tcp->u_arg[0]);
462 tprintf(", %#lo", tcp->u_arg[1]);
463 }
464 return 0;
465}
466
Roland McGrathd9f816f2004-09-04 03:39:20 +0000467static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000468 { F_OK, "F_OK", },
469 { R_OK, "R_OK" },
470 { W_OK, "W_OK" },
471 { X_OK, "X_OK" },
472#ifdef EFF_ONLY_OK
473 { EFF_ONLY_OK, "EFF_ONLY_OK" },
474#endif
475#ifdef EX_OK
476 { EX_OK, "EX_OK" },
477#endif
478 { 0, NULL },
479};
480
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000481static int
482decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000483{
484 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000485 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200486 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000487 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000488 }
489 return 0;
490}
491
492int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000493sys_access(struct tcb *tcp)
494{
495 return decode_access(tcp, 0);
496}
497
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000498int
499sys_faccessat(struct tcb *tcp)
500{
501 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300502 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000503 return decode_access(tcp, 1);
504}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000505
506int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000507sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000508{
509 if (entering(tcp)) {
510 tprintf("%#lo", tcp->u_arg[0]);
511 }
512 return RVAL_OCTAL;
513}
514
Denys Vlasenko86738a22013-02-17 14:31:55 +0100515const struct xlat whence_codes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000516 { SEEK_SET, "SEEK_SET" },
517 { SEEK_CUR, "SEEK_CUR" },
518 { SEEK_END, "SEEK_END" },
Denys Vlasenko86738a22013-02-17 14:31:55 +0100519#ifdef SEEK_DATA
520 { SEEK_DATA, "SEEK_DATA" },
521#endif
522#ifdef SEEK_HOLE
523 { SEEK_HOLE, "SEEK_HOLE" },
524#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525 { 0, NULL },
526};
527
Denys Vlasenko386b8712013-02-17 01:38:14 +0100528/* Linux kernel has exactly one version of lseek:
529 * fs/read_write.c::SYSCALL_DEFINE3(lseek, unsigned, fd, off_t, offset, unsigned, origin)
530 * In kernel, off_t is always the same as (kernel's) long
531 * (see include/uapi/asm-generic/posix_types.h),
532 * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument.
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100533 * Use test/x32_lseek.c to test lseek decoding.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100534 */
H.J. Luc933f272012-04-16 17:41:13 +0200535#if defined(LINUX_MIPSN32) || defined(X32)
Roland McGrath542c2c62008-05-20 01:11:56 +0000536int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000537sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000538{
539 long long offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100540 int whence;
Roland McGrath542c2c62008-05-20 01:11:56 +0000541
542 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300543 printfd(tcp, tcp->u_arg[0]);
Roland McGrath542c2c62008-05-20 01:11:56 +0000544 offset = tcp->ext_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100545 whence = tcp->u_arg[2];
546 if (whence == SEEK_SET)
547 tprintf(", %llu, ", offset);
Roland McGrath542c2c62008-05-20 01:11:56 +0000548 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100549 tprintf(", %lld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100550 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath542c2c62008-05-20 01:11:56 +0000551 }
H.J. Ludd0130b2012-04-16 12:16:45 +0200552 return RVAL_LUDECIMAL;
Roland McGrath542c2c62008-05-20 01:11:56 +0000553}
H.J. Ludd0130b2012-04-16 12:16:45 +0200554#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000555int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000556sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000557{
Denys Vlasenko06121762013-02-17 20:08:50 +0100558 long offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100559 int whence;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000560
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000561 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300562 printfd(tcp, tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000563 offset = tcp->u_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100564 whence = tcp->u_arg[2];
565 if (whence == SEEK_SET)
566 tprintf(", %lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000567 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100568 tprintf(", %ld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100569 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000570 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000571 return RVAL_UDECIMAL;
572}
John Hughes5a826b82001-03-07 13:21:24 +0000573#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000574
Denys Vlasenko386b8712013-02-17 01:38:14 +0100575/* llseek syscall takes explicitly two ulong arguments hi, lo,
576 * rather than one 64-bit argument for which LONG_LONG works
577 * appropriate for the native byte order.
578 *
579 * See kernel's fs/read_write.c::SYSCALL_DEFINE5(llseek, ...)
580 *
581 * hi,lo are "unsigned longs" and combined exactly this way in kernel:
582 * ((loff_t) hi << 32) | lo
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100583 * Note that for architectures with kernel's long wider than userspace long
Denys Vlasenko386b8712013-02-17 01:38:14 +0100584 * (such as x32), combining code will use *kernel's*, i.e. *wide* longs
Denys Vlasenko06121762013-02-17 20:08:50 +0100585 * for hi and lo. We would need to use tcp->ext_arg[N] on x32...
586 * ...however, x32 (and x86_64) does not _have_ llseek syscall as such.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100587 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000588int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000589sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000590{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000591 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300592 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000593 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300594 tprintf(", %llu, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100595 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300596 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000597 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300598 tprintf(", %lld, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100599 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300600 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000601 }
602 else {
Denys Vlasenko386b8712013-02-17 01:38:14 +0100603 long long off;
Denys Vlasenko1d632462009-04-14 12:51:00 +0000604 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
605 tprintf("%#lx, ", tcp->u_arg[3]);
606 else
607 tprintf("[%llu], ", off);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100608 printxval(whence_codes, tcp->u_arg[4], "SEEK_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000609 }
610 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000611}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000612
613int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000614sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000615{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000616 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100617 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300618 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +0200619 argn = printllval(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100620 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000621 }
622 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000623}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000624
625int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000626sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000627{
628 if (entering(tcp)) {
629 printpath(tcp, tcp->u_arg[0]);
630 tprintf(", %lu", tcp->u_arg[1]);
631 }
632 return 0;
633}
634
Denys Vlasenko8435d672013-02-18 15:47:57 +0100635#if _LFS64_LARGEFILE
John Hughes96f51472001-03-06 16:50:41 +0000636int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000637sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000638{
639 if (entering(tcp)) {
640 printpath(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100641 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000642 }
643 return 0;
644}
645#endif
646
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000647int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000648sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000649{
650 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300651 printfd(tcp, tcp->u_arg[0]);
652 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000653 }
654 return 0;
655}
656
Denys Vlasenko8435d672013-02-18 15:47:57 +0100657#if _LFS64_LARGEFILE
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}
667#endif
668
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000669/* several stats */
670
Roland McGrathd9f816f2004-09-04 03:39:20 +0000671static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000672 { S_IFREG, "S_IFREG" },
673 { S_IFSOCK, "S_IFSOCK" },
674 { S_IFIFO, "S_IFIFO" },
675 { S_IFLNK, "S_IFLNK" },
676 { S_IFDIR, "S_IFDIR" },
677 { S_IFBLK, "S_IFBLK" },
678 { S_IFCHR, "S_IFCHR" },
679 { 0, NULL },
680};
681
Roland McGrathf9c49b22004-10-06 22:11:54 +0000682static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000683sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000684{
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100685 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
686 + sizeof(int)*3
687 + /*paranoia:*/ 8];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000688 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000689
690 if ((mode & S_IFMT) == 0)
691 s = "";
692 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
693 sprintf(buf, "%#o", mode);
694 return buf;
695 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100696 s = buf + sprintf(buf, "%s%s%s%s", s,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000697 (mode & S_ISUID) ? "|S_ISUID" : "",
698 (mode & S_ISGID) ? "|S_ISGID" : "",
699 (mode & S_ISVTX) ? "|S_ISVTX" : "");
700 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
701 if (mode)
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100702 sprintf((char*)s, "|%#o", mode);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000703 s = (*buf == '|') ? buf + 1 : buf;
704 return *s ? s : "0";
705}
706
707static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000708sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000709{
710 struct tm *tmp;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100711 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000712
713 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000714 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000715 return buf;
716 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200717 tmp = localtime(&t);
718 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000719 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
720 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
721 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
722 else
723 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
724
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000725 return buf;
726}
727
Denys Vlasenko9472a272013-02-12 11:43:46 +0100728#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000729typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000730 int tv_sec;
731 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000732} timestruct_t;
733
734struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000735 unsigned st_dev;
736 int st_pad1[3]; /* network id */
737 unsigned st_ino;
738 unsigned st_mode;
739 unsigned st_nlink;
740 unsigned st_uid;
741 unsigned st_gid;
742 unsigned st_rdev;
743 int st_pad2[2];
744 int st_size;
745 int st_pad3; /* st_size, off_t expansion */
746 timestruct_t st_atime;
747 timestruct_t st_mtime;
748 timestruct_t st_ctime;
749 int st_blksize;
750 int st_blocks;
751 char st_fstype[16];
752 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000753};
754
755static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000756printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000757{
758 struct solstat statbuf;
759
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000760 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200761 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000762 return;
763 }
764 if (!abbrev(tcp)) {
765 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
766 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
767 (unsigned long) (statbuf.st_dev & 0x3ffff),
768 (unsigned long) statbuf.st_ino,
769 sprintmode(statbuf.st_mode));
770 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
771 (unsigned long) statbuf.st_nlink,
772 (unsigned long) statbuf.st_uid,
773 (unsigned long) statbuf.st_gid);
774 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
775 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
776 }
777 else
778 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
779 switch (statbuf.st_mode & S_IFMT) {
780 case S_IFCHR: case S_IFBLK:
781 tprintf("st_rdev=makedev(%lu, %lu), ",
782 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
783 (unsigned long) (statbuf.st_rdev & 0x3ffff));
784 break;
785 default:
786 tprintf("st_size=%u, ", statbuf.st_size);
787 break;
788 }
789 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000790 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
791 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
792 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000793 }
794 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200795 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000796}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000797
Denys Vlasenko9472a272013-02-12 11:43:46 +0100798# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000799static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000800printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000801{
802 struct stat_sparc64 statbuf;
803
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000804 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200805 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000806 return;
807 }
808
809 if (!abbrev(tcp)) {
810 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
811 (unsigned long) major(statbuf.st_dev),
812 (unsigned long) minor(statbuf.st_dev),
813 (unsigned long) statbuf.st_ino,
814 sprintmode(statbuf.st_mode));
815 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
816 (unsigned long) statbuf.st_nlink,
817 (unsigned long) statbuf.st_uid,
818 (unsigned long) statbuf.st_gid);
819 tprintf("st_blksize=%lu, ",
820 (unsigned long) statbuf.st_blksize);
821 tprintf("st_blocks=%lu, ",
822 (unsigned long) statbuf.st_blocks);
823 }
824 else
825 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
826 switch (statbuf.st_mode & S_IFMT) {
827 case S_IFCHR: case S_IFBLK:
828 tprintf("st_rdev=makedev(%lu, %lu), ",
829 (unsigned long) major(statbuf.st_rdev),
830 (unsigned long) minor(statbuf.st_rdev));
831 break;
832 default:
833 tprintf("st_size=%lu, ", statbuf.st_size);
834 break;
835 }
836 if (!abbrev(tcp)) {
837 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
838 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100839 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000840 }
841 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200842 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000843}
Denys Vlasenko9472a272013-02-12 11:43:46 +0100844# endif /* SPARC64 */
845#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000846
Denys Vlasenko84703742012-02-25 02:38:52 +0100847#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200848struct stat_powerpc32 {
849 unsigned int st_dev;
850 unsigned int st_ino;
851 unsigned int st_mode;
852 unsigned short st_nlink;
853 unsigned int st_uid;
854 unsigned int st_gid;
855 unsigned int st_rdev;
856 unsigned int st_size;
857 unsigned int st_blksize;
858 unsigned int st_blocks;
859 unsigned int st_atime;
860 unsigned int st_atime_nsec;
861 unsigned int st_mtime;
862 unsigned int st_mtime_nsec;
863 unsigned int st_ctime;
864 unsigned int st_ctime_nsec;
865 unsigned int __unused4;
866 unsigned int __unused5;
867};
868
869static void
870printstat_powerpc32(struct tcb *tcp, long addr)
871{
872 struct stat_powerpc32 statbuf;
873
874 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200875 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200876 return;
877 }
878
879 if (!abbrev(tcp)) {
880 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
881 major(statbuf.st_dev), minor(statbuf.st_dev),
882 statbuf.st_ino,
883 sprintmode(statbuf.st_mode));
884 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
885 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
886 tprintf("st_blksize=%u, ", statbuf.st_blksize);
887 tprintf("st_blocks=%u, ", statbuf.st_blocks);
888 }
889 else
890 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
891 switch (statbuf.st_mode & S_IFMT) {
892 case S_IFCHR: case S_IFBLK:
893 tprintf("st_rdev=makedev(%lu, %lu), ",
894 (unsigned long) major(statbuf.st_rdev),
895 (unsigned long) minor(statbuf.st_rdev));
896 break;
897 default:
898 tprintf("st_size=%u, ", statbuf.st_size);
899 break;
900 }
901 if (!abbrev(tcp)) {
902 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
903 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100904 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200905 }
906 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200907 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200908}
Denys Vlasenko84703742012-02-25 02:38:52 +0100909#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200910
Roland McGratha4d48532005-06-08 20:45:28 +0000911static const struct xlat fileflags[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000912 { 0, NULL },
913};
914
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000915static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000916realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000917{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000918 if (!abbrev(tcp)) {
919 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
920 (unsigned long) major(statbuf->st_dev),
921 (unsigned long) minor(statbuf->st_dev),
922 (unsigned long) statbuf->st_ino,
923 sprintmode(statbuf->st_mode));
924 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
925 (unsigned long) statbuf->st_nlink,
926 (unsigned long) statbuf->st_uid,
927 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000928#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000929 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
930#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000931#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000932 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
933#endif
934 }
935 else
936 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
937 switch (statbuf->st_mode & S_IFMT) {
938 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000939#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000940 tprintf("st_rdev=makedev(%lu, %lu), ",
941 (unsigned long) major(statbuf->st_rdev),
942 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000943#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000944 tprintf("st_size=makedev(%lu, %lu), ",
945 (unsigned long) major(statbuf->st_size),
946 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000947#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000948 break;
949 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000950 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000951 break;
952 }
953 if (!abbrev(tcp)) {
954 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
955 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
956 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000957#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200958 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000959 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000960#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000961#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000962 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
963#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000964#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000965 tprintf(", st_level=%ld", statbuf->st_level);
966#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000967#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000968 tprintf(", st_fstype=%.*s",
969 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
970#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000971#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000972 tprintf(", st_gen=%u", statbuf->st_gen);
973#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200974 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000975 }
976 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200977 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000978}
979
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000980#ifndef X32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000981static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000982printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000983{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000984 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000985
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000986 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200987 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000988 return;
989 }
990 if (syserror(tcp) || !verbose(tcp)) {
991 tprintf("%#lx", addr);
992 return;
993 }
994
Denys Vlasenko9472a272013-02-12 11:43:46 +0100995#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000996 if (current_personality == 1) {
997 printstatsol(tcp, addr);
998 return;
999 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001000#ifdef SPARC64
1001 else if (current_personality == 2) {
1002 printstat_sparc64(tcp, addr);
1003 return;
1004 }
1005#endif
Denys Vlasenko9472a272013-02-12 11:43:46 +01001006#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001007
Denys Vlasenko84703742012-02-25 02:38:52 +01001008#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +02001009 if (current_personality == 1) {
1010 printstat_powerpc32(tcp, addr);
1011 return;
1012 }
1013#endif
1014
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001015 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001016 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001017 return;
1018 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001019
1020 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001021}
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001022#else /* X32 */
1023# define printstat printstat64
1024#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001025
Denys Vlasenko84703742012-02-25 02:38:52 +01001026#if !defined HAVE_STAT64 && defined X86_64
Roland McGrathe6d0f712007-08-07 01:22:49 +00001027/*
1028 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1029 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1030 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1031 * __GNUC__ is needed for the required __attribute__ below.
1032 */
1033struct stat64 {
1034 unsigned long long st_dev;
1035 unsigned char __pad0[4];
1036 unsigned int __st_ino;
1037 unsigned int st_mode;
1038 unsigned int st_nlink;
1039 unsigned int st_uid;
1040 unsigned int st_gid;
1041 unsigned long long st_rdev;
1042 unsigned char __pad3[4];
1043 long long st_size;
1044 unsigned int st_blksize;
1045 unsigned long long st_blocks;
1046 unsigned int st_atime;
1047 unsigned int st_atime_nsec;
1048 unsigned int st_mtime;
1049 unsigned int st_mtime_nsec;
1050 unsigned int st_ctime;
1051 unsigned int st_ctime_nsec;
1052 unsigned long long st_ino;
1053} __attribute__((packed));
1054# define HAVE_STAT64 1
1055# define STAT64_SIZE 96
1056#endif
1057
Wichert Akkermanc7926982000-04-10 22:22:31 +00001058#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001059static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001060printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001061{
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001062#ifdef X32
1063 struct stat statbuf;
1064#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001065 struct stat64 statbuf;
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001066#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001067
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001068#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001069 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1070#endif
1071
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001072 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001073 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001074 return;
1075 }
1076 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001077 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001078 return;
1079 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001080
Denys Vlasenko9472a272013-02-12 11:43:46 +01001081#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001082 if (current_personality == 1) {
1083 printstatsol(tcp, addr);
1084 return;
1085 }
1086# ifdef SPARC64
1087 else if (current_personality == 2) {
1088 printstat_sparc64(tcp, addr);
1089 return;
1090 }
1091# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +01001092#endif /* SPARC[64] */
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001093
Denys Vlasenko84703742012-02-25 02:38:52 +01001094#if defined X86_64
H.J. Lu35be5812012-04-16 13:00:01 +02001095 if (current_personality != 1) {
Andreas Schwab61b74352009-10-16 11:37:13 +02001096 printstat(tcp, addr);
1097 return;
1098 }
1099#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +00001100
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001101 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001102 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001103 return;
1104 }
1105
1106 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001107#ifdef HAVE_LONG_LONG
1108 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1109#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001110 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001111#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001112 (unsigned long) major(statbuf.st_dev),
1113 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001114#ifdef HAVE_LONG_LONG
1115 (unsigned long long) statbuf.st_ino,
1116#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001117 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001118#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001119 sprintmode(statbuf.st_mode));
1120 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1121 (unsigned long) statbuf.st_nlink,
1122 (unsigned long) statbuf.st_uid,
1123 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001124#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001125 tprintf("st_blksize=%lu, ",
1126 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001127#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1128#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001129 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001130#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001131 }
1132 else
1133 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1134 switch (statbuf.st_mode & S_IFMT) {
1135 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001136#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001137 tprintf("st_rdev=makedev(%lu, %lu), ",
1138 (unsigned long) major(statbuf.st_rdev),
1139 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001140#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001141 tprintf("st_size=makedev(%lu, %lu), ",
1142 (unsigned long) major(statbuf.st_size),
1143 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001144#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001145 break;
1146 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001147#ifdef HAVE_LONG_LONG
1148 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1149#else
1150 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1151#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001152 break;
1153 }
1154 if (!abbrev(tcp)) {
1155 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1156 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001157 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001158#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001159 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001160 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001161#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001162#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001163 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1164#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001165#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001166 tprintf(", st_level=%ld", statbuf.st_level);
1167#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001168#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001169 tprintf(", st_fstype=%.*s",
1170 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1171#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001172#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001173 tprintf(", st_gen=%u", statbuf.st_gen);
1174#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001175 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001176 }
1177 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001178 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001179}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001180#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001181
Denys Vlasenko8435d672013-02-18 15:47:57 +01001182#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001183static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001184convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001185{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001186 newbuf->st_dev = oldbuf->st_dev;
1187 newbuf->st_ino = oldbuf->st_ino;
1188 newbuf->st_mode = oldbuf->st_mode;
1189 newbuf->st_nlink = oldbuf->st_nlink;
1190 newbuf->st_uid = oldbuf->st_uid;
1191 newbuf->st_gid = oldbuf->st_gid;
1192 newbuf->st_rdev = oldbuf->st_rdev;
1193 newbuf->st_size = oldbuf->st_size;
1194 newbuf->st_atime = oldbuf->st_atime;
1195 newbuf->st_mtime = oldbuf->st_mtime;
1196 newbuf->st_ctime = oldbuf->st_ctime;
1197 newbuf->st_blksize = 0; /* not supported in old_stat */
1198 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001199}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001200
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001201static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001202printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001203{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001204 struct __old_kernel_stat statbuf;
1205 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001206
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001207 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001208 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001209 return;
1210 }
1211 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001212 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001213 return;
1214 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001215
Denys Vlasenko9472a272013-02-12 11:43:46 +01001216# if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001217 if (current_personality == 1) {
1218 printstatsol(tcp, addr);
1219 return;
1220 }
Denys Vlasenko84703742012-02-25 02:38:52 +01001221# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001222
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001223 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001224 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001225 return;
1226 }
1227
1228 convertoldstat(&statbuf, &newstatbuf);
1229 realprintstat(tcp, &newstatbuf);
1230}
Denys Vlasenko84703742012-02-25 02:38:52 +01001231#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001232
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001233int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001234sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001235{
1236 if (entering(tcp)) {
1237 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001238 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001239 } else {
1240 printstat(tcp, tcp->u_arg[1]);
1241 }
1242 return 0;
1243}
1244
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001245#ifdef X32
1246static void
1247printstat64_x32(struct tcb *tcp, long addr)
1248{
1249 struct stat64 statbuf;
1250
1251 if (!addr) {
1252 tprints("NULL");
1253 return;
1254 }
1255 if (syserror(tcp) || !verbose(tcp)) {
1256 tprintf("%#lx", addr);
1257 return;
1258 }
1259
1260 if (umove(tcp, addr, &statbuf) < 0) {
1261 tprints("{...}");
1262 return;
1263 }
1264
1265 if (!abbrev(tcp)) {
1266 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1267 (unsigned long) major(statbuf.st_dev),
1268 (unsigned long) minor(statbuf.st_dev),
1269 (unsigned long long) statbuf.st_ino,
1270 sprintmode(statbuf.st_mode));
1271 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1272 (unsigned long) statbuf.st_nlink,
1273 (unsigned long) statbuf.st_uid,
1274 (unsigned long) statbuf.st_gid);
1275 tprintf("st_blksize=%lu, ",
1276 (unsigned long) statbuf.st_blksize);
1277 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1278 }
1279 else
1280 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1281 switch (statbuf.st_mode & S_IFMT) {
1282 case S_IFCHR: case S_IFBLK:
1283 tprintf("st_rdev=makedev(%lu, %lu), ",
1284 (unsigned long) major(statbuf.st_rdev),
1285 (unsigned long) minor(statbuf.st_rdev));
1286 break;
1287 default:
1288 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1289 break;
1290 }
1291 if (!abbrev(tcp)) {
1292 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1293 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1294 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1295 tprints("}");
1296 }
1297 else
1298 tprints("...}");
1299}
1300#endif /* X32 */
1301
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001302int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001303sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001304{
1305#ifdef HAVE_STAT64
1306 if (entering(tcp)) {
1307 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001308 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001309 } else {
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001310# ifdef X32
1311 printstat64_x32(tcp, tcp->u_arg[1]);
1312# else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001313 printstat64(tcp, tcp->u_arg[1]);
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001314# endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001315 }
1316 return 0;
1317#else
1318 return printargs(tcp);
1319#endif
1320}
1321
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001322#ifndef AT_SYMLINK_NOFOLLOW
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001323# define AT_SYMLINK_NOFOLLOW 0x100
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001324#endif
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001325#ifndef AT_REMOVEDIR
1326# define AT_REMOVEDIR 0x200
1327#endif
1328#ifndef AT_SYMLINK_FOLLOW
1329# define AT_SYMLINK_FOLLOW 0x400
1330#endif
1331#ifndef AT_NO_AUTOMOUNT
1332# define AT_NO_AUTOMOUNT 0x800
1333#endif
1334#ifndef AT_EMPTY_PATH
1335# define AT_EMPTY_PATH 0x1000
1336#endif
1337
1338static const struct xlat at_flags[] = {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001339 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001340 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1341 { AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" },
1342 { AT_NO_AUTOMOUNT, "AT_NO_AUTOMOUNT" },
1343 { AT_EMPTY_PATH, "AT_EMPTY_PATH" },
1344 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001345};
1346
1347int
1348sys_newfstatat(struct tcb *tcp)
1349{
1350 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001351 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001352 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001353 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001354 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001355#ifdef POWERPC64
1356 if (current_personality == 0)
1357 printstat(tcp, tcp->u_arg[2]);
1358 else
1359 printstat64(tcp, tcp->u_arg[2]);
1360#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001361 printstat64(tcp, tcp->u_arg[2]);
1362#else
1363 printstat(tcp, tcp->u_arg[2]);
1364#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001365 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001366 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001367 }
1368 return 0;
1369}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001370
Denys Vlasenko8435d672013-02-18 15:47:57 +01001371#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001372int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001373sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001374{
1375 if (entering(tcp)) {
1376 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001377 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001378 } else {
1379 printoldstat(tcp, tcp->u_arg[1]);
1380 }
1381 return 0;
1382}
Denys Vlasenko84703742012-02-25 02:38:52 +01001383#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001384
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001385int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001386sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001387{
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 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001392 printstat(tcp, tcp->u_arg[1]);
1393 }
1394 return 0;
1395}
1396
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001397int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001398sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001399{
1400#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001401 if (entering(tcp)) {
1402 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001403 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001404 } else {
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001405# ifdef X32
1406 printstat64_x32(tcp, tcp->u_arg[1]);
1407# else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001408 printstat64(tcp, tcp->u_arg[1]);
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001409# endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001410 }
1411 return 0;
1412#else
1413 return printargs(tcp);
1414#endif
1415}
1416
Denys Vlasenko8435d672013-02-18 15:47:57 +01001417#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001418int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001419sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001420{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001421 if (entering(tcp)) {
1422 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001423 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001424 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001425 printoldstat(tcp, tcp->u_arg[1]);
1426 }
1427 return 0;
1428}
Denys Vlasenko84703742012-02-25 02:38:52 +01001429#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001430
Denys Vlasenko9472a272013-02-12 11:43:46 +01001431#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001432
1433int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001434sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001435{
1436 if (entering(tcp)) {
1437 tprintf("%ld, ", tcp->u_arg[0]);
1438 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001439 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001440 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001441# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001442 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001443 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001444 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001445# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001446 printstat(tcp, tcp->u_arg[2]);
1447 }
1448 return 0;
1449}
1450
1451int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001452sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001453{
1454 if (entering(tcp))
1455 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1456 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001457# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001458 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001459 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001460 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001461# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001462 printstat(tcp, tcp->u_arg[2]);
1463 }
1464 return 0;
1465}
1466
1467int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001468sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001469{
1470 if (entering(tcp)) {
1471 tprintf("%ld, ", tcp->u_arg[0]);
1472 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001473 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001474 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001475# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001476 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001477 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001478 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001479# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001480 printstat(tcp, tcp->u_arg[2]);
1481 }
1482 return 0;
1483}
1484
1485int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001486sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001487{
1488 int mode = tcp->u_arg[2];
1489
1490 if (entering(tcp)) {
1491 tprintf("%ld, ", tcp->u_arg[0]);
1492 printpath(tcp, tcp->u_arg[1]);
1493 tprintf(", %s", sprintmode(mode));
1494 switch (mode & S_IFMT) {
1495 case S_IFCHR: case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001496 tprintf(", makedev(%lu, %lu)",
1497 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1498 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001499 break;
1500 default:
1501 break;
1502 }
1503 }
1504 return 0;
1505}
1506
Denys Vlasenko84703742012-02-25 02:38:52 +01001507# ifdef HAVE_SYS_ACL_H
Wichert Akkerman8829a551999-06-11 13:18:40 +00001508
Denys Vlasenko84703742012-02-25 02:38:52 +01001509# include <sys/acl.h>
Wichert Akkerman8829a551999-06-11 13:18:40 +00001510
Roland McGratha4d48532005-06-08 20:45:28 +00001511static const struct xlat aclcmds[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001512# ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001513 { SETACL, "SETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001514# endif
1515# ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001516 { GETACL, "GETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001517# endif
1518# ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001519 { GETACLCNT, "GETACLCNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001520# endif
1521# ifdef ACL_GET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001522 { ACL_GET, "ACL_GET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001523# endif
1524# ifdef ACL_SET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001525 { ACL_SET, "ACL_SET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001526# endif
1527# ifdef ACL_CNT
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001528 { ACL_CNT, "ACL_CNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001529# endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001530 { 0, NULL },
1531};
1532
1533int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001534sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001535{
1536 if (entering(tcp)) {
1537 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001538 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001539 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1540 tprintf(", %ld", tcp->u_arg[2]);
1541 /*
1542 * FIXME - dump out the list of aclent_t's pointed to
1543 * by "tcp->u_arg[3]" if it's not NULL.
1544 */
1545 if (tcp->u_arg[3])
1546 tprintf(", %#lx", tcp->u_arg[3]);
1547 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001548 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001549 }
1550 return 0;
1551}
1552
Wichert Akkerman8829a551999-06-11 13:18:40 +00001553int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001554sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001555{
1556 if (entering(tcp)) {
1557 tprintf("%ld, ", tcp->u_arg[0]);
1558 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1559 tprintf(", %ld", tcp->u_arg[2]);
1560 /*
1561 * FIXME - dump out the list of aclent_t's pointed to
1562 * by "tcp->u_arg[3]" if it's not NULL.
1563 */
1564 if (tcp->u_arg[3])
1565 tprintf(", %#lx", tcp->u_arg[3]);
1566 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001567 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001568 }
1569 return 0;
1570}
1571
Roland McGratha4d48532005-06-08 20:45:28 +00001572static const struct xlat aclipc[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001573# ifdef IPC_SHM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001574 { IPC_SHM, "IPC_SHM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001575# endif
1576# ifdef IPC_SEM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001577 { IPC_SEM, "IPC_SEM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001578# endif
1579# ifdef IPC_MSG
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001580 { IPC_MSG, "IPC_MSG" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001581# endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001582 { 0, NULL },
1583};
1584
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001585int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001586sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001587{
1588 if (entering(tcp)) {
1589 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1590 tprintf(", %#lx, ", tcp->u_arg[1]);
1591 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1592 tprintf(", %ld", tcp->u_arg[3]);
1593 /*
1594 * FIXME - dump out the list of aclent_t's pointed to
1595 * by "tcp->u_arg[4]" if it's not NULL.
1596 */
1597 if (tcp->u_arg[4])
1598 tprintf(", %#lx", tcp->u_arg[4]);
1599 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001600 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001601 }
1602 return 0;
1603}
1604
Denys Vlasenko84703742012-02-25 02:38:52 +01001605# endif /* HAVE_SYS_ACL_H */
Wichert Akkerman8829a551999-06-11 13:18:40 +00001606
Denys Vlasenko9472a272013-02-12 11:43:46 +01001607#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001608
Roland McGrathd9f816f2004-09-04 03:39:20 +00001609static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001610 { 0x73757245, "CODA_SUPER_MAGIC" },
1611 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1612 { 0x1373, "DEVFS_SUPER_MAGIC" },
1613 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1614 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001615 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1616 { 0xef53, "EXT2_SUPER_MAGIC" },
1617 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001618 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001619 { 0x9660, "ISOFS_SUPER_MAGIC" },
1620 { 0x137f, "MINIX_SUPER_MAGIC" },
1621 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001622 { 0x2468, "MINIX2_SUPER_MAGIC" },
1623 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001624 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001625 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001626 { 0x6969, "NFS_SUPER_MAGIC" },
1627 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001628 { 0x002f, "QNX4_SUPER_MAGIC" },
1629 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1630 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1631 { 0x517b, "SMB_SUPER_MAGIC" },
1632 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1633 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1634 { 0x00011954, "UFS_MAGIC" },
1635 { 0x54190100, "UFS_CIGAM" },
1636 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001637 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001638 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001639 { 0, NULL },
1640};
1641
Roland McGrathf9c49b22004-10-06 22:11:54 +00001642static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001643sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001644{
1645 static char buf[32];
Roland McGrathf9c49b22004-10-06 22:11:54 +00001646 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001647
1648 s = xlookup(fsmagic, magic);
1649 if (s) {
1650 sprintf(buf, "\"%s\"", s);
1651 return buf;
1652 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001653 sprintf(buf, "%#x", magic);
1654 return buf;
1655}
1656
1657static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001658printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001659{
1660 struct statfs statbuf;
1661
1662 if (syserror(tcp) || !verbose(tcp)) {
1663 tprintf("%#lx", addr);
1664 return;
1665 }
1666 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001667 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001668 return;
1669 }
1670#ifdef ALPHA
1671
1672 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1673 sprintfstype(statbuf.f_type),
1674 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001675 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001676 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001677 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1678 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001679#else /* !ALPHA */
1680 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1681 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001682 (unsigned long)statbuf.f_bsize,
1683 (unsigned long)statbuf.f_blocks,
1684 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001685 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1686 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001687 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001688 (unsigned long)statbuf.f_ffree,
1689 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001690 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001691#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001692#ifdef _STATFS_F_FRSIZE
1693 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1694#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001695 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001696}
1697
1698int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001699sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001700{
1701 if (entering(tcp)) {
1702 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001703 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001704 } else {
1705 printstatfs(tcp, tcp->u_arg[1]);
1706 }
1707 return 0;
1708}
1709
1710int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001711sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001712{
1713 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001714 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001715 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001716 } else {
1717 printstatfs(tcp, tcp->u_arg[1]);
1718 }
1719 return 0;
1720}
1721
Denys Vlasenko84703742012-02-25 02:38:52 +01001722#if defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001723static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001724printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001725{
1726 struct statfs64 statbuf;
1727
1728 if (syserror(tcp) || !verbose(tcp)) {
1729 tprintf("%#lx", addr);
1730 return;
1731 }
1732 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001733 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001734 return;
1735 }
Roland McGrath08738432005-06-03 02:40:39 +00001736 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001737 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001738 (unsigned long long)statbuf.f_bsize,
1739 (unsigned long long)statbuf.f_blocks,
1740 (unsigned long long)statbuf.f_bfree);
1741 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1742 (unsigned long long)statbuf.f_bavail,
1743 (unsigned long long)statbuf.f_files,
1744 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001745 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1746 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001747#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001748 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001749#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001750#ifdef _STATFS_F_FLAGS
1751 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1752#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001753 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001754}
1755
Andreas Schwab7d558012012-01-17 18:14:22 +01001756struct compat_statfs64 {
1757 uint32_t f_type;
1758 uint32_t f_bsize;
1759 uint64_t f_blocks;
1760 uint64_t f_bfree;
1761 uint64_t f_bavail;
1762 uint64_t f_files;
1763 uint64_t f_ffree;
1764 fsid_t f_fsid;
1765 uint32_t f_namelen;
1766 uint32_t f_frsize;
1767 uint32_t f_flags;
1768 uint32_t f_spare[4];
1769}
1770#if defined(X86_64) || defined(IA64)
1771 __attribute__ ((packed, aligned(4)))
1772#endif
1773;
1774
1775static void
1776printcompat_statfs64(struct tcb *tcp, long addr)
1777{
1778 struct compat_statfs64 statbuf;
1779
1780 if (syserror(tcp) || !verbose(tcp)) {
1781 tprintf("%#lx", addr);
1782 return;
1783 }
1784 if (umove(tcp, addr, &statbuf) < 0) {
1785 tprints("{...}");
1786 return;
1787 }
1788 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1789 sprintfstype(statbuf.f_type),
1790 (unsigned long)statbuf.f_bsize,
1791 (unsigned long long)statbuf.f_blocks,
1792 (unsigned long long)statbuf.f_bfree);
1793 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1794 (unsigned long long)statbuf.f_bavail,
1795 (unsigned long long)statbuf.f_files,
1796 (unsigned long long)statbuf.f_ffree,
1797 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1798 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1799 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001800 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
Andreas Schwab7d558012012-01-17 18:14:22 +01001801}
1802
Roland McGrathab147c52003-07-17 09:03:02 +00001803int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001804sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001805{
1806 if (entering(tcp)) {
1807 printpath(tcp, tcp->u_arg[0]);
1808 tprintf(", %lu, ", tcp->u_arg[1]);
1809 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001810 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001811 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001812 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1813 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001814 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001815 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001816 }
1817 return 0;
1818}
1819
1820int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001821sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001822{
1823 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001824 printfd(tcp, tcp->u_arg[0]);
1825 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001826 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001827 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001828 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001829 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1830 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001831 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001832 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001833 }
1834 return 0;
1835}
1836#endif
1837
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001838#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001839int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001840osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001841{
1842 if (entering(tcp)) {
1843 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001844 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001845 } else {
1846 printstatfs(tcp, tcp->u_arg[1]);
1847 tprintf(", %lu", tcp->u_arg[2]);
1848 }
1849 return 0;
1850}
1851
1852int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001853osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001854{
1855 if (entering(tcp)) {
1856 tprintf("%lu, ", tcp->u_arg[0]);
1857 } else {
1858 printstatfs(tcp, tcp->u_arg[1]);
1859 tprintf(", %lu", tcp->u_arg[2]);
1860 }
1861 return 0;
1862}
Denys Vlasenko84703742012-02-25 02:38:52 +01001863#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001864
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001865/* directory */
1866int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001867sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001868{
1869 if (entering(tcp)) {
1870 printpath(tcp, tcp->u_arg[0]);
1871 }
1872 return 0;
1873}
1874
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001875static int
1876decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001877{
1878 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001879 printpath(tcp, tcp->u_arg[offset]);
1880 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001881 }
1882 return 0;
1883}
1884
1885int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001886sys_mkdir(struct tcb *tcp)
1887{
1888 return decode_mkdir(tcp, 0);
1889}
1890
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001891int
1892sys_mkdirat(struct tcb *tcp)
1893{
1894 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001895 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001896 return decode_mkdir(tcp, 1);
1897}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001898
1899int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001900sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001901{
1902 if (entering(tcp)) {
1903 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001904 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001905 printpath(tcp, tcp->u_arg[1]);
1906 }
1907 return 0;
1908}
1909
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001910int
1911sys_linkat(struct tcb *tcp)
1912{
1913 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001914 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001915 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001916 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001917 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001918 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001919 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001920 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001921 }
1922 return 0;
1923}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001924
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001925int
1926sys_unlinkat(struct tcb *tcp)
1927{
1928 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001929 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001930 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001931 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001932 printflags(at_flags, tcp->u_arg[2], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001933 }
1934 return 0;
1935}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001936
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001937int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001938sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001939{
1940 if (entering(tcp)) {
1941 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001942 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001943 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001944 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001945 }
1946 return 0;
1947}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001948
1949static int
1950decode_readlink(struct tcb *tcp, int offset)
1951{
1952 if (entering(tcp)) {
1953 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001954 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001955 } else {
1956 if (syserror(tcp))
1957 tprintf("%#lx", tcp->u_arg[offset + 1]);
1958 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001959 /* Used to use printpathn(), but readlink
1960 * neither includes NUL in the returned count,
1961 * nor actually writes it into memory.
1962 * printpathn() would decide on printing
1963 * "..." continuation based on garbage
1964 * past return buffer's end.
1965 */
1966 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001967 tprintf(", %lu", tcp->u_arg[offset + 2]);
1968 }
1969 return 0;
1970}
1971
1972int
1973sys_readlink(struct tcb *tcp)
1974{
1975 return decode_readlink(tcp, 0);
1976}
1977
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001978int
1979sys_readlinkat(struct tcb *tcp)
1980{
1981 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001982 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001983 return decode_readlink(tcp, 1);
1984}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001985
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001986int
1987sys_renameat(struct tcb *tcp)
1988{
1989 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001990 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001991 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001992 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001993 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001994 printpath(tcp, tcp->u_arg[3]);
1995 }
1996 return 0;
1997}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001998
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001999int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002000sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002001{
2002 if (entering(tcp)) {
2003 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002004 printuid(", ", tcp->u_arg[1]);
2005 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002006 }
2007 return 0;
2008}
2009
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002010int
2011sys_fchownat(struct tcb *tcp)
2012{
2013 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002014 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002015 printpath(tcp, tcp->u_arg[1]);
2016 printuid(", ", tcp->u_arg[2]);
2017 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002018 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00002019 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002020 }
2021 return 0;
2022}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002023
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002024int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002025sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002026{
2027 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002028 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002029 printuid(", ", tcp->u_arg[1]);
2030 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002031 }
2032 return 0;
2033}
2034
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002035static int
2036decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002037{
2038 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002039 printpath(tcp, tcp->u_arg[offset]);
2040 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002041 }
2042 return 0;
2043}
2044
2045int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002046sys_chmod(struct tcb *tcp)
2047{
2048 return decode_chmod(tcp, 0);
2049}
2050
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002051int
2052sys_fchmodat(struct tcb *tcp)
2053{
2054 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002055 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002056 return decode_chmod(tcp, 1);
2057}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002058
2059int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002060sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002061{
2062 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002063 printfd(tcp, tcp->u_arg[0]);
2064 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002065 }
2066 return 0;
2067}
2068
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002069#ifdef ALPHA
2070int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002071sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002072{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002073 if (entering(tcp)) {
2074 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002075 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002076 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2077 }
2078 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002079}
2080#endif
2081
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002082static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002083decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002084{
2085 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002086 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002087 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002088 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002089 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00002090 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002091 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00002092 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2093 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002094 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002095 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002096 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00002097 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002098 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00002099 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002100 }
2101 return 0;
2102}
2103
2104int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002105sys_utimes(struct tcb *tcp)
2106{
Roland McGrath6afc5652007-07-24 01:57:11 +00002107 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002108}
2109
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002110int
2111sys_futimesat(struct tcb *tcp)
2112{
2113 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002114 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002115 return decode_utimes(tcp, 1, 0);
2116}
2117
2118int
2119sys_utimensat(struct tcb *tcp)
2120{
2121 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002122 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002123 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002124 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00002125 printflags(at_flags, tcp->u_arg[3], "AT_???");
Roland McGrath6afc5652007-07-24 01:57:11 +00002126 }
2127 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002128}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002129
2130int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002131sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002132{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002133 union {
2134 long utl[2];
2135 int uti[2];
Denys Vlasenko751acb32013-02-08 15:34:46 +01002136 long paranoia_for_huge_wordsize[4];
Roland McGrath7e9817c2007-07-05 20:31:58 +00002137 } u;
Denys Vlasenko751acb32013-02-08 15:34:46 +01002138 unsigned wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002139
2140 if (entering(tcp)) {
2141 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002142 tprints(", ");
Denys Vlasenko751acb32013-02-08 15:34:46 +01002143
2144 wordsize = current_wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002145 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002146 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002147 else if (!verbose(tcp))
2148 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002149 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002150 tprints("[?, ?]");
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002151 else if (wordsize == sizeof u.utl[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002152 tprintf("[%s,", sprinttime(u.utl[0]));
2153 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002154 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002155 else if (wordsize == sizeof u.uti[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002156 tprintf("[%s,", sprinttime(u.uti[0]));
2157 tprintf(" %s]", sprinttime(u.uti[1]));
2158 }
2159 else
Denys Vlasenko751acb32013-02-08 15:34:46 +01002160 tprintf("<decode error: unsupported wordsize %d>",
2161 wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002162 }
2163 return 0;
2164}
2165
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002166static int
2167decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002168{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002169 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002170
2171 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002172 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002173 tprintf(", %s", sprintmode(mode));
2174 switch (mode & S_IFMT) {
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002175 case S_IFCHR:
2176 case S_IFBLK:
Denys Vlasenko9472a272013-02-12 11:43:46 +01002177#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002178 if (current_personality == 1)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002179 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002180 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2181 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002182 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002183#endif
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002184 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002185 (unsigned long) major(tcp->u_arg[offset + 2]),
2186 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002187 break;
2188 default:
2189 break;
2190 }
2191 }
2192 return 0;
2193}
2194
2195int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002196sys_mknod(struct tcb *tcp)
2197{
2198 return decode_mknod(tcp, 0);
2199}
2200
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002201int
2202sys_mknodat(struct tcb *tcp)
2203{
2204 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002205 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002206 return decode_mknod(tcp, 1);
2207}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002208
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002209static void
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002210print_old_dirent(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002211{
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002212#ifdef SH64
2213 typedef struct kernel_dirent old_dirent_t;
2214#else
2215 typedef struct {
2216 uint32_t d_ino;
2217 uint32_t d_off;
2218 unsigned short d_reclen;
2219 char d_name[1];
2220 } old_dirent_t;
2221#endif
2222 old_dirent_t d;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002223
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002224 if (!verbose(tcp) || umove(tcp, addr, &d) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002225 tprintf("%#lx", addr);
2226 return;
2227 }
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002228
2229 tprintf("{d_ino=%lu, d_off=%lu, d_reclen=%u, d_name=\"",
2230 (unsigned long) d.d_ino, (unsigned long) d.d_off, d.d_reclen);
2231 if (d.d_reclen > 256)
2232 d.d_reclen = 256;
2233 printpathn(tcp, addr + offsetof(old_dirent_t, d_name), d.d_reclen);
2234 tprints("\"}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002235}
2236
2237int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002238sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002239{
2240 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002241 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002242 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002243 } else {
2244 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2245 tprintf("%#lx", tcp->u_arg[1]);
2246 else
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002247 print_old_dirent(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002248 /* Not much point in printing this out, it is always 1. */
2249 if (tcp->u_arg[2] != 1)
2250 tprintf(", %lu", tcp->u_arg[2]);
2251 }
2252 return 0;
2253}
2254
Roland McGratha4d48532005-06-08 20:45:28 +00002255static const struct xlat direnttypes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002256 { DT_UNKNOWN, "DT_UNKNOWN" },
2257 { DT_FIFO, "DT_FIFO" },
2258 { DT_CHR, "DT_CHR" },
2259 { DT_DIR, "DT_DIR" },
2260 { DT_BLK, "DT_BLK" },
2261 { DT_REG, "DT_REG" },
2262 { DT_LNK, "DT_LNK" },
2263 { DT_SOCK, "DT_SOCK" },
2264 { DT_WHT, "DT_WHT" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002265 { 0, NULL },
2266};
2267
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002268int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002269sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002270{
2271 int i, len, dents = 0;
2272 char *buf;
2273
2274 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002275 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002276 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002277 return 0;
2278 }
2279 if (syserror(tcp) || !verbose(tcp)) {
2280 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2281 return 0;
2282 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002283 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002284 /* Beware of insanely large or negative values in tcp->u_rval */
2285 if (tcp->u_rval > 1024*1024)
2286 len = 1024*1024;
2287 if (tcp->u_rval < 0)
2288 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002289 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002290 if (len && !buf)
2291 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002292 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002293 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002294 free(buf);
2295 return 0;
2296 }
2297 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002298 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002299 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002300 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002301 if (!abbrev(tcp)) {
2302 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2303 i ? " " : "", d->d_ino, d->d_off);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002304 tprintf("d_reclen=%u, d_name=\"%s\", d_type=",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002305 d->d_reclen, d->d_name);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002306 printxval(direnttypes, buf[i + d->d_reclen - 1], "DT_???");
2307 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002308 }
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002309 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002310 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002311 break;
2312 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002313 i += d->d_reclen;
2314 dents++;
2315 }
2316 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002317 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002318 else
2319 tprintf("/* %u entries */", dents);
2320 tprintf(", %lu", tcp->u_arg[2]);
2321 free(buf);
2322 return 0;
2323}
2324
John Hughesbdf48f52001-03-06 15:08:09 +00002325#if _LFS64_LARGEFILE
2326int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002327sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002328{
2329 int i, len, dents = 0;
2330 char *buf;
2331
2332 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002333 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002334 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002335 return 0;
2336 }
2337 if (syserror(tcp) || !verbose(tcp)) {
2338 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2339 return 0;
2340 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002341
John Hughesbdf48f52001-03-06 15:08:09 +00002342 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002343 /* Beware of insanely large or negative tcp->u_rval */
2344 if (tcp->u_rval > 1024*1024)
2345 len = 1024*1024;
2346 if (tcp->u_rval < 0)
2347 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002348 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002349 if (len && !buf)
2350 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002351
John Hughesbdf48f52001-03-06 15:08:09 +00002352 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002353 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002354 free(buf);
2355 return 0;
2356 }
2357 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002358 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002359 for (i = 0; i < len;) {
2360 struct dirent64 *d = (struct dirent64 *) &buf[i];
John Hughesbdf48f52001-03-06 15:08:09 +00002361 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002362 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002363 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002364 d->d_ino,
2365 d->d_off);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002366 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002367 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002368 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002369 tprintf("d_reclen=%u, d_name=\"%s\"}",
2370 d->d_reclen, d->d_name);
2371 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002372 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002373 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002374 break;
2375 }
John Hughesbdf48f52001-03-06 15:08:09 +00002376 i += d->d_reclen;
2377 dents++;
2378 }
2379 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002380 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002381 else
2382 tprintf("/* %u entries */", dents);
2383 tprintf(", %lu", tcp->u_arg[2]);
2384 free(buf);
2385 return 0;
2386}
2387#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002388
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002389int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002390sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002391{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002392 if (exiting(tcp)) {
2393 if (syserror(tcp))
2394 tprintf("%#lx", tcp->u_arg[0]);
2395 else
2396 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2397 tprintf(", %lu", tcp->u_arg[1]);
2398 }
2399 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002400}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002401
2402#ifdef HAVE_SYS_ASYNCH_H
2403
2404int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002405sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002406{
2407 struct aio_result_t res;
2408
2409 if (entering(tcp)) {
2410 tprintf("%lu, ", tcp->u_arg[0]);
2411 } else {
2412 if (syserror(tcp))
2413 tprintf("%#lx", tcp->u_arg[1]);
2414 else
2415 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2416 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2417 printxval(whence, tcp->u_arg[4], "L_???");
2418 if (syserror(tcp) || tcp->u_arg[5] == 0
2419 || umove(tcp, tcp->u_arg[5], &res) < 0)
2420 tprintf(", %#lx", tcp->u_arg[5]);
2421 else
2422 tprintf(", {aio_return %d aio_errno %d}",
2423 res.aio_return, res.aio_errno);
2424 }
2425 return 0;
2426}
2427
2428int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002429sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002430{
2431 struct aio_result_t res;
2432
2433 if (entering(tcp)) {
2434 tprintf("%lu, ", tcp->u_arg[0]);
2435 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2436 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2437 printxval(whence, tcp->u_arg[4], "L_???");
2438 }
2439 else {
2440 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002441 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002442 else if (syserror(tcp)
2443 || umove(tcp, tcp->u_arg[5], &res) < 0)
2444 tprintf(", %#lx", tcp->u_arg[5]);
2445 else
2446 tprintf(", {aio_return %d aio_errno %d}",
2447 res.aio_return, res.aio_errno);
2448 }
2449 return 0;
2450}
2451
2452int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002453sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002454{
2455 if (entering(tcp))
2456 printtv(tcp, tcp->u_arg[0]);
2457 return 0;
2458}
2459
2460int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002461sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002462{
2463 struct aio_result_t res;
2464
2465 if (exiting(tcp)) {
2466 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002467 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002468 else if (syserror(tcp)
2469 || umove(tcp, tcp->u_arg[0], &res) < 0)
2470 tprintf("%#lx", tcp->u_arg[0]);
2471 else
2472 tprintf("{aio_return %d aio_errno %d}",
2473 res.aio_return, res.aio_errno);
2474 }
2475 return 0;
2476}
2477
2478#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002479
Roland McGratha4d48532005-06-08 20:45:28 +00002480static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002481#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002482 { XATTR_CREATE, "XATTR_CREATE" },
2483 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002484#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002485 { 0, NULL }
2486};
2487
Roland McGrath3292e222004-08-31 06:30:48 +00002488static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002489print_xattr_val(struct tcb *tcp, int failed,
2490 unsigned long arg,
2491 unsigned long insize,
2492 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002493{
Dmitry V. Levin1f215132012-12-07 21:38:52 +00002494 if (insize == 0)
2495 failed = 1;
Denys Vlasenko1d632462009-04-14 12:51:00 +00002496 if (!failed) {
2497 unsigned long capacity = 4 * size + 1;
2498 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2499 if (buf == NULL || /* probably a bogus size argument */
2500 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2501 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002502 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002503 else {
2504 unsigned char *out = buf;
2505 unsigned char *in = &buf[3 * size];
2506 size_t i;
2507 for (i = 0; i < size; ++i) {
Denys Vlasenko5198ed42013-03-06 23:44:23 +01002508 if (in[i] >= ' ' && in[i] <= 0x7e)
Denys Vlasenko1d632462009-04-14 12:51:00 +00002509 *out++ = in[i];
2510 else {
2511#define tohex(n) "0123456789abcdef"[n]
2512 *out++ = '\\';
2513 *out++ = 'x';
2514 *out++ = tohex(in[i] / 16);
2515 *out++ = tohex(in[i] % 16);
2516 }
2517 }
2518 /* Don't print terminating NUL if there is one. */
2519 if (i > 0 && in[i - 1] == '\0')
2520 out -= 4;
2521 *out = '\0';
2522 tprintf(", \"%s\", %ld", buf, insize);
2523 }
2524 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002525 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002526 if (failed)
2527 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002528}
2529
Roland McGrath186c5ac2002-12-15 23:58:23 +00002530int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002531sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002532{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002533 if (entering(tcp)) {
2534 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002535 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002536 printstr(tcp, tcp->u_arg[1], -1);
2537 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002538 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002539 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2540 }
2541 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002542}
2543
2544int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002545sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002546{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002547 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002548 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002549 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002550 printstr(tcp, tcp->u_arg[1], -1);
2551 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002552 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002553 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2554 }
2555 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002556}
2557
2558int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002559sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002560{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002561 if (entering(tcp)) {
2562 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002563 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002564 printstr(tcp, tcp->u_arg[1], -1);
2565 } else {
2566 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2567 tcp->u_rval);
2568 }
2569 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002570}
2571
2572int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002573sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002574{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002575 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002576 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002577 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002578 printstr(tcp, tcp->u_arg[1], -1);
2579 } else {
2580 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2581 tcp->u_rval);
2582 }
2583 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002584}
2585
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002586static void
2587print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2588{
2589 if (syserror(tcp)) {
2590 tprintf("%#lx", addr);
2591 } else {
2592 if (!addr) {
2593 tprints("NULL");
2594 } else {
2595 unsigned long len =
2596 (size < tcp->u_rval) ? size : tcp->u_rval;
2597 printstr(tcp, addr, len);
2598 }
2599 }
2600 tprintf(", %lu", size);
2601}
2602
Roland McGrath186c5ac2002-12-15 23:58:23 +00002603int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002604sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002605{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002606 if (entering(tcp)) {
2607 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002608 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002609 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002610 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002611 }
2612 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002613}
2614
2615int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002616sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002617{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002618 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002619 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002620 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002621 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002622 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002623 }
2624 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002625}
2626
2627int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002628sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002629{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002630 if (entering(tcp)) {
2631 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002632 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002633 printstr(tcp, tcp->u_arg[1], -1);
2634 }
2635 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002636}
2637
2638int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002639sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002640{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002641 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002642 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002643 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002644 printstr(tcp, tcp->u_arg[1], -1);
2645 }
2646 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002647}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002648
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002649static const struct xlat advise[] = {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002650 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2651 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2652 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2653 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2654 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2655 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2656 { 0, NULL }
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002657};
2658
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002659int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002660sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002661{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002662 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002663 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002664 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002665 argn = printllval(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002666 tprintf(", %ld, ", tcp->u_arg[argn++]);
2667 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002668 }
2669 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002670}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002671
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002672int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002673sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002674{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002675 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002676 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002677 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002678 argn = printllval(tcp, ", %lld, ", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002679 argn = printllval(tcp, "%lld, ", argn);
Dmitry V. Levin8e096c42013-05-06 18:23:01 +00002680#if defined __ARM_EABI__ || defined AARCH64 || defined POWERPC || defined XTENSA
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002681 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002682#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002683 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002684#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002685 }
2686 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002687}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002688
William Manley16b9dcf2013-08-09 18:04:11 +01002689static const struct xlat sync_file_range_flags[] = {
2690 { SYNC_FILE_RANGE_WAIT_BEFORE, "SYNC_FILE_RANGE_WAIT_BEFORE" },
2691 { SYNC_FILE_RANGE_WRITE, "SYNC_FILE_RANGE_WRITE" },
2692 { SYNC_FILE_RANGE_WAIT_AFTER, "SYNC_FILE_RANGE_WAIT_AFTER" },
2693 { 0, NULL }
2694};
2695
2696int
2697sys_sync_file_range(struct tcb *tcp)
2698{
2699 if (entering(tcp)) {
2700 int argn;
2701 printfd(tcp, tcp->u_arg[0]);
2702 argn = printllval(tcp, ", %lld, ", 1);
2703 argn = printllval(tcp, "%lld, ", argn);
2704 printflags(sync_file_range_flags, tcp->u_arg[argn],
2705 "SYNC_FILE_RANGE_???");
2706 }
2707 return 0;
2708}
2709
2710int
2711sys_sync_file_range2(struct tcb *tcp)
2712{
2713 if (entering(tcp)) {
2714 int argn;
2715 printfd(tcp, tcp->u_arg[0]);
2716 printflags(sync_file_range_flags, 1,
2717 "SYNC_FILE_RANGE_???");
2718 argn = printllval(tcp, ", %lld, ", 2);
2719 argn = printllval(tcp, "%lld, ", argn);
2720 }
2721 return 0;
2722}
2723
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002724static const struct xlat inotify_modes[] = {
Dmitry V. Levind475c062011-03-03 01:02:41 +00002725 { 0x00000001, "IN_ACCESS" },
2726 { 0x00000002, "IN_MODIFY" },
2727 { 0x00000004, "IN_ATTRIB" },
2728 { 0x00000008, "IN_CLOSE_WRITE"},
2729 { 0x00000010, "IN_CLOSE_NOWRITE"},
2730 { 0x00000020, "IN_OPEN" },
2731 { 0x00000040, "IN_MOVED_FROM" },
2732 { 0x00000080, "IN_MOVED_TO" },
2733 { 0x00000100, "IN_CREATE" },
2734 { 0x00000200, "IN_DELETE" },
2735 { 0x00000400, "IN_DELETE_SELF"},
2736 { 0x00000800, "IN_MOVE_SELF" },
2737 { 0x00002000, "IN_UNMOUNT" },
2738 { 0x00004000, "IN_Q_OVERFLOW" },
2739 { 0x00008000, "IN_IGNORED" },
2740 { 0x01000000, "IN_ONLYDIR" },
2741 { 0x02000000, "IN_DONT_FOLLOW"},
2742 { 0x20000000, "IN_MASK_ADD" },
2743 { 0x40000000, "IN_ISDIR" },
2744 { 0x80000000, "IN_ONESHOT" },
2745 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002746};
2747
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002748static const struct xlat inotify_init_flags[] = {
2749 { 0x00000800, "IN_NONBLOCK" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002750 { 0x00080000, "IN_CLOEXEC" },
2751 { 0, NULL }
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002752};
2753
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002754int
2755sys_inotify_add_watch(struct tcb *tcp)
2756{
2757 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002758 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002759 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002760 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002761 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002762 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2763 }
2764 return 0;
2765}
2766
2767int
2768sys_inotify_rm_watch(struct tcb *tcp)
2769{
2770 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002771 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levinab1a70c2012-03-11 15:33:34 +00002772 tprintf(", %d", (int) tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002773 }
2774 return 0;
2775}
Roland McGrath96a96612008-05-20 04:56:18 +00002776
2777int
Mark Wielaardbab89402010-03-21 14:41:26 +01002778sys_inotify_init1(struct tcb *tcp)
2779{
2780 if (entering(tcp))
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002781 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
Mark Wielaardbab89402010-03-21 14:41:26 +01002782 return 0;
2783}
2784
2785int
Roland McGrath96a96612008-05-20 04:56:18 +00002786sys_fallocate(struct tcb *tcp)
2787{
2788 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002789 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002790 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002791 tprintf(", %#lo, ", tcp->u_arg[1]); /* mode */
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002792 argn = printllval(tcp, "%llu, ", 2); /* offset */
2793 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002794 }
2795 return 0;
2796}
Dmitry V. Levin88293652012-03-09 21:02:19 +00002797
Dmitry V. Levinad0c01e2012-03-15 00:52:22 +00002798#ifndef SWAP_FLAG_PREFER
2799# define SWAP_FLAG_PREFER 0x8000
2800#endif
2801#ifndef SWAP_FLAG_DISCARD
2802# define SWAP_FLAG_DISCARD 0x10000
2803#endif
Dmitry V. Levin88293652012-03-09 21:02:19 +00002804static const struct xlat swap_flags[] = {
2805 { SWAP_FLAG_PREFER, "SWAP_FLAG_PREFER" },
2806 { SWAP_FLAG_DISCARD, "SWAP_FLAG_DISCARD" },
2807 { 0, NULL }
2808};
2809
2810int
2811sys_swapon(struct tcb *tcp)
2812{
2813 if (entering(tcp)) {
2814 int flags = tcp->u_arg[1];
2815 printpath(tcp, tcp->u_arg[0]);
2816 tprints(", ");
2817 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2818 "SWAP_FLAG_???");
2819 if (flags & SWAP_FLAG_PREFER)
2820 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);
2821 }
2822 return 0;
2823}