blob: 38bf976441db0e020b20e7d1ca394ced8e6295e8 [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.
29 *
30 * $Id$
31 */
32
33#include "defs.h"
34
35#include <dirent.h>
Roland McGrathc531e572008-08-01 01:13:10 +000036
Michal Ludvig53b320f2002-09-23 13:30:09 +000037#ifdef LINUX
Roland McGrathc531e572008-08-01 01:13:10 +000038struct kernel_dirent {
39 unsigned long d_ino;
40 unsigned long d_off;
41 unsigned short d_reclen;
42 char d_name[1];
43};
Wichert Akkerman9524bb91999-05-25 23:11:18 +000044#else
Roland McGrathc531e572008-08-01 01:13:10 +000045# define kernel_dirent dirent
Wichert Akkerman9524bb91999-05-25 23:11:18 +000046#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000047
Michal Ludvig53b320f2002-09-23 13:30:09 +000048#ifdef LINUX
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000049# ifdef LINUXSPARC
50struct stat {
51 unsigned short st_dev;
52 unsigned int st_ino;
53 unsigned short st_mode;
54 short st_nlink;
55 unsigned short st_uid;
56 unsigned short st_gid;
57 unsigned short st_rdev;
58 unsigned int st_size;
59 int st_atime;
60 unsigned int __unused1;
61 int st_mtime;
62 unsigned int __unused2;
63 int st_ctime;
64 unsigned int __unused3;
65 int st_blksize;
66 int st_blocks;
67 unsigned int __unused4[2];
68};
Roland McGrath6d1a65c2004-07-12 07:44:08 +000069#if defined(SPARC64)
70struct stat_sparc64 {
71 unsigned int st_dev;
72 unsigned long st_ino;
73 unsigned int st_mode;
74 unsigned int st_nlink;
75 unsigned int st_uid;
76 unsigned int st_gid;
77 unsigned int st_rdev;
78 long st_size;
79 long st_atime;
80 long st_mtime;
81 long st_ctime;
82 long st_blksize;
83 long st_blocks;
84 unsigned long __unused4[2];
85};
86#endif /* SPARC64 */
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000087# define stat kernel_stat
88# include <asm/stat.h>
89# undef stat
90# else
Wichert Akkerman5b4d1281999-07-09 00:32:54 +000091# undef dev_t
92# undef ino_t
93# undef mode_t
94# undef nlink_t
95# undef uid_t
96# undef gid_t
97# undef off_t
98# undef loff_t
99
Wichert Akkermana6013701999-07-08 14:00:58 +0000100# define dev_t __kernel_dev_t
101# define ino_t __kernel_ino_t
102# define mode_t __kernel_mode_t
103# define nlink_t __kernel_nlink_t
104# define uid_t __kernel_uid_t
105# define gid_t __kernel_gid_t
106# define off_t __kernel_off_t
107# define loff_t __kernel_loff_t
108
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000109# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +0000110
111# undef dev_t
112# undef ino_t
113# undef mode_t
114# undef nlink_t
115# undef uid_t
116# undef gid_t
117# undef off_t
118# undef loff_t
Wichert Akkerman5b4d1281999-07-09 00:32:54 +0000119
120# define dev_t dev_t
121# define ino_t ino_t
122# define mode_t mode_t
123# define nlink_t nlink_t
124# define uid_t uid_t
125# define gid_t gid_t
126# define off_t off_t
127# define loff_t loff_t
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000128# endif
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000129# ifdef HPPA /* asm-parisc/stat.h defines stat64 */
130# undef stat64
131# endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000132# define stat libc_stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000133# define stat64 libc_stat64
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000134# include <sys/stat.h>
135# undef stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000136# undef stat64
Roland McGrathca16a402003-01-09 06:53:22 +0000137 /* These might be macros. */
138# undef st_atime
139# undef st_mtime
140# undef st_ctime
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000141# ifdef HPPA
142# define stat64 hpux_stat64
143# endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000144#else
145# include <sys/stat.h>
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000146#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000147
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148#include <fcntl.h>
149
150#ifdef SVR4
151# include <sys/cred.h>
152#endif /* SVR4 */
153
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000154#ifdef HAVE_SYS_VFS_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000155#include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000156#endif
157
Roland McGrath186c5ac2002-12-15 23:58:23 +0000158#ifdef HAVE_LINUX_XATTR_H
159#include <linux/xattr.h>
160#elif defined linux
161#define XATTR_CREATE 1
162#define XATTR_REPLACE 2
163#endif
164
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000165#ifdef FREEBSD
166#include <sys/param.h>
167#include <sys/mount.h>
168#include <sys/stat.h>
John Hughes70623be2001-03-08 13:59:00 +0000169#endif
170
Dmitry V. Levin1f336e52006-10-14 20:20:46 +0000171#if _LFS64_LARGEFILE && (defined(LINUX) || defined(SVR4))
172# ifdef HAVE_INTTYPES_H
173# include <inttypes.h>
174# else
175# define PRId64 "lld"
176# define PRIu64 "llu"
177# endif
178#endif
179
John Hughes70623be2001-03-08 13:59:00 +0000180#if HAVE_LONG_LONG_OFF_T
181/*
182 * Ugly hacks for systems that have typedef long long off_t
183 */
John Hughesb8c9f772001-03-07 16:53:07 +0000184
185#define stat64 stat
186#define HAVE_STAT64 1 /* Ugly hack */
John Hughes70623be2001-03-08 13:59:00 +0000187
188#define sys_stat64 sys_stat
189#define sys_fstat64 sys_fstat
190#define sys_lstat64 sys_lstat
191#define sys_lseek64 sys_lseek
192#define sys_truncate64 sys_truncate
193#define sys_ftruncate64 sys_ftruncate
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000194#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000195
196#ifdef MAJOR_IN_SYSMACROS
197#include <sys/sysmacros.h>
198#endif
199
200#ifdef MAJOR_IN_MKDEV
201#include <sys/mkdev.h>
202#endif
203
204#ifdef HAVE_SYS_ASYNCH_H
205#include <sys/asynch.h>
206#endif
207
208#ifdef SUNOS4
209#include <ustat.h>
210#endif
211
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000212const struct xlat open_access_modes[] = {
213 { O_RDONLY, "O_RDONLY" },
214 { O_WRONLY, "O_WRONLY" },
215 { O_RDWR, "O_RDWR" },
216#ifdef O_ACCMODE
217 { O_ACCMODE, "O_ACCMODE" },
218#endif
219 { 0, NULL },
220};
221
222const struct xlat open_mode_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000223 { O_CREAT, "O_CREAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000224 { O_EXCL, "O_EXCL" },
225 { O_NOCTTY, "O_NOCTTY" },
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000226 { O_TRUNC, "O_TRUNC" },
227 { O_APPEND, "O_APPEND" },
228 { O_NONBLOCK, "O_NONBLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000229#ifdef O_SYNC
230 { O_SYNC, "O_SYNC" },
231#endif
232#ifdef O_ASYNC
233 { O_ASYNC, "O_ASYNC" },
234#endif
235#ifdef O_DSYNC
236 { O_DSYNC, "O_DSYNC" },
237#endif
238#ifdef O_RSYNC
239 { O_RSYNC, "O_RSYNC" },
240#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000241#if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000242 { O_NDELAY, "O_NDELAY" },
243#endif
244#ifdef O_PRIV
245 { O_PRIV, "O_PRIV" },
246#endif
247#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000248 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000249#endif
250#ifdef O_LARGEFILE
Roland McGrathfee836e2005-02-02 22:11:32 +0000251# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
252# undef O_LARGEFILE
253# ifdef SPARC64
254# define O_LARGEFILE 0x40000
255# elif defined X86_64 || defined S390X
256# define O_LARGEFILE 0100000
257# endif
258# endif
Roland McGrath663a8a02005-02-04 09:49:56 +0000259# ifdef O_LARGEFILE
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200260 { O_LARGEFILE, "O_LARGEFILE" },
Roland McGrath663a8a02005-02-04 09:49:56 +0000261# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000262#endif
263#ifdef O_DIRECTORY
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200264 { O_DIRECTORY, "O_DIRECTORY" },
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000265#endif
266#ifdef O_NOFOLLOW
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200267 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000268#endif
Roland McGrath1025c3e2005-05-09 07:40:35 +0000269#ifdef O_NOATIME
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200270 { O_NOATIME, "O_NOATIME" },
Roland McGrath1025c3e2005-05-09 07:40:35 +0000271#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000272#ifdef O_CLOEXEC
273 { O_CLOEXEC, "O_CLOEXEC" },
274#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000275
276#ifdef FNDELAY
277 { FNDELAY, "FNDELAY" },
278#endif
279#ifdef FAPPEND
280 { FAPPEND, "FAPPEND" },
281#endif
282#ifdef FMARK
283 { FMARK, "FMARK" },
284#endif
285#ifdef FDEFER
286 { FDEFER, "FDEFER" },
287#endif
288#ifdef FASYNC
289 { FASYNC, "FASYNC" },
290#endif
291#ifdef FSHLOCK
292 { FSHLOCK, "FSHLOCK" },
293#endif
294#ifdef FEXLOCK
295 { FEXLOCK, "FEXLOCK" },
296#endif
297#ifdef FCREAT
298 { FCREAT, "FCREAT" },
299#endif
300#ifdef FTRUNC
301 { FTRUNC, "FTRUNC" },
302#endif
303#ifdef FEXCL
304 { FEXCL, "FEXCL" },
305#endif
306#ifdef FNBIO
307 { FNBIO, "FNBIO" },
308#endif
309#ifdef FSYNC
310 { FSYNC, "FSYNC" },
311#endif
312#ifdef FNOCTTY
313 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000314#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000315#ifdef O_SHLOCK
316 { O_SHLOCK, "O_SHLOCK" },
317#endif
318#ifdef O_EXLOCK
319 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000320#endif
321 { 0, NULL },
322};
323
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000324#ifdef LINUX
325
326#ifndef AT_FDCWD
327# define AT_FDCWD -100
328#endif
329
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000330/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
331 * extension to get the right value. We do this by declaring fd as int here.
332 */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000333static void
Dmitry V. Levin31382132011-03-04 05:08:02 +0300334print_dirfd(struct tcb *tcp, int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000335{
336 if (fd == AT_FDCWD)
337 tprintf("AT_FDCWD, ");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200338 else {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300339 printfd(tcp, fd);
340 tprintf(", ");
341 }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000342}
343#endif
344
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000345/*
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000346 * Pity stpcpy() is not standardized...
347 */
348static char *
349str_append(char *dst, const char *src)
350{
351 while ((*dst = *src++) != '\0')
352 dst++;
353 return dst;
354}
355
356/*
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000357 * low bits of the open(2) flags define access mode,
358 * other bits are real flags.
359 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000360const char *
361sprint_open_modes(mode_t flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000362{
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000363 static char outstr[1024];
364 char *p;
365 char sep = 0;
366 const char *str;
367 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000368
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000369 p = str_append(outstr, "flags ");
370 str = xlookup(open_access_modes, flags & 3);
371 if (str) {
372 p = str_append(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000373 flags &= ~3;
374 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000375 return outstr;
376 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000377 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000378
379 for (x = open_mode_flags; x->str; x++) {
380 if ((flags & x->val) == x->val) {
381 if (sep)
382 *p++ = sep;
383 p = str_append(p, x->str);
384 flags &= ~x->val;
385 if (!flags)
386 return outstr;
387 sep = '|';
388 }
389 }
390 /* flags is still nonzero */
391 if (sep)
392 *p++ = sep;
393 sprintf(p, "%#x", flags);
394 return outstr;
395}
396
397void
398tprint_open_modes(mode_t flags)
399{
Dmitry V. Levin4bcd5ef2009-06-01 10:32:27 +0000400 tprintf("%s", sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000401}
402
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000403static int
404decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000405{
406 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000407 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000408 tprintf(", ");
409 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000410 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000411 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000412 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000413 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000414 }
415 }
416 return 0;
417}
418
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000419int
420sys_open(struct tcb *tcp)
421{
422 return decode_open(tcp, 0);
423}
424
425#ifdef LINUX
426int
427sys_openat(struct tcb *tcp)
428{
429 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300430 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000431 return decode_open(tcp, 1);
432}
433#endif
434
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000435#ifdef LINUXSPARC
Roland McGratha4d48532005-06-08 20:45:28 +0000436static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000437 { 0, "O_RDWR" },
438 { 1, "O_RDONLY" },
439 { 2, "O_WRONLY" },
440 { 0x80, "O_NONBLOCK" },
441 { 8, "O_APPEND" },
442 { 0x100, "O_CREAT" },
443 { 0x200, "O_TRUNC" },
444 { 0x400, "O_EXCL" },
445 { 0x800, "O_NOCTTY" },
446 { 0x10, "O_SYNC" },
447 { 0x40, "O_DSYNC" },
448 { 0x8000, "O_RSYNC" },
449 { 4, "O_NDELAY" },
450 { 0x1000, "O_PRIV" },
451 { 0, NULL },
452};
453
454int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000455solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000456{
457 if (entering(tcp)) {
458 printpath(tcp, tcp->u_arg[0]);
459 tprintf(", ");
460 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000461 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000462 if (tcp->u_arg[1] & 0x100) {
463 /* mode */
464 tprintf(", %#lo", tcp->u_arg[2]);
465 }
466 }
467 return 0;
468}
469
470#endif
471
472int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000473sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000474{
475 if (entering(tcp)) {
476 printpath(tcp, tcp->u_arg[0]);
477 tprintf(", %#lo", tcp->u_arg[1]);
478 }
479 return 0;
480}
481
Roland McGrathd9f816f2004-09-04 03:39:20 +0000482static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000483 { F_OK, "F_OK", },
484 { R_OK, "R_OK" },
485 { W_OK, "W_OK" },
486 { X_OK, "X_OK" },
487#ifdef EFF_ONLY_OK
488 { EFF_ONLY_OK, "EFF_ONLY_OK" },
489#endif
490#ifdef EX_OK
491 { EX_OK, "EX_OK" },
492#endif
493 { 0, NULL },
494};
495
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000496static int
497decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000498{
499 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000500 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000501 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000502 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000503 }
504 return 0;
505}
506
507int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000508sys_access(struct tcb *tcp)
509{
510 return decode_access(tcp, 0);
511}
512
513#ifdef LINUX
514int
515sys_faccessat(struct tcb *tcp)
516{
517 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300518 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000519 return decode_access(tcp, 1);
520}
521#endif
522
523int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000524sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525{
526 if (entering(tcp)) {
527 tprintf("%#lo", tcp->u_arg[0]);
528 }
529 return RVAL_OCTAL;
530}
531
Roland McGrathd9f816f2004-09-04 03:39:20 +0000532static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000533 { SEEK_SET, "SEEK_SET" },
534 { SEEK_CUR, "SEEK_CUR" },
535 { SEEK_END, "SEEK_END" },
536 { 0, NULL },
537};
538
John Hughes70623be2001-03-08 13:59:00 +0000539#ifndef HAVE_LONG_LONG_OFF_T
Roland McGrath542c2c62008-05-20 01:11:56 +0000540#if defined (LINUX_MIPSN32)
541int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000542sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000543{
544 long long offset;
545 int _whence;
546
547 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300548 printfd(tcp, tcp->u_arg[0]);
549 tprintf(", ");
Roland McGrath542c2c62008-05-20 01:11:56 +0000550 offset = tcp->ext_arg[1];
551 _whence = tcp->u_arg[2];
552 if (_whence == SEEK_SET)
553 tprintf("%llu, ", offset);
554 else
555 tprintf("%lld, ", offset);
556 printxval(whence, _whence, "SEEK_???");
557 }
558 return RVAL_UDECIMAL;
559}
560#else /* !LINUX_MIPSN32 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000561int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000562sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000563{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000564 off_t offset;
565 int _whence;
566
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000567 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300568 printfd(tcp, tcp->u_arg[0]);
569 tprintf(", ");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000570 offset = tcp->u_arg[1];
571 _whence = tcp->u_arg[2];
572 if (_whence == SEEK_SET)
573 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000574 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000575 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000576 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000577 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000578 return RVAL_UDECIMAL;
579}
Roland McGrath542c2c62008-05-20 01:11:56 +0000580#endif /* LINUX_MIPSN32 */
John Hughes5a826b82001-03-07 13:21:24 +0000581#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000582
Michal Ludvig53b320f2002-09-23 13:30:09 +0000583#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000584int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000585sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000586{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000587 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300588 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000589 /*
590 * This one call takes explicitly two 32-bit arguments hi, lo,
591 * rather than one 64-bit argument for which LONG_LONG works
592 * appropriate for the native byte order.
593 */
594 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300595 tprintf(", %llu, ",
596 ((long long int) tcp->u_arg[1]) << 32 |
597 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000598 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300599 tprintf(", %lld, ",
600 ((long long int) tcp->u_arg[1]) << 32 |
601 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000602 }
603 else {
604 long long int off;
605 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
606 tprintf("%#lx, ", tcp->u_arg[3]);
607 else
608 tprintf("[%llu], ", off);
609 printxval(whence, tcp->u_arg[4], "SEEK_???");
610 }
611 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000612}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000613
614int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000615sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000616{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000617 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100618 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300619 printfd(tcp, tcp->u_arg[0]);
620 tprintf(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100621 argn = printllval(tcp, "%lld", 1);
622 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000623 }
624 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000625}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000626#endif
627
John Hughes70623be2001-03-08 13:59:00 +0000628#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000629int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000630sys_lseek64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +0000631{
632 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100633 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300634 printfd(tcp, tcp->u_arg[0]);
635 tprintf(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000636 if (tcp->u_arg[3] == SEEK_SET)
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100637 argn = printllval(tcp, "%llu, ", 1);
John Hughesbdf48f52001-03-06 15:08:09 +0000638 else
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100639 argn = printllval(tcp, "%lld, ", 1);
640 printxval(whence, tcp->u_arg[argn], "SEEK_???");
John Hughesbdf48f52001-03-06 15:08:09 +0000641 }
642 return RVAL_LUDECIMAL;
643}
644#endif
645
John Hughes70623be2001-03-08 13:59:00 +0000646#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000647int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000648sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000649{
650 if (entering(tcp)) {
651 printpath(tcp, tcp->u_arg[0]);
652 tprintf(", %lu", tcp->u_arg[1]);
653 }
654 return 0;
655}
John Hughes5a826b82001-03-07 13:21:24 +0000656#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000657
John Hughes70623be2001-03-08 13:59:00 +0000658#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000659int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000660sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000661{
662 if (entering(tcp)) {
663 printpath(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100664 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000665 }
666 return 0;
667}
668#endif
669
John Hughes70623be2001-03-08 13:59:00 +0000670#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000671int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000672sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000673{
674 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300675 printfd(tcp, tcp->u_arg[0]);
676 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000677 }
678 return 0;
679}
John Hughes5a826b82001-03-07 13:21:24 +0000680#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000681
John Hughes70623be2001-03-08 13:59:00 +0000682#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000683int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000684sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000685{
686 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300687 printfd(tcp, tcp->u_arg[0]);
688 tprintf(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100689 printllval(tcp, "%llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000690 }
691 return 0;
692}
693#endif
694
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000695/* several stats */
696
Roland McGrathd9f816f2004-09-04 03:39:20 +0000697static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000698 { S_IFREG, "S_IFREG" },
699 { S_IFSOCK, "S_IFSOCK" },
700 { S_IFIFO, "S_IFIFO" },
701 { S_IFLNK, "S_IFLNK" },
702 { S_IFDIR, "S_IFDIR" },
703 { S_IFBLK, "S_IFBLK" },
704 { S_IFCHR, "S_IFCHR" },
705 { 0, NULL },
706};
707
Roland McGrathf9c49b22004-10-06 22:11:54 +0000708static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000709sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000710{
711 static char buf[64];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000712 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000713
714 if ((mode & S_IFMT) == 0)
715 s = "";
716 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
717 sprintf(buf, "%#o", mode);
718 return buf;
719 }
720 sprintf(buf, "%s%s%s%s", s,
721 (mode & S_ISUID) ? "|S_ISUID" : "",
722 (mode & S_ISGID) ? "|S_ISGID" : "",
723 (mode & S_ISVTX) ? "|S_ISVTX" : "");
724 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
725 if (mode)
726 sprintf(buf + strlen(buf), "|%#o", mode);
727 s = (*buf == '|') ? buf + 1 : buf;
728 return *s ? s : "0";
729}
730
731static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000732sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000733{
734 struct tm *tmp;
735 static char buf[32];
736
737 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000738 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000739 return buf;
740 }
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000741 if ((tmp = localtime(&t)))
742 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
743 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
744 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
745 else
746 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
747
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000748 return buf;
749}
750
751#ifdef LINUXSPARC
752typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000753 int tv_sec;
754 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000755} timestruct_t;
756
757struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000758 unsigned st_dev;
759 int st_pad1[3]; /* network id */
760 unsigned st_ino;
761 unsigned st_mode;
762 unsigned st_nlink;
763 unsigned st_uid;
764 unsigned st_gid;
765 unsigned st_rdev;
766 int st_pad2[2];
767 int st_size;
768 int st_pad3; /* st_size, off_t expansion */
769 timestruct_t st_atime;
770 timestruct_t st_mtime;
771 timestruct_t st_ctime;
772 int st_blksize;
773 int st_blocks;
774 char st_fstype[16];
775 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000776};
777
778static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000779printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000780{
781 struct solstat statbuf;
782
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000783 if (umove(tcp, addr, &statbuf) < 0) {
784 tprintf("{...}");
785 return;
786 }
787 if (!abbrev(tcp)) {
788 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
789 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
790 (unsigned long) (statbuf.st_dev & 0x3ffff),
791 (unsigned long) statbuf.st_ino,
792 sprintmode(statbuf.st_mode));
793 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
794 (unsigned long) statbuf.st_nlink,
795 (unsigned long) statbuf.st_uid,
796 (unsigned long) statbuf.st_gid);
797 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
798 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
799 }
800 else
801 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
802 switch (statbuf.st_mode & S_IFMT) {
803 case S_IFCHR: case S_IFBLK:
804 tprintf("st_rdev=makedev(%lu, %lu), ",
805 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
806 (unsigned long) (statbuf.st_rdev & 0x3ffff));
807 break;
808 default:
809 tprintf("st_size=%u, ", statbuf.st_size);
810 break;
811 }
812 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000813 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
814 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
815 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000816 }
817 else
818 tprintf("...}");
819}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000820
821#if defined (SPARC64)
822static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000823printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000824{
825 struct stat_sparc64 statbuf;
826
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000827 if (umove(tcp, addr, &statbuf) < 0) {
828 tprintf("{...}");
829 return;
830 }
831
832 if (!abbrev(tcp)) {
833 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
834 (unsigned long) major(statbuf.st_dev),
835 (unsigned long) minor(statbuf.st_dev),
836 (unsigned long) statbuf.st_ino,
837 sprintmode(statbuf.st_mode));
838 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
839 (unsigned long) statbuf.st_nlink,
840 (unsigned long) statbuf.st_uid,
841 (unsigned long) statbuf.st_gid);
842 tprintf("st_blksize=%lu, ",
843 (unsigned long) statbuf.st_blksize);
844 tprintf("st_blocks=%lu, ",
845 (unsigned long) statbuf.st_blocks);
846 }
847 else
848 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
849 switch (statbuf.st_mode & S_IFMT) {
850 case S_IFCHR: case S_IFBLK:
851 tprintf("st_rdev=makedev(%lu, %lu), ",
852 (unsigned long) major(statbuf.st_rdev),
853 (unsigned long) minor(statbuf.st_rdev));
854 break;
855 default:
856 tprintf("st_size=%lu, ", statbuf.st_size);
857 break;
858 }
859 if (!abbrev(tcp)) {
860 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
861 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
862 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
863 tprintf("}");
864 }
865 else
866 tprintf("...}");
867}
868#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000869#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000870
Andreas Schwabd69fa492010-07-12 21:39:57 +0200871#if defined LINUX && defined POWERPC64
872struct stat_powerpc32 {
873 unsigned int st_dev;
874 unsigned int st_ino;
875 unsigned int st_mode;
876 unsigned short st_nlink;
877 unsigned int st_uid;
878 unsigned int st_gid;
879 unsigned int st_rdev;
880 unsigned int st_size;
881 unsigned int st_blksize;
882 unsigned int st_blocks;
883 unsigned int st_atime;
884 unsigned int st_atime_nsec;
885 unsigned int st_mtime;
886 unsigned int st_mtime_nsec;
887 unsigned int st_ctime;
888 unsigned int st_ctime_nsec;
889 unsigned int __unused4;
890 unsigned int __unused5;
891};
892
893static void
894printstat_powerpc32(struct tcb *tcp, long addr)
895{
896 struct stat_powerpc32 statbuf;
897
898 if (umove(tcp, addr, &statbuf) < 0) {
899 tprintf("{...}");
900 return;
901 }
902
903 if (!abbrev(tcp)) {
904 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
905 major(statbuf.st_dev), minor(statbuf.st_dev),
906 statbuf.st_ino,
907 sprintmode(statbuf.st_mode));
908 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
909 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
910 tprintf("st_blksize=%u, ", statbuf.st_blksize);
911 tprintf("st_blocks=%u, ", statbuf.st_blocks);
912 }
913 else
914 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
915 switch (statbuf.st_mode & S_IFMT) {
916 case S_IFCHR: case S_IFBLK:
917 tprintf("st_rdev=makedev(%lu, %lu), ",
918 (unsigned long) major(statbuf.st_rdev),
919 (unsigned long) minor(statbuf.st_rdev));
920 break;
921 default:
922 tprintf("st_size=%u, ", statbuf.st_size);
923 break;
924 }
925 if (!abbrev(tcp)) {
926 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
927 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
928 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
929 tprintf("}");
930 }
931 else
932 tprintf("...}");
933}
934#endif /* LINUX && POWERPC64 */
935
Roland McGratha4d48532005-06-08 20:45:28 +0000936static const struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000937#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000938 { UF_NODUMP, "UF_NODUMP" },
939 { UF_IMMUTABLE, "UF_IMMUTABLE" },
940 { UF_APPEND, "UF_APPEND" },
941 { UF_OPAQUE, "UF_OPAQUE" },
942 { UF_NOUNLINK, "UF_NOUNLINK" },
943 { SF_ARCHIVED, "SF_ARCHIVED" },
944 { SF_IMMUTABLE, "SF_IMMUTABLE" },
945 { SF_APPEND, "SF_APPEND" },
946 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000947#elif UNIXWARE >= 2
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200948#ifdef _S_ISMLD
949 { _S_ISMLD, "_S_ISMLD" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000950#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200951#ifdef _S_ISMOUNTED
952 { _S_ISMOUNTED, "_S_ISMOUNTED" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000953#endif
954#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000955 { 0, NULL },
956};
957
John Hughesc0fc3fd2001-03-08 16:10:40 +0000958#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000959int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000960sys_chflags(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000961{
962 if (entering(tcp)) {
963 printpath(tcp, tcp->u_arg[0]);
964 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000965 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000966 }
967 return 0;
968}
969
970int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000971sys_fchflags(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000972{
973 if (entering(tcp)) {
974 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000975 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000976 }
977 return 0;
978}
979#endif
980
John Hughes70623be2001-03-08 13:59:00 +0000981#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000982static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000983realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000984{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000985 if (!abbrev(tcp)) {
986 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
987 (unsigned long) major(statbuf->st_dev),
988 (unsigned long) minor(statbuf->st_dev),
989 (unsigned long) statbuf->st_ino,
990 sprintmode(statbuf->st_mode));
991 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
992 (unsigned long) statbuf->st_nlink,
993 (unsigned long) statbuf->st_uid,
994 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000995#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000996 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
997#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000998#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000999 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
1000#endif
1001 }
1002 else
1003 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
1004 switch (statbuf->st_mode & S_IFMT) {
1005 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001006#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +00001007 tprintf("st_rdev=makedev(%lu, %lu), ",
1008 (unsigned long) major(statbuf->st_rdev),
1009 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001010#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +00001011 tprintf("st_size=makedev(%lu, %lu), ",
1012 (unsigned long) major(statbuf->st_size),
1013 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001014#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +00001015 break;
1016 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +00001017 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +00001018 break;
1019 }
1020 if (!abbrev(tcp)) {
1021 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
1022 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
1023 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001024#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +00001025 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001026 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001027#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001028#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001029 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
1030#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001031#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001032 tprintf(", st_level=%ld", statbuf->st_level);
1033#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001034#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001035 tprintf(", st_fstype=%.*s",
1036 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
1037#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001038#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001039 tprintf(", st_gen=%u", statbuf->st_gen);
1040#endif
1041 tprintf("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +00001042 }
1043 else
1044 tprintf("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001045}
1046
Nate Sammons771a6ff1999-04-05 22:39:31 +00001047
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001048static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001049printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001050{
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001051 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001052
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001053 if (!addr) {
1054 tprintf("NULL");
1055 return;
1056 }
1057 if (syserror(tcp) || !verbose(tcp)) {
1058 tprintf("%#lx", addr);
1059 return;
1060 }
1061
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001062#ifdef LINUXSPARC
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001063 if (current_personality == 1) {
1064 printstatsol(tcp, addr);
1065 return;
1066 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001067#ifdef SPARC64
1068 else if (current_personality == 2) {
1069 printstat_sparc64(tcp, addr);
1070 return;
1071 }
1072#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001073#endif /* LINUXSPARC */
1074
Andreas Schwabd69fa492010-07-12 21:39:57 +02001075#if defined LINUX && defined POWERPC64
1076 if (current_personality == 1) {
1077 printstat_powerpc32(tcp, addr);
1078 return;
1079 }
1080#endif
1081
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001082 if (umove(tcp, addr, &statbuf) < 0) {
1083 tprintf("{...}");
1084 return;
1085 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001086
1087 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001088}
John Hughes70623be2001-03-08 13:59:00 +00001089#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001090
Roland McGrathe6d0f712007-08-07 01:22:49 +00001091#if !defined HAVE_STAT64 && defined LINUX && defined X86_64
1092/*
1093 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1094 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1095 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1096 * __GNUC__ is needed for the required __attribute__ below.
1097 */
1098struct stat64 {
1099 unsigned long long st_dev;
1100 unsigned char __pad0[4];
1101 unsigned int __st_ino;
1102 unsigned int st_mode;
1103 unsigned int st_nlink;
1104 unsigned int st_uid;
1105 unsigned int st_gid;
1106 unsigned long long st_rdev;
1107 unsigned char __pad3[4];
1108 long long st_size;
1109 unsigned int st_blksize;
1110 unsigned long long st_blocks;
1111 unsigned int st_atime;
1112 unsigned int st_atime_nsec;
1113 unsigned int st_mtime;
1114 unsigned int st_mtime_nsec;
1115 unsigned int st_ctime;
1116 unsigned int st_ctime_nsec;
1117 unsigned long long st_ino;
1118} __attribute__((packed));
1119# define HAVE_STAT64 1
1120# define STAT64_SIZE 96
1121#endif
1122
Wichert Akkermanc7926982000-04-10 22:22:31 +00001123#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001124static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001125printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001126{
1127 struct stat64 statbuf;
1128
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001129#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001130 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1131#endif
1132
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001133 if (!addr) {
1134 tprintf("NULL");
1135 return;
1136 }
1137 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001138 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001139 return;
1140 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001141
1142#ifdef LINUXSPARC
1143 if (current_personality == 1) {
1144 printstatsol(tcp, addr);
1145 return;
1146 }
1147# ifdef SPARC64
1148 else if (current_personality == 2) {
1149 printstat_sparc64(tcp, addr);
1150 return;
1151 }
1152# endif
1153#endif /* LINUXSPARC */
1154
Andreas Schwab61b74352009-10-16 11:37:13 +02001155#if defined LINUX && defined X86_64
1156 if (current_personality == 0) {
1157 printstat(tcp, addr);
1158 return;
1159 }
1160#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +00001161
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001162 if (umove(tcp, addr, &statbuf) < 0) {
1163 tprintf("{...}");
1164 return;
1165 }
1166
1167 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001168#ifdef HAVE_LONG_LONG
1169 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1170#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001171 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001172#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001173 (unsigned long) major(statbuf.st_dev),
1174 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001175#ifdef HAVE_LONG_LONG
1176 (unsigned long long) statbuf.st_ino,
1177#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001178 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001179#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001180 sprintmode(statbuf.st_mode));
1181 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1182 (unsigned long) statbuf.st_nlink,
1183 (unsigned long) statbuf.st_uid,
1184 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001185#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001186 tprintf("st_blksize=%lu, ",
1187 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001188#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1189#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001190 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001191#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001192 }
1193 else
1194 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1195 switch (statbuf.st_mode & S_IFMT) {
1196 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001197#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001198 tprintf("st_rdev=makedev(%lu, %lu), ",
1199 (unsigned long) major(statbuf.st_rdev),
1200 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001201#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001202 tprintf("st_size=makedev(%lu, %lu), ",
1203 (unsigned long) major(statbuf.st_size),
1204 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001205#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001206 break;
1207 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001208#ifdef HAVE_LONG_LONG
1209 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1210#else
1211 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1212#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001213 break;
1214 }
1215 if (!abbrev(tcp)) {
1216 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1217 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001218 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001219#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +00001220 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001221 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001222#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001223#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001224 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1225#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001226#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001227 tprintf(", st_level=%ld", statbuf.st_level);
1228#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001229#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001230 tprintf(", st_fstype=%.*s",
1231 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1232#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001233#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001234 tprintf(", st_gen=%u", statbuf.st_gen);
1235#endif
1236 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001237 }
1238 else
1239 tprintf("...}");
1240}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001241#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001242
Roland McGrath79db8af2003-06-27 21:20:09 +00001243#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001244static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001245convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001246{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001247 newbuf->st_dev = oldbuf->st_dev;
1248 newbuf->st_ino = oldbuf->st_ino;
1249 newbuf->st_mode = oldbuf->st_mode;
1250 newbuf->st_nlink = oldbuf->st_nlink;
1251 newbuf->st_uid = oldbuf->st_uid;
1252 newbuf->st_gid = oldbuf->st_gid;
1253 newbuf->st_rdev = oldbuf->st_rdev;
1254 newbuf->st_size = oldbuf->st_size;
1255 newbuf->st_atime = oldbuf->st_atime;
1256 newbuf->st_mtime = oldbuf->st_mtime;
1257 newbuf->st_ctime = oldbuf->st_ctime;
1258 newbuf->st_blksize = 0; /* not supported in old_stat */
1259 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001260}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001261
1262
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001263static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001264printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001265{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001266 struct __old_kernel_stat statbuf;
1267 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001268
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001269 if (!addr) {
1270 tprintf("NULL");
1271 return;
1272 }
1273 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001274 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001275 return;
1276 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001277
1278#ifdef LINUXSPARC
1279 if (current_personality == 1) {
1280 printstatsol(tcp, addr);
1281 return;
1282 }
1283#endif /* LINUXSPARC */
1284
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001285 if (umove(tcp, addr, &statbuf) < 0) {
1286 tprintf("{...}");
1287 return;
1288 }
1289
1290 convertoldstat(&statbuf, &newstatbuf);
1291 realprintstat(tcp, &newstatbuf);
1292}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001293#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001294
John Hughes70623be2001-03-08 13:59:00 +00001295#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001296int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001297sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001298{
1299 if (entering(tcp)) {
1300 printpath(tcp, tcp->u_arg[0]);
1301 tprintf(", ");
1302 } else {
1303 printstat(tcp, tcp->u_arg[1]);
1304 }
1305 return 0;
1306}
John Hughesb8c9f772001-03-07 16:53:07 +00001307#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001308
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001309int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001310sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001311{
1312#ifdef HAVE_STAT64
1313 if (entering(tcp)) {
1314 printpath(tcp, tcp->u_arg[0]);
1315 tprintf(", ");
1316 } else {
1317 printstat64(tcp, tcp->u_arg[1]);
1318 }
1319 return 0;
1320#else
1321 return printargs(tcp);
1322#endif
1323}
1324
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001325#ifdef LINUX
1326static const struct xlat fstatatflags[] = {
1327#ifndef AT_SYMLINK_NOFOLLOW
1328# define AT_SYMLINK_NOFOLLOW 0x100
1329#endif
1330 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1331 { 0, NULL },
1332};
Roland McGrath6afc5652007-07-24 01:57:11 +00001333#define utimensatflags fstatatflags
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001334
1335int
1336sys_newfstatat(struct tcb *tcp)
1337{
1338 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001339 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001340 printpath(tcp, tcp->u_arg[1]);
1341 tprintf(", ");
1342 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001343#ifdef POWERPC64
1344 if (current_personality == 0)
1345 printstat(tcp, tcp->u_arg[2]);
1346 else
1347 printstat64(tcp, tcp->u_arg[2]);
1348#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001349 printstat64(tcp, tcp->u_arg[2]);
1350#else
1351 printstat(tcp, tcp->u_arg[2]);
1352#endif
1353 tprintf(", ");
1354 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1355 }
1356 return 0;
1357}
1358#endif
1359
Roland McGrath79db8af2003-06-27 21:20:09 +00001360#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001361int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001362sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001363{
1364 if (entering(tcp)) {
1365 printpath(tcp, tcp->u_arg[0]);
1366 tprintf(", ");
1367 } else {
1368 printoldstat(tcp, tcp->u_arg[1]);
1369 }
1370 return 0;
1371}
Roland McGrath79db8af2003-06-27 21:20:09 +00001372#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001373
John Hughes70623be2001-03-08 13:59:00 +00001374#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001375int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001376sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001377{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001378 if (entering(tcp)) {
1379 printfd(tcp, tcp->u_arg[0]);
1380 tprintf(", ");
1381 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001382 printstat(tcp, tcp->u_arg[1]);
1383 }
1384 return 0;
1385}
John Hughesb8c9f772001-03-07 16:53:07 +00001386#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001387
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001388int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001389sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001390{
1391#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001392 if (entering(tcp)) {
1393 printfd(tcp, tcp->u_arg[0]);
1394 tprintf(", ");
1395 } else {
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001396 printstat64(tcp, tcp->u_arg[1]);
1397 }
1398 return 0;
1399#else
1400 return printargs(tcp);
1401#endif
1402}
1403
Roland McGrath79db8af2003-06-27 21:20:09 +00001404#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001405int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001406sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001407{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001408 if (entering(tcp)) {
1409 printfd(tcp, tcp->u_arg[0]);
1410 tprintf(", ");
1411 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001412 printoldstat(tcp, tcp->u_arg[1]);
1413 }
1414 return 0;
1415}
Roland McGrath79db8af2003-06-27 21:20:09 +00001416#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001417
John Hughes70623be2001-03-08 13:59:00 +00001418#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001419int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001420sys_lstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001421{
1422 if (entering(tcp)) {
1423 printpath(tcp, tcp->u_arg[0]);
1424 tprintf(", ");
1425 } else {
1426 printstat(tcp, tcp->u_arg[1]);
1427 }
1428 return 0;
1429}
John Hughesb8c9f772001-03-07 16:53:07 +00001430#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001431
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001432int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001433sys_lstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001434{
1435#ifdef HAVE_STAT64
1436 if (entering(tcp)) {
1437 printpath(tcp, tcp->u_arg[0]);
1438 tprintf(", ");
1439 } else {
1440 printstat64(tcp, tcp->u_arg[1]);
1441 }
1442 return 0;
1443#else
1444 return printargs(tcp);
1445#endif
1446}
1447
Roland McGrath79db8af2003-06-27 21:20:09 +00001448#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001449int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001450sys_oldlstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001451{
1452 if (entering(tcp)) {
1453 printpath(tcp, tcp->u_arg[0]);
1454 tprintf(", ");
1455 } else {
1456 printoldstat(tcp, tcp->u_arg[1]);
1457 }
1458 return 0;
1459}
Roland McGrath79db8af2003-06-27 21:20:09 +00001460#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001461
1462
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001463#if defined(SVR4) || defined(LINUXSPARC)
1464
1465int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001466sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001467{
1468 if (entering(tcp)) {
1469 tprintf("%ld, ", tcp->u_arg[0]);
1470 printpath(tcp, tcp->u_arg[1]);
1471 tprintf(", ");
1472 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001473#ifdef _STAT64_VER
1474 if (tcp->u_arg[0] == _STAT64_VER)
1475 printstat64 (tcp, tcp->u_arg[2]);
1476 else
1477#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001478 printstat(tcp, tcp->u_arg[2]);
1479 }
1480 return 0;
1481}
1482
1483int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001484sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001485{
1486 if (entering(tcp))
1487 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1488 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001489#ifdef _STAT64_VER
1490 if (tcp->u_arg[0] == _STAT64_VER)
1491 printstat64 (tcp, tcp->u_arg[2]);
1492 else
1493#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001494 printstat(tcp, tcp->u_arg[2]);
1495 }
1496 return 0;
1497}
1498
1499int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001500sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001501{
1502 if (entering(tcp)) {
1503 tprintf("%ld, ", tcp->u_arg[0]);
1504 printpath(tcp, tcp->u_arg[1]);
1505 tprintf(", ");
1506 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001507#ifdef _STAT64_VER
1508 if (tcp->u_arg[0] == _STAT64_VER)
1509 printstat64 (tcp, tcp->u_arg[2]);
1510 else
1511#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001512 printstat(tcp, tcp->u_arg[2]);
1513 }
1514 return 0;
1515}
1516
1517int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001518sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001519{
1520 int mode = tcp->u_arg[2];
1521
1522 if (entering(tcp)) {
1523 tprintf("%ld, ", tcp->u_arg[0]);
1524 printpath(tcp, tcp->u_arg[1]);
1525 tprintf(", %s", sprintmode(mode));
1526 switch (mode & S_IFMT) {
1527 case S_IFCHR: case S_IFBLK:
1528#ifdef LINUXSPARC
1529 tprintf(", makedev(%lu, %lu)",
1530 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1531 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001532#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001533 tprintf(", makedev(%lu, %lu)",
1534 (unsigned long) major(tcp->u_arg[3]),
1535 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001536#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001537 break;
1538 default:
1539 break;
1540 }
1541 }
1542 return 0;
1543}
1544
Wichert Akkerman8829a551999-06-11 13:18:40 +00001545#ifdef HAVE_SYS_ACL_H
1546
1547#include <sys/acl.h>
1548
Roland McGratha4d48532005-06-08 20:45:28 +00001549static const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001550#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001551 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001552#endif
1553#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001554 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001555#endif
1556#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001557 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001558#endif
1559#ifdef ACL_GET
1560 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001561#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001562#ifdef ACL_SET
1563 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001564#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001565#ifdef ACL_CNT
1566 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001567#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001568 { 0, NULL },
1569};
1570
1571int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001572sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001573{
1574 if (entering(tcp)) {
1575 printpath(tcp, tcp->u_arg[0]);
1576 tprintf(", ");
1577 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1578 tprintf(", %ld", tcp->u_arg[2]);
1579 /*
1580 * FIXME - dump out the list of aclent_t's pointed to
1581 * by "tcp->u_arg[3]" if it's not NULL.
1582 */
1583 if (tcp->u_arg[3])
1584 tprintf(", %#lx", tcp->u_arg[3]);
1585 else
1586 tprintf(", NULL");
1587 }
1588 return 0;
1589}
1590
1591
1592int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001593sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001594{
1595 if (entering(tcp)) {
1596 tprintf("%ld, ", tcp->u_arg[0]);
1597 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1598 tprintf(", %ld", tcp->u_arg[2]);
1599 /*
1600 * FIXME - dump out the list of aclent_t's pointed to
1601 * by "tcp->u_arg[3]" if it's not NULL.
1602 */
1603 if (tcp->u_arg[3])
1604 tprintf(", %#lx", tcp->u_arg[3]);
1605 else
1606 tprintf(", NULL");
1607 }
1608 return 0;
1609}
1610
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001611
Roland McGratha4d48532005-06-08 20:45:28 +00001612static const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001613#ifdef IPC_SHM
1614 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001615#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001616#ifdef IPC_SEM
1617 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001618#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001619#ifdef IPC_MSG
1620 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001621#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001622 { 0, NULL },
1623};
1624
1625
1626int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001627sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001628{
1629 if (entering(tcp)) {
1630 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1631 tprintf(", %#lx, ", tcp->u_arg[1]);
1632 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1633 tprintf(", %ld", tcp->u_arg[3]);
1634 /*
1635 * FIXME - dump out the list of aclent_t's pointed to
1636 * by "tcp->u_arg[4]" if it's not NULL.
1637 */
1638 if (tcp->u_arg[4])
1639 tprintf(", %#lx", tcp->u_arg[4]);
1640 else
1641 tprintf(", NULL");
1642 }
1643 return 0;
1644}
1645
Wichert Akkerman8829a551999-06-11 13:18:40 +00001646#endif /* HAVE_SYS_ACL_H */
1647
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001648#endif /* SVR4 || LINUXSPARC */
1649
Michal Ludvig53b320f2002-09-23 13:30:09 +00001650#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001651
Roland McGrathd9f816f2004-09-04 03:39:20 +00001652static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001653 { 0x73757245, "CODA_SUPER_MAGIC" },
1654 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1655 { 0x1373, "DEVFS_SUPER_MAGIC" },
1656 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1657 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001658 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1659 { 0xef53, "EXT2_SUPER_MAGIC" },
1660 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001661 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001662 { 0x9660, "ISOFS_SUPER_MAGIC" },
1663 { 0x137f, "MINIX_SUPER_MAGIC" },
1664 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001665 { 0x2468, "MINIX2_SUPER_MAGIC" },
1666 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001667 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001668 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001669 { 0x6969, "NFS_SUPER_MAGIC" },
1670 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001671 { 0x002f, "QNX4_SUPER_MAGIC" },
1672 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1673 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1674 { 0x517b, "SMB_SUPER_MAGIC" },
1675 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1676 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1677 { 0x00011954, "UFS_MAGIC" },
1678 { 0x54190100, "UFS_CIGAM" },
1679 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001680 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001681 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001682 { 0, NULL },
1683};
1684
Michal Ludvig53b320f2002-09-23 13:30:09 +00001685#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001686
1687#ifndef SVR4
1688
Roland McGrathf9c49b22004-10-06 22:11:54 +00001689static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001690sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001691{
1692 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001693#ifdef LINUX
Roland McGrathf9c49b22004-10-06 22:11:54 +00001694 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001695
1696 s = xlookup(fsmagic, magic);
1697 if (s) {
1698 sprintf(buf, "\"%s\"", s);
1699 return buf;
1700 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001701#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001702 sprintf(buf, "%#x", magic);
1703 return buf;
1704}
1705
1706static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001707printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001708{
1709 struct statfs statbuf;
1710
1711 if (syserror(tcp) || !verbose(tcp)) {
1712 tprintf("%#lx", addr);
1713 return;
1714 }
1715 if (umove(tcp, addr, &statbuf) < 0) {
1716 tprintf("{...}");
1717 return;
1718 }
1719#ifdef ALPHA
1720
1721 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1722 sprintfstype(statbuf.f_type),
1723 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001724 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001725 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001726 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1727 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001728#else /* !ALPHA */
1729 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1730 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001731 (unsigned long)statbuf.f_bsize,
1732 (unsigned long)statbuf.f_blocks,
1733 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001734 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1735 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001736 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001737 (unsigned long)statbuf.f_ffree,
1738 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001739#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001740 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001741#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001742#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001743#ifdef _STATFS_F_FRSIZE
1744 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1745#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001746 tprintf("}");
1747}
1748
1749int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001750sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001751{
1752 if (entering(tcp)) {
1753 printpath(tcp, tcp->u_arg[0]);
1754 tprintf(", ");
1755 } else {
1756 printstatfs(tcp, tcp->u_arg[1]);
1757 }
1758 return 0;
1759}
1760
1761int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001762sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001763{
1764 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001765 printfd(tcp, tcp->u_arg[0]);
1766 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001767 } else {
1768 printstatfs(tcp, tcp->u_arg[1]);
1769 }
1770 return 0;
1771}
1772
Bernhard Reutner-Fischer9906e6d2009-10-14 16:33:58 +02001773#if defined LINUX && defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001774static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001775printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001776{
1777 struct statfs64 statbuf;
1778
1779 if (syserror(tcp) || !verbose(tcp)) {
1780 tprintf("%#lx", addr);
1781 return;
1782 }
1783 if (umove(tcp, addr, &statbuf) < 0) {
1784 tprintf("{...}");
1785 return;
1786 }
Roland McGrath08738432005-06-03 02:40:39 +00001787 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001788 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001789 (unsigned long long)statbuf.f_bsize,
1790 (unsigned long long)statbuf.f_blocks,
1791 (unsigned long long)statbuf.f_bfree);
1792 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1793 (unsigned long long)statbuf.f_bavail,
1794 (unsigned long long)statbuf.f_files,
1795 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001796 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1797 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001798#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001799 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001800#endif
1801 tprintf("}");
1802}
1803
1804int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001805sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001806{
1807 if (entering(tcp)) {
1808 printpath(tcp, tcp->u_arg[0]);
1809 tprintf(", %lu, ", tcp->u_arg[1]);
1810 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001811 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001812 printstatfs64(tcp, tcp->u_arg[2]);
1813 else
1814 tprintf("{???}");
1815 }
1816 return 0;
1817}
1818
1819int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001820sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001821{
1822 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001823 printfd(tcp, tcp->u_arg[0]);
1824 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001825 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001826 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001827 printstatfs64(tcp, tcp->u_arg[2]);
1828 else
1829 tprintf("{???}");
1830 }
1831 return 0;
1832}
1833#endif
1834
Michal Ludvig53b320f2002-09-23 13:30:09 +00001835#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001836
1837int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001838osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001839{
1840 if (entering(tcp)) {
1841 printpath(tcp, tcp->u_arg[0]);
1842 tprintf(", ");
1843 } else {
1844 printstatfs(tcp, tcp->u_arg[1]);
1845 tprintf(", %lu", tcp->u_arg[2]);
1846 }
1847 return 0;
1848}
1849
1850int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001851osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001852{
1853 if (entering(tcp)) {
1854 tprintf("%lu, ", tcp->u_arg[0]);
1855 } else {
1856 printstatfs(tcp, tcp->u_arg[1]);
1857 tprintf(", %lu", tcp->u_arg[2]);
1858 }
1859 return 0;
1860}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001861#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001862
1863#endif /* !SVR4 */
1864
1865#ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001866int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001867sys_ustat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001868{
1869 struct ustat statbuf;
1870
1871 if (entering(tcp)) {
1872 tprintf("makedev(%lu, %lu), ",
1873 (long) major(tcp->u_arg[0]),
1874 (long) minor(tcp->u_arg[0]));
1875 }
1876 else {
1877 if (syserror(tcp) || !verbose(tcp))
1878 tprintf("%#lx", tcp->u_arg[1]);
1879 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1880 tprintf("{...}");
1881 else {
1882 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1883 statbuf.f_tfree, statbuf.f_tinode);
1884 tprintf("f_fname=\"%.*s\", ",
1885 (int) sizeof(statbuf.f_fname),
1886 statbuf.f_fname);
1887 tprintf("f_fpack=\"%.*s\"}",
1888 (int) sizeof(statbuf.f_fpack),
1889 statbuf.f_fpack);
1890 }
1891 }
1892 return 0;
1893}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001894#endif /* SUNOS4 */
1895
Wichert Akkermanc7926982000-04-10 22:22:31 +00001896int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001897sys_pivotroot(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +00001898{
1899 if (entering(tcp)) {
1900 printpath(tcp, tcp->u_arg[0]);
1901 tprintf(", ");
1902 printpath(tcp, tcp->u_arg[1]);
1903 }
1904 return 0;
1905}
1906
1907
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001908/* directory */
1909int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001910sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001911{
1912 if (entering(tcp)) {
1913 printpath(tcp, tcp->u_arg[0]);
1914 }
1915 return 0;
1916}
1917
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001918static int
1919decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001920{
1921 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001922 printpath(tcp, tcp->u_arg[offset]);
1923 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001924 }
1925 return 0;
1926}
1927
1928int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001929sys_mkdir(struct tcb *tcp)
1930{
1931 return decode_mkdir(tcp, 0);
1932}
1933
1934#ifdef LINUX
1935int
1936sys_mkdirat(struct tcb *tcp)
1937{
1938 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001939 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001940 return decode_mkdir(tcp, 1);
1941}
1942#endif
1943
1944int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001945sys_rmdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001946{
1947 if (entering(tcp)) {
1948 printpath(tcp, tcp->u_arg[0]);
1949 }
1950 return 0;
1951}
1952
1953int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001954sys_fchdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001955{
1956 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001957 printfd(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001958 }
1959 return 0;
1960}
1961
1962int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001963sys_chroot(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001964{
1965 if (entering(tcp)) {
1966 printpath(tcp, tcp->u_arg[0]);
1967 }
1968 return 0;
1969}
1970
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001971#if defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001972int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001973sys_fchroot(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001974{
1975 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001976 printfd(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001977 }
1978 return 0;
1979}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001980#endif /* SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001981
1982int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001983sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001984{
1985 if (entering(tcp)) {
1986 printpath(tcp, tcp->u_arg[0]);
1987 tprintf(", ");
1988 printpath(tcp, tcp->u_arg[1]);
1989 }
1990 return 0;
1991}
1992
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001993#ifdef LINUX
1994int
1995sys_linkat(struct tcb *tcp)
1996{
1997 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001998 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001999 printpath(tcp, tcp->u_arg[1]);
2000 tprintf(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03002001 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002002 printpath(tcp, tcp->u_arg[3]);
Dmitry V. Levin31382132011-03-04 05:08:02 +03002003 tprintf(", ");
2004 printfd(tcp, tcp->u_arg[4]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002005 }
2006 return 0;
2007}
2008#endif
2009
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002010int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002011sys_unlink(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002012{
2013 if (entering(tcp)) {
2014 printpath(tcp, tcp->u_arg[0]);
2015 }
2016 return 0;
2017}
2018
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002019#ifdef LINUX
2020static const struct xlat unlinkatflags[] = {
2021#ifndef AT_REMOVEDIR
2022# define AT_REMOVEDIR 0x200
2023#endif
2024 { AT_REMOVEDIR, "AT_REMOVEDIR" },
2025 { 0, NULL },
2026};
2027
2028int
2029sys_unlinkat(struct tcb *tcp)
2030{
2031 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002032 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002033 printpath(tcp, tcp->u_arg[1]);
2034 tprintf(", ");
2035 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
2036 }
2037 return 0;
2038}
2039#endif
2040
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002041int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002042sys_symlink(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002043{
2044 if (entering(tcp)) {
2045 printpath(tcp, tcp->u_arg[0]);
2046 tprintf(", ");
2047 printpath(tcp, tcp->u_arg[1]);
2048 }
2049 return 0;
2050}
2051
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002052#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002053int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002054sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002055{
2056 if (entering(tcp)) {
2057 printpath(tcp, tcp->u_arg[0]);
2058 tprintf(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03002059 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002060 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002061 }
2062 return 0;
2063}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002064#endif
2065
2066static int
2067decode_readlink(struct tcb *tcp, int offset)
2068{
2069 if (entering(tcp)) {
2070 printpath(tcp, tcp->u_arg[offset]);
2071 tprintf(", ");
2072 } else {
2073 if (syserror(tcp))
2074 tprintf("%#lx", tcp->u_arg[offset + 1]);
2075 else
2076 printpathn(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
2077 tprintf(", %lu", tcp->u_arg[offset + 2]);
2078 }
2079 return 0;
2080}
2081
2082int
2083sys_readlink(struct tcb *tcp)
2084{
2085 return decode_readlink(tcp, 0);
2086}
2087
2088#ifdef LINUX
2089int
2090sys_readlinkat(struct tcb *tcp)
2091{
2092 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002093 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002094 return decode_readlink(tcp, 1);
2095}
2096#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002097
2098int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002099sys_rename(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002100{
2101 if (entering(tcp)) {
2102 printpath(tcp, tcp->u_arg[0]);
2103 tprintf(", ");
2104 printpath(tcp, tcp->u_arg[1]);
2105 }
2106 return 0;
2107}
2108
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002109#ifdef LINUX
2110int
2111sys_renameat(struct tcb *tcp)
2112{
2113 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002114 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002115 printpath(tcp, tcp->u_arg[1]);
2116 tprintf(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03002117 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002118 printpath(tcp, tcp->u_arg[3]);
2119 }
2120 return 0;
2121}
2122#endif
2123
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002124int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002125sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002126{
2127 if (entering(tcp)) {
2128 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002129 printuid(", ", tcp->u_arg[1]);
2130 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002131 }
2132 return 0;
2133}
2134
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002135#ifdef LINUX
2136int
2137sys_fchownat(struct tcb *tcp)
2138{
2139 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002140 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002141 printpath(tcp, tcp->u_arg[1]);
2142 printuid(", ", tcp->u_arg[2]);
2143 printuid(", ", tcp->u_arg[3]);
2144 tprintf(", ");
2145 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
2146 }
2147 return 0;
2148}
2149#endif
2150
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002151int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002152sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002153{
2154 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002155 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002156 printuid(", ", tcp->u_arg[1]);
2157 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002158 }
2159 return 0;
2160}
2161
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002162static int
2163decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002164{
2165 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002166 printpath(tcp, tcp->u_arg[offset]);
2167 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002168 }
2169 return 0;
2170}
2171
2172int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002173sys_chmod(struct tcb *tcp)
2174{
2175 return decode_chmod(tcp, 0);
2176}
2177
2178#ifdef LINUX
2179int
2180sys_fchmodat(struct tcb *tcp)
2181{
2182 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002183 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002184 return decode_chmod(tcp, 1);
2185}
2186#endif
2187
2188int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002189sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002190{
2191 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002192 printfd(tcp, tcp->u_arg[0]);
2193 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002194 }
2195 return 0;
2196}
2197
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002198#ifdef ALPHA
2199int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002200sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002201{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002202 if (entering(tcp)) {
2203 printpath(tcp, tcp->u_arg[0]);
2204 tprintf(", ");
2205 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2206 }
2207 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002208}
2209#endif
2210
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002211static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002212decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002213{
2214 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002215 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002216 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002217 if (tcp->u_arg[offset + 1] == 0)
2218 tprintf("NULL");
2219 else {
2220 tprintf("{");
2221 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2222 BITNESS_CURRENT, special);
2223 tprintf(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002224 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002225 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00002226 BITNESS_CURRENT, special);
2227 tprintf("}");
2228 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002229 }
2230 return 0;
2231}
2232
2233int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002234sys_utimes(struct tcb *tcp)
2235{
Roland McGrath6afc5652007-07-24 01:57:11 +00002236 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002237}
2238
2239#ifdef LINUX
2240int
2241sys_futimesat(struct tcb *tcp)
2242{
2243 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002244 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002245 return decode_utimes(tcp, 1, 0);
2246}
2247
2248int
2249sys_utimensat(struct tcb *tcp)
2250{
2251 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002252 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002253 decode_utimes(tcp, 1, 1);
2254 tprintf(", ");
2255 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2256 }
2257 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002258}
2259#endif
2260
2261int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002262sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002263{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002264 union {
2265 long utl[2];
2266 int uti[2];
2267 } u;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002268
2269 if (entering(tcp)) {
2270 printpath(tcp, tcp->u_arg[0]);
2271 tprintf(", ");
2272 if (!tcp->u_arg[1])
2273 tprintf("NULL");
2274 else if (!verbose(tcp))
2275 tprintf("%#lx", tcp->u_arg[1]);
Roland McGrath7e9817c2007-07-05 20:31:58 +00002276 else if (umoven(tcp, tcp->u_arg[1],
2277 2 * personality_wordsize[current_personality],
2278 (char *) &u) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002279 tprintf("[?, ?]");
Roland McGrath7e9817c2007-07-05 20:31:58 +00002280 else if (personality_wordsize[current_personality]
2281 == sizeof u.utl[0]) {
2282 tprintf("[%s,", sprinttime(u.utl[0]));
2283 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002284 }
Roland McGrath7e9817c2007-07-05 20:31:58 +00002285 else if (personality_wordsize[current_personality]
2286 == sizeof u.uti[0]) {
2287 tprintf("[%s,", sprinttime(u.uti[0]));
2288 tprintf(" %s]", sprinttime(u.uti[1]));
2289 }
2290 else
2291 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002292 }
2293 return 0;
2294}
2295
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002296static int
2297decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002298{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002299 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002300
2301 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002302 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002303 tprintf(", %s", sprintmode(mode));
2304 switch (mode & S_IFMT) {
2305 case S_IFCHR: case S_IFBLK:
2306#ifdef LINUXSPARC
2307 if (current_personality == 1)
2308 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002309 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2310 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002311 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002312#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002313 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002314 (unsigned long) major(tcp->u_arg[offset + 2]),
2315 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002316 break;
2317 default:
2318 break;
2319 }
2320 }
2321 return 0;
2322}
2323
2324int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002325sys_mknod(struct tcb *tcp)
2326{
2327 return decode_mknod(tcp, 0);
2328}
2329
2330#ifdef LINUX
2331int
2332sys_mknodat(struct tcb *tcp)
2333{
2334 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002335 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002336 return decode_mknod(tcp, 1);
2337}
2338#endif
2339
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002340#ifdef FREEBSD
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002341int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002342sys_mkfifo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002343{
2344 if (entering(tcp)) {
2345 printpath(tcp, tcp->u_arg[0]);
2346 tprintf(", %#lo", tcp->u_arg[1]);
2347 }
2348 return 0;
2349}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002350#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002351
2352int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002353sys_fsync(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002354{
2355 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002356 printfd(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002357 }
2358 return 0;
2359}
2360
Michal Ludvig53b320f2002-09-23 13:30:09 +00002361#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002362
2363static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002364printdir(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002365{
2366 struct dirent d;
2367
2368 if (!verbose(tcp)) {
2369 tprintf("%#lx", addr);
2370 return;
2371 }
2372 if (umove(tcp, addr, &d) < 0) {
2373 tprintf("{...}");
2374 return;
2375 }
2376 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002377 tprintf("d_name=");
2378 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2379 tprintf("}");
2380}
2381
2382int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002383sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002384{
2385 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002386 printfd(tcp, tcp->u_arg[0]);
2387 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002388 } else {
2389 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2390 tprintf("%#lx", tcp->u_arg[1]);
2391 else
2392 printdir(tcp, tcp->u_arg[1]);
2393 /* Not much point in printing this out, it is always 1. */
2394 if (tcp->u_arg[2] != 1)
2395 tprintf(", %lu", tcp->u_arg[2]);
2396 }
2397 return 0;
2398}
2399
Michal Ludvig53b320f2002-09-23 13:30:09 +00002400#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002401
Roland McGrath40542842004-01-13 09:47:49 +00002402#if defined FREEBSD || defined LINUX
Roland McGratha4d48532005-06-08 20:45:28 +00002403static const struct xlat direnttypes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002404 { DT_UNKNOWN, "DT_UNKNOWN" },
2405 { DT_FIFO, "DT_FIFO" },
2406 { DT_CHR, "DT_CHR" },
2407 { DT_DIR, "DT_DIR" },
2408 { DT_BLK, "DT_BLK" },
2409 { DT_REG, "DT_REG" },
2410 { DT_LNK, "DT_LNK" },
2411 { DT_SOCK, "DT_SOCK" },
2412 { DT_WHT, "DT_WHT" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002413 { 0, NULL },
2414};
2415
2416#endif
2417
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002418int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002419sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002420{
2421 int i, len, dents = 0;
2422 char *buf;
2423
2424 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002425 printfd(tcp, tcp->u_arg[0]);
2426 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002427 return 0;
2428 }
2429 if (syserror(tcp) || !verbose(tcp)) {
2430 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2431 return 0;
2432 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002433 len = tcp->u_rval;
Mike Frysinger229738c2009-10-07 20:41:56 -04002434 buf = len ? malloc(len) : NULL;
2435 if (len && !buf) {
Roland McGrath46100d02005-06-01 18:55:42 +00002436 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2437 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002438 return 0;
2439 }
2440 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002441 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002442 free(buf);
2443 return 0;
2444 }
2445 if (!abbrev(tcp))
2446 tprintf("{");
2447 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002448 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002449#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002450 if (!abbrev(tcp)) {
2451 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2452 i ? " " : "", d->d_ino, d->d_off);
2453 tprintf("d_reclen=%u, d_name=\"%s\"}",
2454 d->d_reclen, d->d_name);
2455 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002456#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002457#ifdef SVR4
2458 if (!abbrev(tcp)) {
2459 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002460 i ? " " : "",
2461 (unsigned long) d->d_ino,
2462 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002463 tprintf("d_reclen=%u, d_name=\"%s\"}",
2464 d->d_reclen, d->d_name);
2465 }
2466#endif /* SVR4 */
2467#ifdef SUNOS4
2468 if (!abbrev(tcp)) {
2469 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2470 i ? " " : "", d->d_off, d->d_fileno,
2471 d->d_reclen);
2472 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2473 d->d_namlen, d->d_namlen, d->d_name);
2474 }
2475#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002476#ifdef FREEBSD
2477 if (!abbrev(tcp)) {
2478 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2479 i ? " " : "", d->d_fileno, d->d_reclen);
2480 printxval(direnttypes, d->d_type, "DT_???");
2481 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2482 d->d_namlen, d->d_namlen, d->d_name);
2483 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002484#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002485 if (!d->d_reclen) {
2486 tprintf("/* d_reclen == 0, problem here */");
2487 break;
2488 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002489 i += d->d_reclen;
2490 dents++;
2491 }
2492 if (!abbrev(tcp))
2493 tprintf("}");
2494 else
2495 tprintf("/* %u entries */", dents);
2496 tprintf(", %lu", tcp->u_arg[2]);
2497 free(buf);
2498 return 0;
2499}
2500
John Hughesbdf48f52001-03-06 15:08:09 +00002501
2502#if _LFS64_LARGEFILE
2503int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002504sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002505{
2506 int i, len, dents = 0;
2507 char *buf;
2508
2509 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002510 printfd(tcp, tcp->u_arg[0]);
2511 tprintf(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002512 return 0;
2513 }
2514 if (syserror(tcp) || !verbose(tcp)) {
2515 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2516 return 0;
2517 }
2518 len = tcp->u_rval;
Mike Frysinger229738c2009-10-07 20:41:56 -04002519 buf = len ? malloc(len) : NULL;
2520 if (len && !buf) {
Roland McGrath46100d02005-06-01 18:55:42 +00002521 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2522 fprintf(stderr, "out of memory\n");
John Hughesbdf48f52001-03-06 15:08:09 +00002523 return 0;
2524 }
2525 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002526 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002527 free(buf);
2528 return 0;
2529 }
2530 if (!abbrev(tcp))
2531 tprintf("{");
2532 for (i = 0; i < len;) {
2533 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002534#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002535 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002536 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002537 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002538 d->d_ino,
2539 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002540#ifdef LINUX
2541 tprintf("d_type=");
2542 printxval(direnttypes, d->d_type, "DT_???");
2543 tprintf(", ");
2544#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002545 tprintf("d_reclen=%u, d_name=\"%s\"}",
2546 d->d_reclen, d->d_name);
2547 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002548#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002549#ifdef SUNOS4
2550 if (!abbrev(tcp)) {
2551 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2552 i ? " " : "", d->d_off, d->d_fileno,
2553 d->d_reclen);
2554 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2555 d->d_namlen, d->d_namlen, d->d_name);
2556 }
2557#endif /* SUNOS4 */
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002558 if (!d->d_reclen) {
2559 tprintf("/* d_reclen == 0, problem here */");
2560 break;
2561 }
John Hughesbdf48f52001-03-06 15:08:09 +00002562 i += d->d_reclen;
2563 dents++;
2564 }
2565 if (!abbrev(tcp))
2566 tprintf("}");
2567 else
2568 tprintf("/* %u entries */", dents);
2569 tprintf(", %lu", tcp->u_arg[2]);
2570 free(buf);
2571 return 0;
2572}
2573#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002574
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002575#ifdef FREEBSD
2576int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002577sys_getdirentries(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002578{
2579 int i, len, dents = 0;
2580 long basep;
2581 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002582
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002583 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002584 printfd(tcp, tcp->u_arg[0]);
2585 tprintf(", ");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002586 return 0;
2587 }
2588 if (syserror(tcp) || !verbose(tcp)) {
2589 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2590 return 0;
2591 }
2592 len = tcp->u_rval;
2593 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002594 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2595 fprintf(stderr, "out of memory\n");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002596 return 0;
2597 }
2598 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002599 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002600 free(buf);
2601 return 0;
2602 }
2603 if (!abbrev(tcp))
2604 tprintf("{");
2605 for (i = 0; i < len;) {
2606 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2607 if (!abbrev(tcp)) {
2608 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2609 i ? " " : "", d->d_fileno, d->d_reclen);
2610 printxval(direnttypes, d->d_type, "DT_???");
2611 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2612 d->d_namlen, d->d_namlen, d->d_name);
2613 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002614 if (!d->d_reclen) {
2615 tprintf("/* d_reclen == 0, problem here */");
2616 break;
2617 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002618 i += d->d_reclen;
2619 dents++;
2620 }
2621 if (!abbrev(tcp))
2622 tprintf("}");
2623 else
2624 tprintf("/* %u entries */", dents);
2625 free(buf);
2626 tprintf(", %lu", tcp->u_arg[2]);
2627 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2628 tprintf(", %#lx", tcp->u_arg[3]);
2629 else
2630 tprintf(", [%lu]", basep);
2631 return 0;
2632}
2633#endif
2634
Michal Ludvig53b320f2002-09-23 13:30:09 +00002635#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002636int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002637sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002638{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002639 if (exiting(tcp)) {
2640 if (syserror(tcp))
2641 tprintf("%#lx", tcp->u_arg[0]);
2642 else
2643 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2644 tprintf(", %lu", tcp->u_arg[1]);
2645 }
2646 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002647}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002648#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002649
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002650#ifdef FREEBSD
2651int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002652sys___getcwd(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002653{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002654 if (exiting(tcp)) {
2655 if (syserror(tcp))
2656 tprintf("%#lx", tcp->u_arg[0]);
2657 else
2658 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2659 tprintf(", %lu", tcp->u_arg[1]);
2660 }
2661 return 0;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002662}
2663#endif
2664
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002665#ifdef HAVE_SYS_ASYNCH_H
2666
2667int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002668sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002669{
2670 struct aio_result_t res;
2671
2672 if (entering(tcp)) {
2673 tprintf("%lu, ", tcp->u_arg[0]);
2674 } else {
2675 if (syserror(tcp))
2676 tprintf("%#lx", tcp->u_arg[1]);
2677 else
2678 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2679 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2680 printxval(whence, tcp->u_arg[4], "L_???");
2681 if (syserror(tcp) || tcp->u_arg[5] == 0
2682 || umove(tcp, tcp->u_arg[5], &res) < 0)
2683 tprintf(", %#lx", tcp->u_arg[5]);
2684 else
2685 tprintf(", {aio_return %d aio_errno %d}",
2686 res.aio_return, res.aio_errno);
2687 }
2688 return 0;
2689}
2690
2691int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002692sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002693{
2694 struct aio_result_t res;
2695
2696 if (entering(tcp)) {
2697 tprintf("%lu, ", tcp->u_arg[0]);
2698 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2699 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2700 printxval(whence, tcp->u_arg[4], "L_???");
2701 }
2702 else {
2703 if (tcp->u_arg[5] == 0)
2704 tprintf(", NULL");
2705 else if (syserror(tcp)
2706 || umove(tcp, tcp->u_arg[5], &res) < 0)
2707 tprintf(", %#lx", tcp->u_arg[5]);
2708 else
2709 tprintf(", {aio_return %d aio_errno %d}",
2710 res.aio_return, res.aio_errno);
2711 }
2712 return 0;
2713}
2714
2715int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002716sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002717{
2718 if (entering(tcp))
2719 printtv(tcp, tcp->u_arg[0]);
2720 return 0;
2721}
2722
2723int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002724sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002725{
2726 struct aio_result_t res;
2727
2728 if (exiting(tcp)) {
2729 if (tcp->u_arg[0] == 0)
2730 tprintf("NULL");
2731 else if (syserror(tcp)
2732 || umove(tcp, tcp->u_arg[0], &res) < 0)
2733 tprintf("%#lx", tcp->u_arg[0]);
2734 else
2735 tprintf("{aio_return %d aio_errno %d}",
2736 res.aio_return, res.aio_errno);
2737 }
2738 return 0;
2739}
2740
2741#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002742
Roland McGratha4d48532005-06-08 20:45:28 +00002743static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002744#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002745 { XATTR_CREATE, "XATTR_CREATE" },
2746 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002747#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002748 { 0, NULL }
2749};
2750
Roland McGrath3292e222004-08-31 06:30:48 +00002751static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002752print_xattr_val(struct tcb *tcp, int failed,
2753 unsigned long arg,
2754 unsigned long insize,
2755 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002756{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002757 if (!failed) {
2758 unsigned long capacity = 4 * size + 1;
2759 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2760 if (buf == NULL || /* probably a bogus size argument */
2761 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2762 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002763 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002764 else {
2765 unsigned char *out = buf;
2766 unsigned char *in = &buf[3 * size];
2767 size_t i;
2768 for (i = 0; i < size; ++i) {
2769 if (isprint(in[i]))
2770 *out++ = in[i];
2771 else {
2772#define tohex(n) "0123456789abcdef"[n]
2773 *out++ = '\\';
2774 *out++ = 'x';
2775 *out++ = tohex(in[i] / 16);
2776 *out++ = tohex(in[i] % 16);
2777 }
2778 }
2779 /* Don't print terminating NUL if there is one. */
2780 if (i > 0 && in[i - 1] == '\0')
2781 out -= 4;
2782 *out = '\0';
2783 tprintf(", \"%s\", %ld", buf, insize);
2784 }
2785 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002786 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002787 if (failed)
2788 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002789}
2790
Roland McGrath186c5ac2002-12-15 23:58:23 +00002791int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002792sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002793{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002794 if (entering(tcp)) {
2795 printpath(tcp, tcp->u_arg[0]);
2796 tprintf(", ");
2797 printstr(tcp, tcp->u_arg[1], -1);
2798 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2799 tprintf(", ");
2800 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2801 }
2802 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002803}
2804
2805int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002806sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002807{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002808 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002809 printfd(tcp, tcp->u_arg[0]);
2810 tprintf(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002811 printstr(tcp, tcp->u_arg[1], -1);
2812 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2813 tprintf(", ");
2814 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2815 }
2816 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002817}
2818
2819int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002820sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002821{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002822 if (entering(tcp)) {
2823 printpath(tcp, tcp->u_arg[0]);
2824 tprintf(", ");
2825 printstr(tcp, tcp->u_arg[1], -1);
2826 } else {
2827 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2828 tcp->u_rval);
2829 }
2830 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002831}
2832
2833int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002834sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002835{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002836 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002837 printfd(tcp, tcp->u_arg[0]);
2838 tprintf(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002839 printstr(tcp, tcp->u_arg[1], -1);
2840 } else {
2841 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2842 tcp->u_rval);
2843 }
2844 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002845}
2846
2847int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002848sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002849{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002850 if (entering(tcp)) {
2851 printpath(tcp, tcp->u_arg[0]);
2852 } else {
2853 /* XXX Print value in format */
2854 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2855 }
2856 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002857}
2858
2859int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002860sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002861{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002862 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002863 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002864 } else {
2865 /* XXX Print value in format */
2866 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2867 }
2868 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002869}
2870
2871int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002872sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002873{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002874 if (entering(tcp)) {
2875 printpath(tcp, tcp->u_arg[0]);
2876 tprintf(", ");
2877 printstr(tcp, tcp->u_arg[1], -1);
2878 }
2879 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002880}
2881
2882int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002883sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002884{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002885 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002886 printfd(tcp, tcp->u_arg[0]);
2887 tprintf(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002888 printstr(tcp, tcp->u_arg[1], -1);
2889 }
2890 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002891}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002892
2893
2894static const struct xlat advise[] = {
2895 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2896 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2897 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2898 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2899 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2900 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2901 { 0, NULL }
2902};
2903
2904
Roland McGrathe27ed342004-10-20 02:24:19 +00002905#ifdef LINUX
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002906int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002907sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002908{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002909 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002910 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002911 printfd(tcp, tcp->u_arg[0]);
2912 tprintf(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002913 argn = printllval(tcp, "%lld", 1);
2914 tprintf(", %ld, ", tcp->u_arg[argn++]);
2915 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002916 }
2917 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002918}
2919#endif
2920
2921
2922int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002923sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002924{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002925 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002926 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002927 printfd(tcp, tcp->u_arg[0]);
2928 tprintf(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002929#if defined ARM || defined POWERPC
2930 argn = printllval(tcp, "%lld, ", 2);
2931#else
2932 argn = printllval(tcp, "%lld, ", 1);
2933#endif
2934 argn = printllval(tcp, "%lld, ", argn);
2935#if defined ARM || defined POWERPC
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002936 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002937#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002938 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002939#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002940 }
2941 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002942}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002943
2944#ifdef LINUX
2945static const struct xlat inotify_modes[] = {
Dmitry V. Levind475c062011-03-03 01:02:41 +00002946 { 0x00000001, "IN_ACCESS" },
2947 { 0x00000002, "IN_MODIFY" },
2948 { 0x00000004, "IN_ATTRIB" },
2949 { 0x00000008, "IN_CLOSE_WRITE"},
2950 { 0x00000010, "IN_CLOSE_NOWRITE"},
2951 { 0x00000020, "IN_OPEN" },
2952 { 0x00000040, "IN_MOVED_FROM" },
2953 { 0x00000080, "IN_MOVED_TO" },
2954 { 0x00000100, "IN_CREATE" },
2955 { 0x00000200, "IN_DELETE" },
2956 { 0x00000400, "IN_DELETE_SELF"},
2957 { 0x00000800, "IN_MOVE_SELF" },
2958 { 0x00002000, "IN_UNMOUNT" },
2959 { 0x00004000, "IN_Q_OVERFLOW" },
2960 { 0x00008000, "IN_IGNORED" },
2961 { 0x01000000, "IN_ONLYDIR" },
2962 { 0x02000000, "IN_DONT_FOLLOW"},
2963 { 0x20000000, "IN_MASK_ADD" },
2964 { 0x40000000, "IN_ISDIR" },
2965 { 0x80000000, "IN_ONESHOT" },
2966 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002967};
2968
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002969static const struct xlat inotify_init_flags[] = {
2970 { 0x00000800, "IN_NONBLOCK" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002971 { 0x00080000, "IN_CLOEXEC" },
2972 { 0, NULL }
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002973};
2974
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002975int
2976sys_inotify_add_watch(struct tcb *tcp)
2977{
2978 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002979 printfd(tcp, tcp->u_arg[0]);
2980 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002981 printpath(tcp, tcp->u_arg[1]);
2982 tprintf(", ");
2983 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2984 }
2985 return 0;
2986}
2987
2988int
2989sys_inotify_rm_watch(struct tcb *tcp)
2990{
2991 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002992 printfd(tcp, tcp->u_arg[0]);
2993 tprintf(", %ld", tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002994 }
2995 return 0;
2996}
Roland McGrath96a96612008-05-20 04:56:18 +00002997
2998int
Mark Wielaardbab89402010-03-21 14:41:26 +01002999sys_inotify_init1(struct tcb *tcp)
3000{
3001 if (entering(tcp))
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01003002 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
Mark Wielaardbab89402010-03-21 14:41:26 +01003003 return 0;
3004}
3005
3006int
Roland McGrath96a96612008-05-20 04:56:18 +00003007sys_fallocate(struct tcb *tcp)
3008{
3009 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01003010 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03003011 printfd(tcp, tcp->u_arg[0]); /* fd */
3012 tprintf(", ");
Roland McGrath96a96612008-05-20 04:56:18 +00003013 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
Andreas Schwabb5600fc2009-11-04 17:08:34 +01003014 argn = printllval(tcp, "%llu, ", 2); /* offset */
3015 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00003016 }
3017 return 0;
3018}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00003019#endif