blob: 080e10b0c45dc4f452e1d358b8e3789a2d0836f9 [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
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000260 { 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
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000264 { O_DIRECTORY, "O_DIRECTORY" },
265#endif
266#ifdef O_NOFOLLOW
267 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000268#endif
Roland McGrath1025c3e2005-05-09 07:40:35 +0000269#ifdef O_NOATIME
270 { O_NOATIME, "O_NOATIME" },
271#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
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000334print_dirfd(int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000335{
336 if (fd == AT_FDCWD)
337 tprintf("AT_FDCWD, ");
338 else
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000339 tprintf("%d, ", fd);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000340}
341#endif
342
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000343/*
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000344 * Pity stpcpy() is not standardized...
345 */
346static char *
347str_append(char *dst, const char *src)
348{
349 while ((*dst = *src++) != '\0')
350 dst++;
351 return dst;
352}
353
354/*
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000355 * low bits of the open(2) flags define access mode,
356 * other bits are real flags.
357 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000358const char *
359sprint_open_modes(mode_t flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000360{
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000361 static char outstr[1024];
362 char *p;
363 char sep = 0;
364 const char *str;
365 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000366
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000367 p = str_append(outstr, "flags ");
368 str = xlookup(open_access_modes, flags & 3);
369 if (str) {
370 p = str_append(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000371 flags &= ~3;
372 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000373 return outstr;
374 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000375 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000376
377 for (x = open_mode_flags; x->str; x++) {
378 if ((flags & x->val) == x->val) {
379 if (sep)
380 *p++ = sep;
381 p = str_append(p, x->str);
382 flags &= ~x->val;
383 if (!flags)
384 return outstr;
385 sep = '|';
386 }
387 }
388 /* flags is still nonzero */
389 if (sep)
390 *p++ = sep;
391 sprintf(p, "%#x", flags);
392 return outstr;
393}
394
395void
396tprint_open_modes(mode_t flags)
397{
398 tprintf(sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000399}
400
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000401static int
402decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000403{
404 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000405 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406 tprintf(", ");
407 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000408 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000409 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000410 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000411 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000412 }
413 }
414 return 0;
415}
416
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000417int
418sys_open(struct tcb *tcp)
419{
420 return decode_open(tcp, 0);
421}
422
423#ifdef LINUX
424int
425sys_openat(struct tcb *tcp)
426{
427 if (entering(tcp))
428 print_dirfd(tcp->u_arg[0]);
429 return decode_open(tcp, 1);
430}
431#endif
432
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000433#ifdef LINUXSPARC
Roland McGratha4d48532005-06-08 20:45:28 +0000434static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000435 { 0, "O_RDWR" },
436 { 1, "O_RDONLY" },
437 { 2, "O_WRONLY" },
438 { 0x80, "O_NONBLOCK" },
439 { 8, "O_APPEND" },
440 { 0x100, "O_CREAT" },
441 { 0x200, "O_TRUNC" },
442 { 0x400, "O_EXCL" },
443 { 0x800, "O_NOCTTY" },
444 { 0x10, "O_SYNC" },
445 { 0x40, "O_DSYNC" },
446 { 0x8000, "O_RSYNC" },
447 { 4, "O_NDELAY" },
448 { 0x1000, "O_PRIV" },
449 { 0, NULL },
450};
451
452int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000453solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000454{
455 if (entering(tcp)) {
456 printpath(tcp, tcp->u_arg[0]);
457 tprintf(", ");
458 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000459 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000460 if (tcp->u_arg[1] & 0x100) {
461 /* mode */
462 tprintf(", %#lo", tcp->u_arg[2]);
463 }
464 }
465 return 0;
466}
467
468#endif
469
470int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000471sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000472{
473 if (entering(tcp)) {
474 printpath(tcp, tcp->u_arg[0]);
475 tprintf(", %#lo", tcp->u_arg[1]);
476 }
477 return 0;
478}
479
Roland McGrathd9f816f2004-09-04 03:39:20 +0000480static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000481 { F_OK, "F_OK", },
482 { R_OK, "R_OK" },
483 { W_OK, "W_OK" },
484 { X_OK, "X_OK" },
485#ifdef EFF_ONLY_OK
486 { EFF_ONLY_OK, "EFF_ONLY_OK" },
487#endif
488#ifdef EX_OK
489 { EX_OK, "EX_OK" },
490#endif
491 { 0, NULL },
492};
493
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000494static int
495decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000496{
497 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000498 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000499 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000500 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000501 }
502 return 0;
503}
504
505int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000506sys_access(struct tcb *tcp)
507{
508 return decode_access(tcp, 0);
509}
510
511#ifdef LINUX
512int
513sys_faccessat(struct tcb *tcp)
514{
515 if (entering(tcp))
516 print_dirfd(tcp->u_arg[0]);
517 return decode_access(tcp, 1);
518}
519#endif
520
521int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000522sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000523{
524 if (entering(tcp)) {
525 tprintf("%#lo", tcp->u_arg[0]);
526 }
527 return RVAL_OCTAL;
528}
529
Roland McGrathd9f816f2004-09-04 03:39:20 +0000530static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000531 { SEEK_SET, "SEEK_SET" },
532 { SEEK_CUR, "SEEK_CUR" },
533 { SEEK_END, "SEEK_END" },
534 { 0, NULL },
535};
536
John Hughes70623be2001-03-08 13:59:00 +0000537#ifndef HAVE_LONG_LONG_OFF_T
Roland McGrath542c2c62008-05-20 01:11:56 +0000538#if defined (LINUX_MIPSN32)
539int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000540sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000541{
542 long long offset;
543 int _whence;
544
545 if (entering(tcp)) {
546 tprintf("%ld, ", tcp->u_arg[0]);
547 offset = tcp->ext_arg[1];
548 _whence = tcp->u_arg[2];
549 if (_whence == SEEK_SET)
550 tprintf("%llu, ", offset);
551 else
552 tprintf("%lld, ", offset);
553 printxval(whence, _whence, "SEEK_???");
554 }
555 return RVAL_UDECIMAL;
556}
557#else /* !LINUX_MIPSN32 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000559sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000560{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000561 off_t offset;
562 int _whence;
563
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564 if (entering(tcp)) {
565 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000566 offset = tcp->u_arg[1];
567 _whence = tcp->u_arg[2];
568 if (_whence == SEEK_SET)
569 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000570 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000571 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000572 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000573 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000574 return RVAL_UDECIMAL;
575}
Roland McGrath542c2c62008-05-20 01:11:56 +0000576#endif /* LINUX_MIPSN32 */
John Hughes5a826b82001-03-07 13:21:24 +0000577#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000578
Michal Ludvig53b320f2002-09-23 13:30:09 +0000579#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000580int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000581sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000582{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000583 if (entering(tcp)) {
584 /*
585 * This one call takes explicitly two 32-bit arguments hi, lo,
586 * rather than one 64-bit argument for which LONG_LONG works
587 * appropriate for the native byte order.
588 */
589 if (tcp->u_arg[4] == SEEK_SET)
590 tprintf("%ld, %llu, ", tcp->u_arg[0],
591 (((long long int) tcp->u_arg[1]) << 32
592 | (unsigned long long) (unsigned) tcp->u_arg[2]));
593 else
594 tprintf("%ld, %lld, ", tcp->u_arg[0],
595 (((long long int) tcp->u_arg[1]) << 32
596 | (unsigned long long) (unsigned) tcp->u_arg[2]));
597 }
598 else {
599 long long int off;
600 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
601 tprintf("%#lx, ", tcp->u_arg[3]);
602 else
603 tprintf("[%llu], ", off);
604 printxval(whence, tcp->u_arg[4], "SEEK_???");
605 }
606 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000607}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000608
609int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000610sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000611{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000612 if (entering(tcp)) {
613 tprintf("%ld, %lld, %ld", tcp->u_arg[0],
Roland McGrath542c2c62008-05-20 01:11:56 +0000614# if defined LINUX_MIPSN32
Denys Vlasenko1d632462009-04-14 12:51:00 +0000615 tcp->ext_arg[1], tcp->u_arg[2]
Roland McGrath542c2c62008-05-20 01:11:56 +0000616# elif defined IA64 || defined X86_64 || defined ALPHA || defined LINUX_MIPSN64
Denys Vlasenko1d632462009-04-14 12:51:00 +0000617 (long long int) tcp->u_arg[1], tcp->u_arg[2]
Roland McGrath186c5ac2002-12-15 23:58:23 +0000618# else
Denys Vlasenko1d632462009-04-14 12:51:00 +0000619 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]
Roland McGrath186c5ac2002-12-15 23:58:23 +0000620# endif
621 );
Denys Vlasenko1d632462009-04-14 12:51:00 +0000622 }
623 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000624}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000625#endif
626
John Hughes70623be2001-03-08 13:59:00 +0000627#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000628int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000629sys_lseek64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +0000630{
631 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000632 long long offset;
633 ALIGN64 (tcp, 1); /* FreeBSD aligns off_t args */
John Hughes0c79e012001-03-08 14:40:06 +0000634 offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +0000635 if (tcp->u_arg[3] == SEEK_SET)
636 tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
637 else
638 tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
639 printxval(whence, tcp->u_arg[3], "SEEK_???");
640 }
641 return RVAL_LUDECIMAL;
642}
643#endif
644
John Hughes70623be2001-03-08 13:59:00 +0000645#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000646int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000647sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000648{
649 if (entering(tcp)) {
650 printpath(tcp, tcp->u_arg[0]);
651 tprintf(", %lu", tcp->u_arg[1]);
652 }
653 return 0;
654}
John Hughes5a826b82001-03-07 13:21:24 +0000655#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000656
John Hughes70623be2001-03-08 13:59:00 +0000657#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000658int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000659sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000660{
661 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000662 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000663 printpath(tcp, tcp->u_arg[0]);
John Hughes0c79e012001-03-08 14:40:06 +0000664 tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
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)) {
675 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
676 }
677 return 0;
678}
John Hughes5a826b82001-03-07 13:21:24 +0000679#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000680
John Hughes70623be2001-03-08 13:59:00 +0000681#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000682int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000683sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000684{
685 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000686 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000687 tprintf("%ld, %llu", tcp->u_arg[0],
John Hughes0c79e012001-03-08 14:40:06 +0000688 LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000689 }
690 return 0;
691}
692#endif
693
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000694/* several stats */
695
Roland McGrathd9f816f2004-09-04 03:39:20 +0000696static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000697 { S_IFREG, "S_IFREG" },
698 { S_IFSOCK, "S_IFSOCK" },
699 { S_IFIFO, "S_IFIFO" },
700 { S_IFLNK, "S_IFLNK" },
701 { S_IFDIR, "S_IFDIR" },
702 { S_IFBLK, "S_IFBLK" },
703 { S_IFCHR, "S_IFCHR" },
704 { 0, NULL },
705};
706
Roland McGrathf9c49b22004-10-06 22:11:54 +0000707static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000708sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000709{
710 static char buf[64];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000711 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000712
713 if ((mode & S_IFMT) == 0)
714 s = "";
715 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
716 sprintf(buf, "%#o", mode);
717 return buf;
718 }
719 sprintf(buf, "%s%s%s%s", s,
720 (mode & S_ISUID) ? "|S_ISUID" : "",
721 (mode & S_ISGID) ? "|S_ISGID" : "",
722 (mode & S_ISVTX) ? "|S_ISVTX" : "");
723 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
724 if (mode)
725 sprintf(buf + strlen(buf), "|%#o", mode);
726 s = (*buf == '|') ? buf + 1 : buf;
727 return *s ? s : "0";
728}
729
730static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000731sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000732{
733 struct tm *tmp;
734 static char buf[32];
735
736 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000737 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000738 return buf;
739 }
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000740 if ((tmp = localtime(&t)))
741 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
742 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
743 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
744 else
745 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
746
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000747 return buf;
748}
749
750#ifdef LINUXSPARC
751typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000752 int tv_sec;
753 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000754} timestruct_t;
755
756struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000757 unsigned st_dev;
758 int st_pad1[3]; /* network id */
759 unsigned st_ino;
760 unsigned st_mode;
761 unsigned st_nlink;
762 unsigned st_uid;
763 unsigned st_gid;
764 unsigned st_rdev;
765 int st_pad2[2];
766 int st_size;
767 int st_pad3; /* st_size, off_t expansion */
768 timestruct_t st_atime;
769 timestruct_t st_mtime;
770 timestruct_t st_ctime;
771 int st_blksize;
772 int st_blocks;
773 char st_fstype[16];
774 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000775};
776
777static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000778printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000779{
780 struct solstat statbuf;
781
782 if (!addr) {
783 tprintf("NULL");
784 return;
785 }
786 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000787 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000788 return;
789 }
790 if (umove(tcp, addr, &statbuf) < 0) {
791 tprintf("{...}");
792 return;
793 }
794 if (!abbrev(tcp)) {
795 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
796 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
797 (unsigned long) (statbuf.st_dev & 0x3ffff),
798 (unsigned long) statbuf.st_ino,
799 sprintmode(statbuf.st_mode));
800 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
801 (unsigned long) statbuf.st_nlink,
802 (unsigned long) statbuf.st_uid,
803 (unsigned long) statbuf.st_gid);
804 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
805 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
806 }
807 else
808 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
809 switch (statbuf.st_mode & S_IFMT) {
810 case S_IFCHR: case S_IFBLK:
811 tprintf("st_rdev=makedev(%lu, %lu), ",
812 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
813 (unsigned long) (statbuf.st_rdev & 0x3ffff));
814 break;
815 default:
816 tprintf("st_size=%u, ", statbuf.st_size);
817 break;
818 }
819 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000820 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
821 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
822 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000823 }
824 else
825 tprintf("...}");
826}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000827
828#if defined (SPARC64)
829static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000830printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000831{
832 struct stat_sparc64 statbuf;
833
834 if (!addr) {
835 tprintf("NULL");
836 return;
837 }
838 if (syserror(tcp) || !verbose(tcp)) {
839 tprintf("%#lx", addr);
840 return;
841 }
842 if (umove(tcp, addr, &statbuf) < 0) {
843 tprintf("{...}");
844 return;
845 }
846
847 if (!abbrev(tcp)) {
848 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
849 (unsigned long) major(statbuf.st_dev),
850 (unsigned long) minor(statbuf.st_dev),
851 (unsigned long) statbuf.st_ino,
852 sprintmode(statbuf.st_mode));
853 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
854 (unsigned long) statbuf.st_nlink,
855 (unsigned long) statbuf.st_uid,
856 (unsigned long) statbuf.st_gid);
857 tprintf("st_blksize=%lu, ",
858 (unsigned long) statbuf.st_blksize);
859 tprintf("st_blocks=%lu, ",
860 (unsigned long) statbuf.st_blocks);
861 }
862 else
863 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
864 switch (statbuf.st_mode & S_IFMT) {
865 case S_IFCHR: case S_IFBLK:
866 tprintf("st_rdev=makedev(%lu, %lu), ",
867 (unsigned long) major(statbuf.st_rdev),
868 (unsigned long) minor(statbuf.st_rdev));
869 break;
870 default:
871 tprintf("st_size=%lu, ", statbuf.st_size);
872 break;
873 }
874 if (!abbrev(tcp)) {
875 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
876 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
877 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
878 tprintf("}");
879 }
880 else
881 tprintf("...}");
882}
883#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000884#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000885
Roland McGratha4d48532005-06-08 20:45:28 +0000886static const struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000887#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000888 { UF_NODUMP, "UF_NODUMP" },
889 { UF_IMMUTABLE, "UF_IMMUTABLE" },
890 { UF_APPEND, "UF_APPEND" },
891 { UF_OPAQUE, "UF_OPAQUE" },
892 { UF_NOUNLINK, "UF_NOUNLINK" },
893 { SF_ARCHIVED, "SF_ARCHIVED" },
894 { SF_IMMUTABLE, "SF_IMMUTABLE" },
895 { SF_APPEND, "SF_APPEND" },
896 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000897#elif UNIXWARE >= 2
898#ifdef _S_ISMLD
899 { _S_ISMLD, "_S_ISMLD" },
900#endif
901#ifdef _S_ISMOUNTED
902 { _S_ISMOUNTED, "_S_ISMOUNTED" },
903#endif
904#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000905 { 0, NULL },
906};
907
John Hughesc0fc3fd2001-03-08 16:10:40 +0000908#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000909int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000910sys_chflags(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000911{
912 if (entering(tcp)) {
913 printpath(tcp, tcp->u_arg[0]);
914 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000915 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000916 }
917 return 0;
918}
919
920int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000921sys_fchflags(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000922{
923 if (entering(tcp)) {
924 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000925 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000926 }
927 return 0;
928}
929#endif
930
John Hughes70623be2001-03-08 13:59:00 +0000931#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000932static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000933realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000934{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000935 if (!abbrev(tcp)) {
936 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
937 (unsigned long) major(statbuf->st_dev),
938 (unsigned long) minor(statbuf->st_dev),
939 (unsigned long) statbuf->st_ino,
940 sprintmode(statbuf->st_mode));
941 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
942 (unsigned long) statbuf->st_nlink,
943 (unsigned long) statbuf->st_uid,
944 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000945#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000946 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
947#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000948#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000949 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
950#endif
951 }
952 else
953 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
954 switch (statbuf->st_mode & S_IFMT) {
955 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000956#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000957 tprintf("st_rdev=makedev(%lu, %lu), ",
958 (unsigned long) major(statbuf->st_rdev),
959 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000960#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000961 tprintf("st_size=makedev(%lu, %lu), ",
962 (unsigned long) major(statbuf->st_size),
963 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000964#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000965 break;
966 default:
967 tprintf("st_size=%lu, ", statbuf->st_size);
968 break;
969 }
970 if (!abbrev(tcp)) {
971 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
972 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
973 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000974#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000975 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000976 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000977#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000978#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000979 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
980#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000981#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000982 tprintf(", st_level=%ld", statbuf->st_level);
983#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000984#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000985 tprintf(", st_fstype=%.*s",
986 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
987#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000988#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000989 tprintf(", st_gen=%u", statbuf->st_gen);
990#endif
991 tprintf("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000992 }
993 else
994 tprintf("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000995}
996
Nate Sammons771a6ff1999-04-05 22:39:31 +0000997
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000998static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000999printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001000{
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001001 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001002
1003#ifdef LINUXSPARC
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001004 if (current_personality == 1) {
1005 printstatsol(tcp, addr);
1006 return;
1007 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001008#ifdef SPARC64
1009 else if (current_personality == 2) {
1010 printstat_sparc64(tcp, addr);
1011 return;
1012 }
1013#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001014#endif /* LINUXSPARC */
1015
1016 if (!addr) {
1017 tprintf("NULL");
1018 return;
1019 }
1020 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001021 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001022 return;
1023 }
1024 if (umove(tcp, addr, &statbuf) < 0) {
1025 tprintf("{...}");
1026 return;
1027 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001028
1029 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001030}
John Hughes70623be2001-03-08 13:59:00 +00001031#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001032
Roland McGrathe6d0f712007-08-07 01:22:49 +00001033#if !defined HAVE_STAT64 && defined LINUX && defined X86_64
1034/*
1035 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1036 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1037 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1038 * __GNUC__ is needed for the required __attribute__ below.
1039 */
1040struct stat64 {
1041 unsigned long long st_dev;
1042 unsigned char __pad0[4];
1043 unsigned int __st_ino;
1044 unsigned int st_mode;
1045 unsigned int st_nlink;
1046 unsigned int st_uid;
1047 unsigned int st_gid;
1048 unsigned long long st_rdev;
1049 unsigned char __pad3[4];
1050 long long st_size;
1051 unsigned int st_blksize;
1052 unsigned long long st_blocks;
1053 unsigned int st_atime;
1054 unsigned int st_atime_nsec;
1055 unsigned int st_mtime;
1056 unsigned int st_mtime_nsec;
1057 unsigned int st_ctime;
1058 unsigned int st_ctime_nsec;
1059 unsigned long long st_ino;
1060} __attribute__((packed));
1061# define HAVE_STAT64 1
1062# define STAT64_SIZE 96
1063#endif
1064
Wichert Akkermanc7926982000-04-10 22:22:31 +00001065#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001066static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001067printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001068{
1069 struct stat64 statbuf;
1070
Roland McGrathe6d0f712007-08-07 01:22:49 +00001071#ifdef STAT64_SIZE
1072 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1073#endif
1074
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001075#ifdef LINUXSPARC
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001076 if (current_personality == 1) {
1077 printstatsol(tcp, addr);
1078 return;
1079 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001080#ifdef SPARC64
1081 else if (current_personality == 2) {
1082 printstat_sparc64(tcp, addr);
1083 return;
1084 }
1085#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001086#endif /* LINUXSPARC */
1087
1088 if (!addr) {
1089 tprintf("NULL");
1090 return;
1091 }
1092 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001093 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001094 return;
1095 }
1096 if (umove(tcp, addr, &statbuf) < 0) {
1097 tprintf("{...}");
1098 return;
1099 }
1100
1101 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001102#ifdef HAVE_LONG_LONG
1103 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1104#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001105 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001106#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001107 (unsigned long) major(statbuf.st_dev),
1108 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001109#ifdef HAVE_LONG_LONG
1110 (unsigned long long) statbuf.st_ino,
1111#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001112 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001113#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001114 sprintmode(statbuf.st_mode));
1115 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1116 (unsigned long) statbuf.st_nlink,
1117 (unsigned long) statbuf.st_uid,
1118 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001119#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001120 tprintf("st_blksize=%lu, ",
1121 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001122#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1123#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001124 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001125#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001126 }
1127 else
1128 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1129 switch (statbuf.st_mode & S_IFMT) {
1130 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001131#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001132 tprintf("st_rdev=makedev(%lu, %lu), ",
1133 (unsigned long) major(statbuf.st_rdev),
1134 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001135#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001136 tprintf("st_size=makedev(%lu, %lu), ",
1137 (unsigned long) major(statbuf.st_size),
1138 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001139#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001140 break;
1141 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001142#ifdef HAVE_LONG_LONG
1143 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1144#else
1145 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1146#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001147 break;
1148 }
1149 if (!abbrev(tcp)) {
1150 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1151 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001152 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001153#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +00001154 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001155 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001156#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001157#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001158 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1159#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001160#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001161 tprintf(", st_level=%ld", statbuf.st_level);
1162#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001163#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001164 tprintf(", st_fstype=%.*s",
1165 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1166#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001167#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001168 tprintf(", st_gen=%u", statbuf.st_gen);
1169#endif
1170 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001171 }
1172 else
1173 tprintf("...}");
1174}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001175#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001176
Roland McGrath79db8af2003-06-27 21:20:09 +00001177#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001178static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001179convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001180{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001181 newbuf->st_dev = oldbuf->st_dev;
1182 newbuf->st_ino = oldbuf->st_ino;
1183 newbuf->st_mode = oldbuf->st_mode;
1184 newbuf->st_nlink = oldbuf->st_nlink;
1185 newbuf->st_uid = oldbuf->st_uid;
1186 newbuf->st_gid = oldbuf->st_gid;
1187 newbuf->st_rdev = oldbuf->st_rdev;
1188 newbuf->st_size = oldbuf->st_size;
1189 newbuf->st_atime = oldbuf->st_atime;
1190 newbuf->st_mtime = oldbuf->st_mtime;
1191 newbuf->st_ctime = oldbuf->st_ctime;
1192 newbuf->st_blksize = 0; /* not supported in old_stat */
1193 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001194}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001195
1196
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001197static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001198printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001199{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001200 struct __old_kernel_stat statbuf;
1201 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001202
1203#ifdef LINUXSPARC
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001204 if (current_personality == 1) {
1205 printstatsol(tcp, addr);
1206 return;
1207 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001208#endif /* LINUXSPARC */
1209
1210 if (!addr) {
1211 tprintf("NULL");
1212 return;
1213 }
1214 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001215 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001216 return;
1217 }
1218 if (umove(tcp, addr, &statbuf) < 0) {
1219 tprintf("{...}");
1220 return;
1221 }
1222
1223 convertoldstat(&statbuf, &newstatbuf);
1224 realprintstat(tcp, &newstatbuf);
1225}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001226#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001227
John Hughes70623be2001-03-08 13:59:00 +00001228#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001229int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001230sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001231{
1232 if (entering(tcp)) {
1233 printpath(tcp, tcp->u_arg[0]);
1234 tprintf(", ");
1235 } else {
1236 printstat(tcp, tcp->u_arg[1]);
1237 }
1238 return 0;
1239}
John Hughesb8c9f772001-03-07 16:53:07 +00001240#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001241
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001242int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001243sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001244{
1245#ifdef HAVE_STAT64
1246 if (entering(tcp)) {
1247 printpath(tcp, tcp->u_arg[0]);
1248 tprintf(", ");
1249 } else {
1250 printstat64(tcp, tcp->u_arg[1]);
1251 }
1252 return 0;
1253#else
1254 return printargs(tcp);
1255#endif
1256}
1257
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001258#ifdef LINUX
1259static const struct xlat fstatatflags[] = {
1260#ifndef AT_SYMLINK_NOFOLLOW
1261# define AT_SYMLINK_NOFOLLOW 0x100
1262#endif
1263 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1264 { 0, NULL },
1265};
Roland McGrath6afc5652007-07-24 01:57:11 +00001266#define utimensatflags fstatatflags
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001267
1268int
1269sys_newfstatat(struct tcb *tcp)
1270{
1271 if (entering(tcp)) {
1272 print_dirfd(tcp->u_arg[0]);
1273 printpath(tcp, tcp->u_arg[1]);
1274 tprintf(", ");
1275 } else {
Roland McGrath359c8ed2007-07-05 19:01:17 +00001276#if defined HAVE_STAT64 && !(defined POWERPC && defined __powerpc64__)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001277 printstat64(tcp, tcp->u_arg[2]);
1278#else
1279 printstat(tcp, tcp->u_arg[2]);
1280#endif
1281 tprintf(", ");
1282 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1283 }
1284 return 0;
1285}
1286#endif
1287
Roland McGrath79db8af2003-06-27 21:20:09 +00001288#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001289int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001290sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001291{
1292 if (entering(tcp)) {
1293 printpath(tcp, tcp->u_arg[0]);
1294 tprintf(", ");
1295 } else {
1296 printoldstat(tcp, tcp->u_arg[1]);
1297 }
1298 return 0;
1299}
Roland McGrath79db8af2003-06-27 21:20:09 +00001300#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001301
John Hughes70623be2001-03-08 13:59:00 +00001302#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001303int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001304sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001305{
1306 if (entering(tcp))
1307 tprintf("%ld, ", tcp->u_arg[0]);
1308 else {
1309 printstat(tcp, tcp->u_arg[1]);
1310 }
1311 return 0;
1312}
John Hughesb8c9f772001-03-07 16:53:07 +00001313#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001314
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001315int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001316sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001317{
1318#ifdef HAVE_STAT64
1319 if (entering(tcp))
1320 tprintf("%ld, ", tcp->u_arg[0]);
1321 else {
1322 printstat64(tcp, tcp->u_arg[1]);
1323 }
1324 return 0;
1325#else
1326 return printargs(tcp);
1327#endif
1328}
1329
Roland McGrath79db8af2003-06-27 21:20:09 +00001330#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001331int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001332sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001333{
1334 if (entering(tcp))
1335 tprintf("%ld, ", tcp->u_arg[0]);
1336 else {
1337 printoldstat(tcp, tcp->u_arg[1]);
1338 }
1339 return 0;
1340}
Roland McGrath79db8af2003-06-27 21:20:09 +00001341#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001342
John Hughes70623be2001-03-08 13:59:00 +00001343#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001344int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001345sys_lstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001346{
1347 if (entering(tcp)) {
1348 printpath(tcp, tcp->u_arg[0]);
1349 tprintf(", ");
1350 } else {
1351 printstat(tcp, tcp->u_arg[1]);
1352 }
1353 return 0;
1354}
John Hughesb8c9f772001-03-07 16:53:07 +00001355#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001356
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001357int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001358sys_lstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001359{
1360#ifdef HAVE_STAT64
1361 if (entering(tcp)) {
1362 printpath(tcp, tcp->u_arg[0]);
1363 tprintf(", ");
1364 } else {
1365 printstat64(tcp, tcp->u_arg[1]);
1366 }
1367 return 0;
1368#else
1369 return printargs(tcp);
1370#endif
1371}
1372
Roland McGrath79db8af2003-06-27 21:20:09 +00001373#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001374int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001375sys_oldlstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001376{
1377 if (entering(tcp)) {
1378 printpath(tcp, tcp->u_arg[0]);
1379 tprintf(", ");
1380 } else {
1381 printoldstat(tcp, tcp->u_arg[1]);
1382 }
1383 return 0;
1384}
Roland McGrath79db8af2003-06-27 21:20:09 +00001385#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001386
1387
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001388#if defined(SVR4) || defined(LINUXSPARC)
1389
1390int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001391sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001392{
1393 if (entering(tcp)) {
1394 tprintf("%ld, ", tcp->u_arg[0]);
1395 printpath(tcp, tcp->u_arg[1]);
1396 tprintf(", ");
1397 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001398#ifdef _STAT64_VER
1399 if (tcp->u_arg[0] == _STAT64_VER)
1400 printstat64 (tcp, tcp->u_arg[2]);
1401 else
1402#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001403 printstat(tcp, tcp->u_arg[2]);
1404 }
1405 return 0;
1406}
1407
1408int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001409sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001410{
1411 if (entering(tcp))
1412 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1413 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001414#ifdef _STAT64_VER
1415 if (tcp->u_arg[0] == _STAT64_VER)
1416 printstat64 (tcp, tcp->u_arg[2]);
1417 else
1418#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001419 printstat(tcp, tcp->u_arg[2]);
1420 }
1421 return 0;
1422}
1423
1424int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001425sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001426{
1427 if (entering(tcp)) {
1428 tprintf("%ld, ", tcp->u_arg[0]);
1429 printpath(tcp, tcp->u_arg[1]);
1430 tprintf(", ");
1431 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001432#ifdef _STAT64_VER
1433 if (tcp->u_arg[0] == _STAT64_VER)
1434 printstat64 (tcp, tcp->u_arg[2]);
1435 else
1436#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001437 printstat(tcp, tcp->u_arg[2]);
1438 }
1439 return 0;
1440}
1441
1442int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001443sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001444{
1445 int mode = tcp->u_arg[2];
1446
1447 if (entering(tcp)) {
1448 tprintf("%ld, ", tcp->u_arg[0]);
1449 printpath(tcp, tcp->u_arg[1]);
1450 tprintf(", %s", sprintmode(mode));
1451 switch (mode & S_IFMT) {
1452 case S_IFCHR: case S_IFBLK:
1453#ifdef LINUXSPARC
1454 tprintf(", makedev(%lu, %lu)",
1455 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1456 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001457#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001458 tprintf(", makedev(%lu, %lu)",
1459 (unsigned long) major(tcp->u_arg[3]),
1460 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001461#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001462 break;
1463 default:
1464 break;
1465 }
1466 }
1467 return 0;
1468}
1469
Wichert Akkerman8829a551999-06-11 13:18:40 +00001470#ifdef HAVE_SYS_ACL_H
1471
1472#include <sys/acl.h>
1473
Roland McGratha4d48532005-06-08 20:45:28 +00001474static const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001475#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001476 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001477#endif
1478#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001479 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001480#endif
1481#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001482 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001483#endif
1484#ifdef ACL_GET
1485 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001486#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001487#ifdef ACL_SET
1488 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001489#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001490#ifdef ACL_CNT
1491 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001492#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001493 { 0, NULL },
1494};
1495
1496int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001497sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001498{
1499 if (entering(tcp)) {
1500 printpath(tcp, tcp->u_arg[0]);
1501 tprintf(", ");
1502 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1503 tprintf(", %ld", tcp->u_arg[2]);
1504 /*
1505 * FIXME - dump out the list of aclent_t's pointed to
1506 * by "tcp->u_arg[3]" if it's not NULL.
1507 */
1508 if (tcp->u_arg[3])
1509 tprintf(", %#lx", tcp->u_arg[3]);
1510 else
1511 tprintf(", NULL");
1512 }
1513 return 0;
1514}
1515
1516
1517int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001518sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001519{
1520 if (entering(tcp)) {
1521 tprintf("%ld, ", tcp->u_arg[0]);
1522 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1523 tprintf(", %ld", tcp->u_arg[2]);
1524 /*
1525 * FIXME - dump out the list of aclent_t's pointed to
1526 * by "tcp->u_arg[3]" if it's not NULL.
1527 */
1528 if (tcp->u_arg[3])
1529 tprintf(", %#lx", tcp->u_arg[3]);
1530 else
1531 tprintf(", NULL");
1532 }
1533 return 0;
1534}
1535
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001536
Roland McGratha4d48532005-06-08 20:45:28 +00001537static const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001538#ifdef IPC_SHM
1539 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001540#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001541#ifdef IPC_SEM
1542 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001543#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001544#ifdef IPC_MSG
1545 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001546#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001547 { 0, NULL },
1548};
1549
1550
1551int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001552sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001553{
1554 if (entering(tcp)) {
1555 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1556 tprintf(", %#lx, ", tcp->u_arg[1]);
1557 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1558 tprintf(", %ld", tcp->u_arg[3]);
1559 /*
1560 * FIXME - dump out the list of aclent_t's pointed to
1561 * by "tcp->u_arg[4]" if it's not NULL.
1562 */
1563 if (tcp->u_arg[4])
1564 tprintf(", %#lx", tcp->u_arg[4]);
1565 else
1566 tprintf(", NULL");
1567 }
1568 return 0;
1569}
1570
Wichert Akkerman8829a551999-06-11 13:18:40 +00001571#endif /* HAVE_SYS_ACL_H */
1572
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001573#endif /* SVR4 || LINUXSPARC */
1574
Michal Ludvig53b320f2002-09-23 13:30:09 +00001575#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001576
Roland McGrathd9f816f2004-09-04 03:39:20 +00001577static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001578 { 0x73757245, "CODA_SUPER_MAGIC" },
1579 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1580 { 0x1373, "DEVFS_SUPER_MAGIC" },
1581 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1582 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001583 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1584 { 0xef53, "EXT2_SUPER_MAGIC" },
1585 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001586 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001587 { 0x9660, "ISOFS_SUPER_MAGIC" },
1588 { 0x137f, "MINIX_SUPER_MAGIC" },
1589 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001590 { 0x2468, "MINIX2_SUPER_MAGIC" },
1591 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001592 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001593 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001594 { 0x6969, "NFS_SUPER_MAGIC" },
1595 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001596 { 0x002f, "QNX4_SUPER_MAGIC" },
1597 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1598 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1599 { 0x517b, "SMB_SUPER_MAGIC" },
1600 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1601 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1602 { 0x00011954, "UFS_MAGIC" },
1603 { 0x54190100, "UFS_CIGAM" },
1604 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001605 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001606 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001607 { 0, NULL },
1608};
1609
Michal Ludvig53b320f2002-09-23 13:30:09 +00001610#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001611
1612#ifndef SVR4
1613
Roland McGrathf9c49b22004-10-06 22:11:54 +00001614static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001615sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001616{
1617 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001618#ifdef LINUX
Roland McGrathf9c49b22004-10-06 22:11:54 +00001619 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001620
1621 s = xlookup(fsmagic, magic);
1622 if (s) {
1623 sprintf(buf, "\"%s\"", s);
1624 return buf;
1625 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001626#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001627 sprintf(buf, "%#x", magic);
1628 return buf;
1629}
1630
1631static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001632printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001633{
1634 struct statfs statbuf;
1635
1636 if (syserror(tcp) || !verbose(tcp)) {
1637 tprintf("%#lx", addr);
1638 return;
1639 }
1640 if (umove(tcp, addr, &statbuf) < 0) {
1641 tprintf("{...}");
1642 return;
1643 }
1644#ifdef ALPHA
1645
1646 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1647 sprintfstype(statbuf.f_type),
1648 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001649 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1650 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1651 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1652 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001653#else /* !ALPHA */
1654 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1655 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001656 (unsigned long)statbuf.f_bsize,
1657 (unsigned long)statbuf.f_blocks,
1658 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001659 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1660 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001661 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001662 (unsigned long)statbuf.f_ffree,
1663 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001664#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001665 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001666#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001667#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001668#ifdef _STATFS_F_FRSIZE
1669 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1670#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001671 tprintf("}");
1672}
1673
1674int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001675sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001676{
1677 if (entering(tcp)) {
1678 printpath(tcp, tcp->u_arg[0]);
1679 tprintf(", ");
1680 } else {
1681 printstatfs(tcp, tcp->u_arg[1]);
1682 }
1683 return 0;
1684}
1685
1686int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001687sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001688{
1689 if (entering(tcp)) {
1690 tprintf("%lu, ", tcp->u_arg[0]);
1691 } else {
1692 printstatfs(tcp, tcp->u_arg[1]);
1693 }
1694 return 0;
1695}
1696
Roland McGrathab147c52003-07-17 09:03:02 +00001697#ifdef LINUX
1698static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001699printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001700{
1701 struct statfs64 statbuf;
1702
1703 if (syserror(tcp) || !verbose(tcp)) {
1704 tprintf("%#lx", addr);
1705 return;
1706 }
1707 if (umove(tcp, addr, &statbuf) < 0) {
1708 tprintf("{...}");
1709 return;
1710 }
Roland McGrath08738432005-06-03 02:40:39 +00001711 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001712 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001713 (unsigned long long)statbuf.f_bsize,
1714 (unsigned long long)statbuf.f_blocks,
1715 (unsigned long long)statbuf.f_bfree);
1716 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1717 (unsigned long long)statbuf.f_bavail,
1718 (unsigned long long)statbuf.f_files,
1719 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001720 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1721 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001722#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001723 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001724#endif
1725 tprintf("}");
1726}
1727
1728int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001729sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001730{
1731 if (entering(tcp)) {
1732 printpath(tcp, tcp->u_arg[0]);
1733 tprintf(", %lu, ", tcp->u_arg[1]);
1734 } else {
1735 if (tcp->u_arg[1] == sizeof (struct statfs64))
1736 printstatfs64(tcp, tcp->u_arg[2]);
1737 else
1738 tprintf("{???}");
1739 }
1740 return 0;
1741}
1742
1743int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001744sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001745{
1746 if (entering(tcp)) {
1747 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1748 } else {
1749 if (tcp->u_arg[1] == sizeof (struct statfs64))
1750 printstatfs64(tcp, tcp->u_arg[2]);
1751 else
1752 tprintf("{???}");
1753 }
1754 return 0;
1755}
1756#endif
1757
Michal Ludvig53b320f2002-09-23 13:30:09 +00001758#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001759
1760int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001761osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001762{
1763 if (entering(tcp)) {
1764 printpath(tcp, tcp->u_arg[0]);
1765 tprintf(", ");
1766 } else {
1767 printstatfs(tcp, tcp->u_arg[1]);
1768 tprintf(", %lu", tcp->u_arg[2]);
1769 }
1770 return 0;
1771}
1772
1773int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001774osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001775{
1776 if (entering(tcp)) {
1777 tprintf("%lu, ", tcp->u_arg[0]);
1778 } else {
1779 printstatfs(tcp, tcp->u_arg[1]);
1780 tprintf(", %lu", tcp->u_arg[2]);
1781 }
1782 return 0;
1783}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001784#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001785
1786#endif /* !SVR4 */
1787
1788#ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001789int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001790sys_ustat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001791{
1792 struct ustat statbuf;
1793
1794 if (entering(tcp)) {
1795 tprintf("makedev(%lu, %lu), ",
1796 (long) major(tcp->u_arg[0]),
1797 (long) minor(tcp->u_arg[0]));
1798 }
1799 else {
1800 if (syserror(tcp) || !verbose(tcp))
1801 tprintf("%#lx", tcp->u_arg[1]);
1802 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1803 tprintf("{...}");
1804 else {
1805 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1806 statbuf.f_tfree, statbuf.f_tinode);
1807 tprintf("f_fname=\"%.*s\", ",
1808 (int) sizeof(statbuf.f_fname),
1809 statbuf.f_fname);
1810 tprintf("f_fpack=\"%.*s\"}",
1811 (int) sizeof(statbuf.f_fpack),
1812 statbuf.f_fpack);
1813 }
1814 }
1815 return 0;
1816}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001817#endif /* SUNOS4 */
1818
Wichert Akkermanc7926982000-04-10 22:22:31 +00001819int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001820sys_pivotroot(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +00001821{
1822 if (entering(tcp)) {
1823 printpath(tcp, tcp->u_arg[0]);
1824 tprintf(", ");
1825 printpath(tcp, tcp->u_arg[1]);
1826 }
1827 return 0;
1828}
1829
1830
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001831/* directory */
1832int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001833sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001834{
1835 if (entering(tcp)) {
1836 printpath(tcp, tcp->u_arg[0]);
1837 }
1838 return 0;
1839}
1840
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001841static int
1842decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001843{
1844 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001845 printpath(tcp, tcp->u_arg[offset]);
1846 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001847 }
1848 return 0;
1849}
1850
1851int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001852sys_mkdir(struct tcb *tcp)
1853{
1854 return decode_mkdir(tcp, 0);
1855}
1856
1857#ifdef LINUX
1858int
1859sys_mkdirat(struct tcb *tcp)
1860{
1861 if (entering(tcp))
1862 print_dirfd(tcp->u_arg[0]);
1863 return decode_mkdir(tcp, 1);
1864}
1865#endif
1866
1867int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001868sys_rmdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001869{
1870 if (entering(tcp)) {
1871 printpath(tcp, tcp->u_arg[0]);
1872 }
1873 return 0;
1874}
1875
1876int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001877sys_fchdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001878{
1879 if (entering(tcp)) {
1880 tprintf("%ld", tcp->u_arg[0]);
1881 }
1882 return 0;
1883}
1884
1885int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001886sys_chroot(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001887{
1888 if (entering(tcp)) {
1889 printpath(tcp, tcp->u_arg[0]);
1890 }
1891 return 0;
1892}
1893
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001894#if defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001895int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001896sys_fchroot(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001897{
1898 if (entering(tcp)) {
1899 tprintf("%ld", tcp->u_arg[0]);
1900 }
1901 return 0;
1902}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001903#endif /* SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001904
1905int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001906sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001907{
1908 if (entering(tcp)) {
1909 printpath(tcp, tcp->u_arg[0]);
1910 tprintf(", ");
1911 printpath(tcp, tcp->u_arg[1]);
1912 }
1913 return 0;
1914}
1915
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001916#ifdef LINUX
1917int
1918sys_linkat(struct tcb *tcp)
1919{
1920 if (entering(tcp)) {
1921 print_dirfd(tcp->u_arg[0]);
1922 printpath(tcp, tcp->u_arg[1]);
1923 tprintf(", ");
1924 print_dirfd(tcp->u_arg[2]);
1925 printpath(tcp, tcp->u_arg[3]);
1926 tprintf(", %ld", tcp->u_arg[4]);
1927 }
1928 return 0;
1929}
1930#endif
1931
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001932int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001933sys_unlink(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001934{
1935 if (entering(tcp)) {
1936 printpath(tcp, tcp->u_arg[0]);
1937 }
1938 return 0;
1939}
1940
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001941#ifdef LINUX
1942static const struct xlat unlinkatflags[] = {
1943#ifndef AT_REMOVEDIR
1944# define AT_REMOVEDIR 0x200
1945#endif
1946 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1947 { 0, NULL },
1948};
1949
1950int
1951sys_unlinkat(struct tcb *tcp)
1952{
1953 if (entering(tcp)) {
1954 print_dirfd(tcp->u_arg[0]);
1955 printpath(tcp, tcp->u_arg[1]);
1956 tprintf(", ");
1957 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1958 }
1959 return 0;
1960}
1961#endif
1962
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001963int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001964sys_symlink(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001965{
1966 if (entering(tcp)) {
1967 printpath(tcp, tcp->u_arg[0]);
1968 tprintf(", ");
1969 printpath(tcp, tcp->u_arg[1]);
1970 }
1971 return 0;
1972}
1973
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001974#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001975int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001976sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001977{
1978 if (entering(tcp)) {
1979 printpath(tcp, tcp->u_arg[0]);
1980 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001981 print_dirfd(tcp->u_arg[1]);
1982 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001983 }
1984 return 0;
1985}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001986#endif
1987
1988static int
1989decode_readlink(struct tcb *tcp, int offset)
1990{
1991 if (entering(tcp)) {
1992 printpath(tcp, tcp->u_arg[offset]);
1993 tprintf(", ");
1994 } else {
1995 if (syserror(tcp))
1996 tprintf("%#lx", tcp->u_arg[offset + 1]);
1997 else
1998 printpathn(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1999 tprintf(", %lu", tcp->u_arg[offset + 2]);
2000 }
2001 return 0;
2002}
2003
2004int
2005sys_readlink(struct tcb *tcp)
2006{
2007 return decode_readlink(tcp, 0);
2008}
2009
2010#ifdef LINUX
2011int
2012sys_readlinkat(struct tcb *tcp)
2013{
2014 if (entering(tcp))
2015 print_dirfd(tcp->u_arg[0]);
2016 return decode_readlink(tcp, 1);
2017}
2018#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002019
2020int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002021sys_rename(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002022{
2023 if (entering(tcp)) {
2024 printpath(tcp, tcp->u_arg[0]);
2025 tprintf(", ");
2026 printpath(tcp, tcp->u_arg[1]);
2027 }
2028 return 0;
2029}
2030
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002031#ifdef LINUX
2032int
2033sys_renameat(struct tcb *tcp)
2034{
2035 if (entering(tcp)) {
2036 print_dirfd(tcp->u_arg[0]);
2037 printpath(tcp, tcp->u_arg[1]);
2038 tprintf(", ");
2039 print_dirfd(tcp->u_arg[2]);
2040 printpath(tcp, tcp->u_arg[3]);
2041 }
2042 return 0;
2043}
2044#endif
2045
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002046int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002047sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002048{
2049 if (entering(tcp)) {
2050 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002051 printuid(", ", tcp->u_arg[1]);
2052 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002053 }
2054 return 0;
2055}
2056
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002057#ifdef LINUX
2058int
2059sys_fchownat(struct tcb *tcp)
2060{
2061 if (entering(tcp)) {
2062 print_dirfd(tcp->u_arg[0]);
2063 printpath(tcp, tcp->u_arg[1]);
2064 printuid(", ", tcp->u_arg[2]);
2065 printuid(", ", tcp->u_arg[3]);
2066 tprintf(", ");
2067 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
2068 }
2069 return 0;
2070}
2071#endif
2072
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002073int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002074sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002075{
2076 if (entering(tcp)) {
Roland McGrath6bc12202003-11-13 22:32:27 +00002077 tprintf("%ld", tcp->u_arg[0]);
2078 printuid(", ", tcp->u_arg[1]);
2079 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002080 }
2081 return 0;
2082}
2083
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002084static int
2085decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002086{
2087 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002088 printpath(tcp, tcp->u_arg[offset]);
2089 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002090 }
2091 return 0;
2092}
2093
2094int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002095sys_chmod(struct tcb *tcp)
2096{
2097 return decode_chmod(tcp, 0);
2098}
2099
2100#ifdef LINUX
2101int
2102sys_fchmodat(struct tcb *tcp)
2103{
2104 if (entering(tcp))
2105 print_dirfd(tcp->u_arg[0]);
2106 return decode_chmod(tcp, 1);
2107}
2108#endif
2109
2110int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002111sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002112{
2113 if (entering(tcp)) {
2114 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
2115 }
2116 return 0;
2117}
2118
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002119#ifdef ALPHA
2120int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002121sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002122{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002123 if (entering(tcp)) {
2124 printpath(tcp, tcp->u_arg[0]);
2125 tprintf(", ");
2126 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2127 }
2128 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002129}
2130#endif
2131
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002132static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002133decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002134{
2135 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002136 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002137 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002138 if (tcp->u_arg[offset + 1] == 0)
2139 tprintf("NULL");
2140 else {
2141 tprintf("{");
2142 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2143 BITNESS_CURRENT, special);
2144 tprintf(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002145 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Roland McGrath6afc5652007-07-24 01:57:11 +00002146 + sizeof (struct timeval),
2147 BITNESS_CURRENT, special);
2148 tprintf("}");
2149 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002150 }
2151 return 0;
2152}
2153
2154int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002155sys_utimes(struct tcb *tcp)
2156{
Roland McGrath6afc5652007-07-24 01:57:11 +00002157 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002158}
2159
2160#ifdef LINUX
2161int
2162sys_futimesat(struct tcb *tcp)
2163{
2164 if (entering(tcp))
2165 print_dirfd(tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002166 return decode_utimes(tcp, 1, 0);
2167}
2168
2169int
2170sys_utimensat(struct tcb *tcp)
2171{
2172 if (entering(tcp)) {
2173 print_dirfd(tcp->u_arg[0]);
2174 decode_utimes(tcp, 1, 1);
2175 tprintf(", ");
2176 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2177 }
2178 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002179}
2180#endif
2181
2182int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002183sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002184{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002185 union {
2186 long utl[2];
2187 int uti[2];
2188 } u;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002189
2190 if (entering(tcp)) {
2191 printpath(tcp, tcp->u_arg[0]);
2192 tprintf(", ");
2193 if (!tcp->u_arg[1])
2194 tprintf("NULL");
2195 else if (!verbose(tcp))
2196 tprintf("%#lx", tcp->u_arg[1]);
Roland McGrath7e9817c2007-07-05 20:31:58 +00002197 else if (umoven(tcp, tcp->u_arg[1],
2198 2 * personality_wordsize[current_personality],
2199 (char *) &u) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002200 tprintf("[?, ?]");
Roland McGrath7e9817c2007-07-05 20:31:58 +00002201 else if (personality_wordsize[current_personality]
2202 == sizeof u.utl[0]) {
2203 tprintf("[%s,", sprinttime(u.utl[0]));
2204 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002205 }
Roland McGrath7e9817c2007-07-05 20:31:58 +00002206 else if (personality_wordsize[current_personality]
2207 == sizeof u.uti[0]) {
2208 tprintf("[%s,", sprinttime(u.uti[0]));
2209 tprintf(" %s]", sprinttime(u.uti[1]));
2210 }
2211 else
2212 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002213 }
2214 return 0;
2215}
2216
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002217static int
2218decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002219{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002220 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002221
2222 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002223 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002224 tprintf(", %s", sprintmode(mode));
2225 switch (mode & S_IFMT) {
2226 case S_IFCHR: case S_IFBLK:
2227#ifdef LINUXSPARC
2228 if (current_personality == 1)
2229 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002230 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2231 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002232 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002233#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002234 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002235 (unsigned long) major(tcp->u_arg[offset + 2]),
2236 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002237 break;
2238 default:
2239 break;
2240 }
2241 }
2242 return 0;
2243}
2244
2245int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002246sys_mknod(struct tcb *tcp)
2247{
2248 return decode_mknod(tcp, 0);
2249}
2250
2251#ifdef LINUX
2252int
2253sys_mknodat(struct tcb *tcp)
2254{
2255 if (entering(tcp))
2256 print_dirfd(tcp->u_arg[0]);
2257 return decode_mknod(tcp, 1);
2258}
2259#endif
2260
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002261#ifdef FREEBSD
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002262int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002263sys_mkfifo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002264{
2265 if (entering(tcp)) {
2266 printpath(tcp, tcp->u_arg[0]);
2267 tprintf(", %#lo", tcp->u_arg[1]);
2268 }
2269 return 0;
2270}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002271#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002272
2273int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002274sys_fsync(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002275{
2276 if (entering(tcp)) {
2277 tprintf("%ld", tcp->u_arg[0]);
2278 }
2279 return 0;
2280}
2281
Michal Ludvig53b320f2002-09-23 13:30:09 +00002282#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002283
2284static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002285printdir(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002286{
2287 struct dirent d;
2288
2289 if (!verbose(tcp)) {
2290 tprintf("%#lx", addr);
2291 return;
2292 }
2293 if (umove(tcp, addr, &d) < 0) {
2294 tprintf("{...}");
2295 return;
2296 }
2297 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002298 tprintf("d_name=");
2299 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2300 tprintf("}");
2301}
2302
2303int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002304sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002305{
2306 if (entering(tcp)) {
2307 tprintf("%lu, ", tcp->u_arg[0]);
2308 } else {
2309 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2310 tprintf("%#lx", tcp->u_arg[1]);
2311 else
2312 printdir(tcp, tcp->u_arg[1]);
2313 /* Not much point in printing this out, it is always 1. */
2314 if (tcp->u_arg[2] != 1)
2315 tprintf(", %lu", tcp->u_arg[2]);
2316 }
2317 return 0;
2318}
2319
Michal Ludvig53b320f2002-09-23 13:30:09 +00002320#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002321
Roland McGrath40542842004-01-13 09:47:49 +00002322#if defined FREEBSD || defined LINUX
Roland McGratha4d48532005-06-08 20:45:28 +00002323static const struct xlat direnttypes[] = {
Roland McGrath40542842004-01-13 09:47:49 +00002324 { DT_UNKNOWN, "DT_UNKNOWN" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002325 { DT_FIFO, "DT_FIFO" },
2326 { DT_CHR, "DT_CHR" },
2327 { DT_DIR, "DT_DIR" },
2328 { DT_BLK, "DT_BLK" },
2329 { DT_REG, "DT_REG" },
2330 { DT_LNK, "DT_LNK" },
2331 { DT_SOCK, "DT_SOCK" },
2332 { DT_WHT, "DT_WHT" },
2333 { 0, NULL },
2334};
2335
2336#endif
2337
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002338int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002339sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002340{
2341 int i, len, dents = 0;
2342 char *buf;
2343
2344 if (entering(tcp)) {
2345 tprintf("%lu, ", tcp->u_arg[0]);
2346 return 0;
2347 }
2348 if (syserror(tcp) || !verbose(tcp)) {
2349 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2350 return 0;
2351 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002352 len = tcp->u_rval;
2353 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002354 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2355 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002356 return 0;
2357 }
2358 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002359 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002360 free(buf);
2361 return 0;
2362 }
2363 if (!abbrev(tcp))
2364 tprintf("{");
2365 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002366 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002367#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002368 if (!abbrev(tcp)) {
2369 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2370 i ? " " : "", d->d_ino, d->d_off);
2371 tprintf("d_reclen=%u, d_name=\"%s\"}",
2372 d->d_reclen, d->d_name);
2373 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002374#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002375#ifdef SVR4
2376 if (!abbrev(tcp)) {
2377 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002378 i ? " " : "",
2379 (unsigned long) d->d_ino,
2380 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002381 tprintf("d_reclen=%u, d_name=\"%s\"}",
2382 d->d_reclen, d->d_name);
2383 }
2384#endif /* SVR4 */
2385#ifdef SUNOS4
2386 if (!abbrev(tcp)) {
2387 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2388 i ? " " : "", d->d_off, d->d_fileno,
2389 d->d_reclen);
2390 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2391 d->d_namlen, d->d_namlen, d->d_name);
2392 }
2393#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002394#ifdef FREEBSD
2395 if (!abbrev(tcp)) {
2396 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2397 i ? " " : "", d->d_fileno, d->d_reclen);
2398 printxval(direnttypes, d->d_type, "DT_???");
2399 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2400 d->d_namlen, d->d_namlen, d->d_name);
2401 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002402#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002403 if (!d->d_reclen) {
2404 tprintf("/* d_reclen == 0, problem here */");
2405 break;
2406 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002407 i += d->d_reclen;
2408 dents++;
2409 }
2410 if (!abbrev(tcp))
2411 tprintf("}");
2412 else
2413 tprintf("/* %u entries */", dents);
2414 tprintf(", %lu", tcp->u_arg[2]);
2415 free(buf);
2416 return 0;
2417}
2418
John Hughesbdf48f52001-03-06 15:08:09 +00002419
2420#if _LFS64_LARGEFILE
2421int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002422sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002423{
2424 int i, len, dents = 0;
2425 char *buf;
2426
2427 if (entering(tcp)) {
2428 tprintf("%lu, ", tcp->u_arg[0]);
2429 return 0;
2430 }
2431 if (syserror(tcp) || !verbose(tcp)) {
2432 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2433 return 0;
2434 }
2435 len = tcp->u_rval;
2436 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002437 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2438 fprintf(stderr, "out of memory\n");
John Hughesbdf48f52001-03-06 15:08:09 +00002439 return 0;
2440 }
2441 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002442 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002443 free(buf);
2444 return 0;
2445 }
2446 if (!abbrev(tcp))
2447 tprintf("{");
2448 for (i = 0; i < len;) {
2449 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002450#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002451 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002452 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002453 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002454 d->d_ino,
2455 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002456#ifdef LINUX
2457 tprintf("d_type=");
2458 printxval(direnttypes, d->d_type, "DT_???");
2459 tprintf(", ");
2460#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002461 tprintf("d_reclen=%u, d_name=\"%s\"}",
2462 d->d_reclen, d->d_name);
2463 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002464#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002465#ifdef SUNOS4
2466 if (!abbrev(tcp)) {
2467 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2468 i ? " " : "", d->d_off, d->d_fileno,
2469 d->d_reclen);
2470 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2471 d->d_namlen, d->d_namlen, d->d_name);
2472 }
2473#endif /* SUNOS4 */
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002474 if (!d->d_reclen) {
2475 tprintf("/* d_reclen == 0, problem here */");
2476 break;
2477 }
John Hughesbdf48f52001-03-06 15:08:09 +00002478 i += d->d_reclen;
2479 dents++;
2480 }
2481 if (!abbrev(tcp))
2482 tprintf("}");
2483 else
2484 tprintf("/* %u entries */", dents);
2485 tprintf(", %lu", tcp->u_arg[2]);
2486 free(buf);
2487 return 0;
2488}
2489#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002490
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002491#ifdef FREEBSD
2492int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002493sys_getdirentries(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002494{
2495 int i, len, dents = 0;
2496 long basep;
2497 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002498
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002499 if (entering(tcp)) {
2500 tprintf("%lu, ", tcp->u_arg[0]);
2501 return 0;
2502 }
2503 if (syserror(tcp) || !verbose(tcp)) {
2504 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2505 return 0;
2506 }
2507 len = tcp->u_rval;
2508 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002509 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2510 fprintf(stderr, "out of memory\n");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002511 return 0;
2512 }
2513 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002514 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002515 free(buf);
2516 return 0;
2517 }
2518 if (!abbrev(tcp))
2519 tprintf("{");
2520 for (i = 0; i < len;) {
2521 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2522 if (!abbrev(tcp)) {
2523 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2524 i ? " " : "", d->d_fileno, d->d_reclen);
2525 printxval(direnttypes, d->d_type, "DT_???");
2526 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2527 d->d_namlen, d->d_namlen, d->d_name);
2528 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002529 if (!d->d_reclen) {
2530 tprintf("/* d_reclen == 0, problem here */");
2531 break;
2532 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002533 i += d->d_reclen;
2534 dents++;
2535 }
2536 if (!abbrev(tcp))
2537 tprintf("}");
2538 else
2539 tprintf("/* %u entries */", dents);
2540 free(buf);
2541 tprintf(", %lu", tcp->u_arg[2]);
2542 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2543 tprintf(", %#lx", tcp->u_arg[3]);
2544 else
2545 tprintf(", [%lu]", basep);
2546 return 0;
2547}
2548#endif
2549
Michal Ludvig53b320f2002-09-23 13:30:09 +00002550#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002551int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002552sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002553{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002554 if (exiting(tcp)) {
2555 if (syserror(tcp))
2556 tprintf("%#lx", tcp->u_arg[0]);
2557 else
2558 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2559 tprintf(", %lu", tcp->u_arg[1]);
2560 }
2561 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002562}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002563#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002564
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002565#ifdef FREEBSD
2566int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002567sys___getcwd(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002568{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002569 if (exiting(tcp)) {
2570 if (syserror(tcp))
2571 tprintf("%#lx", tcp->u_arg[0]);
2572 else
2573 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2574 tprintf(", %lu", tcp->u_arg[1]);
2575 }
2576 return 0;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002577}
2578#endif
2579
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002580#ifdef HAVE_SYS_ASYNCH_H
2581
2582int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002583sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002584{
2585 struct aio_result_t res;
2586
2587 if (entering(tcp)) {
2588 tprintf("%lu, ", tcp->u_arg[0]);
2589 } else {
2590 if (syserror(tcp))
2591 tprintf("%#lx", tcp->u_arg[1]);
2592 else
2593 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2594 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2595 printxval(whence, tcp->u_arg[4], "L_???");
2596 if (syserror(tcp) || tcp->u_arg[5] == 0
2597 || umove(tcp, tcp->u_arg[5], &res) < 0)
2598 tprintf(", %#lx", tcp->u_arg[5]);
2599 else
2600 tprintf(", {aio_return %d aio_errno %d}",
2601 res.aio_return, res.aio_errno);
2602 }
2603 return 0;
2604}
2605
2606int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002607sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002608{
2609 struct aio_result_t res;
2610
2611 if (entering(tcp)) {
2612 tprintf("%lu, ", tcp->u_arg[0]);
2613 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2614 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2615 printxval(whence, tcp->u_arg[4], "L_???");
2616 }
2617 else {
2618 if (tcp->u_arg[5] == 0)
2619 tprintf(", NULL");
2620 else if (syserror(tcp)
2621 || umove(tcp, tcp->u_arg[5], &res) < 0)
2622 tprintf(", %#lx", tcp->u_arg[5]);
2623 else
2624 tprintf(", {aio_return %d aio_errno %d}",
2625 res.aio_return, res.aio_errno);
2626 }
2627 return 0;
2628}
2629
2630int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002631sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002632{
2633 if (entering(tcp))
2634 printtv(tcp, tcp->u_arg[0]);
2635 return 0;
2636}
2637
2638int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002639sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002640{
2641 struct aio_result_t res;
2642
2643 if (exiting(tcp)) {
2644 if (tcp->u_arg[0] == 0)
2645 tprintf("NULL");
2646 else if (syserror(tcp)
2647 || umove(tcp, tcp->u_arg[0], &res) < 0)
2648 tprintf("%#lx", tcp->u_arg[0]);
2649 else
2650 tprintf("{aio_return %d aio_errno %d}",
2651 res.aio_return, res.aio_errno);
2652 }
2653 return 0;
2654}
2655
2656#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002657
Roland McGratha4d48532005-06-08 20:45:28 +00002658static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002659#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002660 { XATTR_CREATE, "XATTR_CREATE" },
2661 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002662#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002663 { 0, NULL }
2664};
2665
Roland McGrath3292e222004-08-31 06:30:48 +00002666static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002667print_xattr_val(struct tcb *tcp, int failed,
2668 unsigned long arg,
2669 unsigned long insize,
2670 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002671{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002672 if (!failed) {
2673 unsigned long capacity = 4 * size + 1;
2674 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2675 if (buf == NULL || /* probably a bogus size argument */
2676 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2677 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002678 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002679 else {
2680 unsigned char *out = buf;
2681 unsigned char *in = &buf[3 * size];
2682 size_t i;
2683 for (i = 0; i < size; ++i) {
2684 if (isprint(in[i]))
2685 *out++ = in[i];
2686 else {
2687#define tohex(n) "0123456789abcdef"[n]
2688 *out++ = '\\';
2689 *out++ = 'x';
2690 *out++ = tohex(in[i] / 16);
2691 *out++ = tohex(in[i] % 16);
2692 }
2693 }
2694 /* Don't print terminating NUL if there is one. */
2695 if (i > 0 && in[i - 1] == '\0')
2696 out -= 4;
2697 *out = '\0';
2698 tprintf(", \"%s\", %ld", buf, insize);
2699 }
2700 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002701 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002702 if (failed)
2703 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002704}
2705
Roland McGrath186c5ac2002-12-15 23:58:23 +00002706int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002707sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002708{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002709 if (entering(tcp)) {
2710 printpath(tcp, tcp->u_arg[0]);
2711 tprintf(", ");
2712 printstr(tcp, tcp->u_arg[1], -1);
2713 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2714 tprintf(", ");
2715 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2716 }
2717 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002718}
2719
2720int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002721sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002722{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002723 if (entering(tcp)) {
2724 tprintf("%ld, ", tcp->u_arg[0]);
2725 printstr(tcp, tcp->u_arg[1], -1);
2726 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2727 tprintf(", ");
2728 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2729 }
2730 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002731}
2732
2733int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002734sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002735{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002736 if (entering(tcp)) {
2737 printpath(tcp, tcp->u_arg[0]);
2738 tprintf(", ");
2739 printstr(tcp, tcp->u_arg[1], -1);
2740 } else {
2741 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2742 tcp->u_rval);
2743 }
2744 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002745}
2746
2747int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002748sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002749{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002750 if (entering(tcp)) {
2751 tprintf("%ld, ", tcp->u_arg[0]);
2752 printstr(tcp, tcp->u_arg[1], -1);
2753 } else {
2754 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2755 tcp->u_rval);
2756 }
2757 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002758}
2759
2760int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002761sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002762{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002763 if (entering(tcp)) {
2764 printpath(tcp, tcp->u_arg[0]);
2765 } else {
2766 /* XXX Print value in format */
2767 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2768 }
2769 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002770}
2771
2772int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002773sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002774{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002775 if (entering(tcp)) {
2776 tprintf("%ld", tcp->u_arg[0]);
2777 } else {
2778 /* XXX Print value in format */
2779 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2780 }
2781 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002782}
2783
2784int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002785sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002786{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002787 if (entering(tcp)) {
2788 printpath(tcp, tcp->u_arg[0]);
2789 tprintf(", ");
2790 printstr(tcp, tcp->u_arg[1], -1);
2791 }
2792 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002793}
2794
2795int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002796sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002797{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002798 if (entering(tcp)) {
2799 tprintf("%ld, ", tcp->u_arg[0]);
2800 printstr(tcp, tcp->u_arg[1], -1);
2801 }
2802 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002803}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002804
2805
2806static const struct xlat advise[] = {
2807 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2808 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2809 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2810 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2811 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2812 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2813 { 0, NULL }
2814};
2815
2816
Roland McGrathe27ed342004-10-20 02:24:19 +00002817#ifdef LINUX
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002818int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002819sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002820{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002821 if (entering(tcp)) {
2822 tprintf("%ld, %lld, %ld, ",
2823 tcp->u_arg[0],
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002824# if defined IA64 || defined X86_64 || defined ALPHA
Denys Vlasenko1d632462009-04-14 12:51:00 +00002825 (long long int) tcp->u_arg[1], tcp->u_arg[2]);
2826 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002827#else
Denys Vlasenko1d632462009-04-14 12:51:00 +00002828 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
2829 printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002830#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002831 }
2832 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002833}
2834#endif
2835
2836
2837int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002838sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002839{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002840 if (entering(tcp)) {
2841 tprintf("%ld, %lld, %lld, ",
2842 tcp->u_arg[0],
Roland McGrath542c2c62008-05-20 01:11:56 +00002843#if defined LINUX_MIPSN32
Denys Vlasenko1d632462009-04-14 12:51:00 +00002844 tcp->ext_arg[1], tcp->ext_arg[2]);
2845 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
Roland McGrath542c2c62008-05-20 01:11:56 +00002846#elif defined IA64 || defined X86_64 || defined ALPHA || defined LINUX_MIPSN64
Denys Vlasenko1d632462009-04-14 12:51:00 +00002847 (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
2848 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002849#else
Denys Vlasenko1d632462009-04-14 12:51:00 +00002850 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
2851 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
2852 printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002853#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002854 }
2855 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002856}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002857
2858#ifdef LINUX
2859static const struct xlat inotify_modes[] = {
2860 { 0x00000001, "IN_ACCESS" },
2861 { 0x00000002, "IN_MODIFY" },
2862 { 0x00000004, "IN_ATTRIB" },
2863 { 0x00000008, "IN_CLOSE_WRITE" },
2864 { 0x00000010, "IN_CLOSE_NOWRITE" },
2865 { 0x00000020, "IN_OPEN" },
2866 { 0x00000040, "IN_MOVED_FROM" },
2867 { 0x00000080, "IN_MOVED_TO" },
2868 { 0x00000100, "IN_CREATE" },
2869 { 0x00000200, "IN_DELETE" },
2870 { 0x00000400, "IN_DELETE_SELF" },
2871 { 0x00000800, "IN_MOVE_SELF" },
2872 { 0x00002000, "IN_UNMOUNT" },
2873 { 0x00004000, "IN_Q_OVERFLOW" },
2874 { 0x00008000, "IN_IGNORED" },
2875 { 0x01000000, "IN_ONLYDIR" },
2876 { 0x02000000, "IN_DONT_FOLLOW" },
2877 { 0x20000000, "IN_MASK_ADD" },
2878 { 0x40000000, "IN_ISDIR" },
2879 { 0x80000000, "IN_ONESHOT" }
2880};
2881
2882int
2883sys_inotify_add_watch(struct tcb *tcp)
2884{
2885 if (entering(tcp)) {
2886 tprintf("%ld, ", tcp->u_arg[0]);
2887 printpath(tcp, tcp->u_arg[1]);
2888 tprintf(", ");
2889 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2890 }
2891 return 0;
2892}
2893
2894int
2895sys_inotify_rm_watch(struct tcb *tcp)
2896{
2897 if (entering(tcp)) {
2898 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
2899 }
2900 return 0;
2901}
Roland McGrath96a96612008-05-20 04:56:18 +00002902
2903int
2904sys_fallocate(struct tcb *tcp)
2905{
2906 if (entering(tcp)) {
2907 tprintf("%ld, ", tcp->u_arg[0]); /* fd */
2908 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
2909 tprintf("%llu, ", LONG_LONG(tcp->u_arg[2],
2910 tcp->u_arg[3])); /* offset */
2911 tprintf("%llu", LONG_LONG(tcp->u_arg[4],
2912 tcp->u_arg[5])); /* len */
2913 }
2914 return 0;
2915}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002916#endif