blob: 53c2489515047e2429b41f2bb1f0a31f0b902a90 [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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000782 if (umove(tcp, addr, &statbuf) < 0) {
783 tprintf("{...}");
784 return;
785 }
786 if (!abbrev(tcp)) {
787 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
788 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
789 (unsigned long) (statbuf.st_dev & 0x3ffff),
790 (unsigned long) statbuf.st_ino,
791 sprintmode(statbuf.st_mode));
792 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
793 (unsigned long) statbuf.st_nlink,
794 (unsigned long) statbuf.st_uid,
795 (unsigned long) statbuf.st_gid);
796 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
797 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
798 }
799 else
800 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
801 switch (statbuf.st_mode & S_IFMT) {
802 case S_IFCHR: case S_IFBLK:
803 tprintf("st_rdev=makedev(%lu, %lu), ",
804 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
805 (unsigned long) (statbuf.st_rdev & 0x3ffff));
806 break;
807 default:
808 tprintf("st_size=%u, ", statbuf.st_size);
809 break;
810 }
811 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000812 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
813 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
814 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000815 }
816 else
817 tprintf("...}");
818}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000819
820#if defined (SPARC64)
821static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000822printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000823{
824 struct stat_sparc64 statbuf;
825
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000826 if (umove(tcp, addr, &statbuf) < 0) {
827 tprintf("{...}");
828 return;
829 }
830
831 if (!abbrev(tcp)) {
832 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
833 (unsigned long) major(statbuf.st_dev),
834 (unsigned long) minor(statbuf.st_dev),
835 (unsigned long) statbuf.st_ino,
836 sprintmode(statbuf.st_mode));
837 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
838 (unsigned long) statbuf.st_nlink,
839 (unsigned long) statbuf.st_uid,
840 (unsigned long) statbuf.st_gid);
841 tprintf("st_blksize=%lu, ",
842 (unsigned long) statbuf.st_blksize);
843 tprintf("st_blocks=%lu, ",
844 (unsigned long) statbuf.st_blocks);
845 }
846 else
847 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
848 switch (statbuf.st_mode & S_IFMT) {
849 case S_IFCHR: case S_IFBLK:
850 tprintf("st_rdev=makedev(%lu, %lu), ",
851 (unsigned long) major(statbuf.st_rdev),
852 (unsigned long) minor(statbuf.st_rdev));
853 break;
854 default:
855 tprintf("st_size=%lu, ", statbuf.st_size);
856 break;
857 }
858 if (!abbrev(tcp)) {
859 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
860 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
861 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
862 tprintf("}");
863 }
864 else
865 tprintf("...}");
866}
867#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000868#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000869
Roland McGratha4d48532005-06-08 20:45:28 +0000870static const struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000871#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000872 { UF_NODUMP, "UF_NODUMP" },
873 { UF_IMMUTABLE, "UF_IMMUTABLE" },
874 { UF_APPEND, "UF_APPEND" },
875 { UF_OPAQUE, "UF_OPAQUE" },
876 { UF_NOUNLINK, "UF_NOUNLINK" },
877 { SF_ARCHIVED, "SF_ARCHIVED" },
878 { SF_IMMUTABLE, "SF_IMMUTABLE" },
879 { SF_APPEND, "SF_APPEND" },
880 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000881#elif UNIXWARE >= 2
882#ifdef _S_ISMLD
883 { _S_ISMLD, "_S_ISMLD" },
884#endif
885#ifdef _S_ISMOUNTED
886 { _S_ISMOUNTED, "_S_ISMOUNTED" },
887#endif
888#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000889 { 0, NULL },
890};
891
John Hughesc0fc3fd2001-03-08 16:10:40 +0000892#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000893int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000894sys_chflags(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000895{
896 if (entering(tcp)) {
897 printpath(tcp, tcp->u_arg[0]);
898 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000899 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000900 }
901 return 0;
902}
903
904int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000905sys_fchflags(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000906{
907 if (entering(tcp)) {
908 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000909 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000910 }
911 return 0;
912}
913#endif
914
John Hughes70623be2001-03-08 13:59:00 +0000915#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000916static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000917realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000918{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000919 if (!abbrev(tcp)) {
920 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
921 (unsigned long) major(statbuf->st_dev),
922 (unsigned long) minor(statbuf->st_dev),
923 (unsigned long) statbuf->st_ino,
924 sprintmode(statbuf->st_mode));
925 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
926 (unsigned long) statbuf->st_nlink,
927 (unsigned long) statbuf->st_uid,
928 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000929#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000930 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
931#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000932#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000933 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
934#endif
935 }
936 else
937 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
938 switch (statbuf->st_mode & S_IFMT) {
939 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000940#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000941 tprintf("st_rdev=makedev(%lu, %lu), ",
942 (unsigned long) major(statbuf->st_rdev),
943 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000944#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000945 tprintf("st_size=makedev(%lu, %lu), ",
946 (unsigned long) major(statbuf->st_size),
947 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000948#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000949 break;
950 default:
951 tprintf("st_size=%lu, ", statbuf->st_size);
952 break;
953 }
954 if (!abbrev(tcp)) {
955 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
956 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
957 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000958#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000959 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000960 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000961#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000962#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000963 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
964#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000965#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000966 tprintf(", st_level=%ld", statbuf->st_level);
967#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000968#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000969 tprintf(", st_fstype=%.*s",
970 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
971#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000972#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000973 tprintf(", st_gen=%u", statbuf->st_gen);
974#endif
975 tprintf("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000976 }
977 else
978 tprintf("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000979}
980
Nate Sammons771a6ff1999-04-05 22:39:31 +0000981
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000982static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000983printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000984{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000985 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000986
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000987 if (!addr) {
988 tprintf("NULL");
989 return;
990 }
991 if (syserror(tcp) || !verbose(tcp)) {
992 tprintf("%#lx", addr);
993 return;
994 }
995
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000996#ifdef LINUXSPARC
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000997 if (current_personality == 1) {
998 printstatsol(tcp, addr);
999 return;
1000 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001001#ifdef SPARC64
1002 else if (current_personality == 2) {
1003 printstat_sparc64(tcp, addr);
1004 return;
1005 }
1006#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001007#endif /* LINUXSPARC */
1008
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001009 if (umove(tcp, addr, &statbuf) < 0) {
1010 tprintf("{...}");
1011 return;
1012 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001013
1014 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001015}
John Hughes70623be2001-03-08 13:59:00 +00001016#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001017
Roland McGrathe6d0f712007-08-07 01:22:49 +00001018#if !defined HAVE_STAT64 && defined LINUX && defined X86_64
1019/*
1020 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1021 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1022 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1023 * __GNUC__ is needed for the required __attribute__ below.
1024 */
1025struct stat64 {
1026 unsigned long long st_dev;
1027 unsigned char __pad0[4];
1028 unsigned int __st_ino;
1029 unsigned int st_mode;
1030 unsigned int st_nlink;
1031 unsigned int st_uid;
1032 unsigned int st_gid;
1033 unsigned long long st_rdev;
1034 unsigned char __pad3[4];
1035 long long st_size;
1036 unsigned int st_blksize;
1037 unsigned long long st_blocks;
1038 unsigned int st_atime;
1039 unsigned int st_atime_nsec;
1040 unsigned int st_mtime;
1041 unsigned int st_mtime_nsec;
1042 unsigned int st_ctime;
1043 unsigned int st_ctime_nsec;
1044 unsigned long long st_ino;
1045} __attribute__((packed));
1046# define HAVE_STAT64 1
1047# define STAT64_SIZE 96
1048#endif
1049
Wichert Akkermanc7926982000-04-10 22:22:31 +00001050#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001051static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001052printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001053{
1054 struct stat64 statbuf;
1055
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001056#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001057 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1058#endif
1059
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001060 if (!addr) {
1061 tprintf("NULL");
1062 return;
1063 }
1064 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001065 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001066 return;
1067 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001068
1069#ifdef LINUXSPARC
1070 if (current_personality == 1) {
1071 printstatsol(tcp, addr);
1072 return;
1073 }
1074# ifdef SPARC64
1075 else if (current_personality == 2) {
1076 printstat_sparc64(tcp, addr);
1077 return;
1078 }
1079# endif
1080#endif /* LINUXSPARC */
1081
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001082 if (umove(tcp, addr, &statbuf) < 0) {
1083 tprintf("{...}");
1084 return;
1085 }
1086
1087 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001088#ifdef HAVE_LONG_LONG
1089 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1090#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001091 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001092#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001093 (unsigned long) major(statbuf.st_dev),
1094 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001095#ifdef HAVE_LONG_LONG
1096 (unsigned long long) statbuf.st_ino,
1097#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001098 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001099#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001100 sprintmode(statbuf.st_mode));
1101 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1102 (unsigned long) statbuf.st_nlink,
1103 (unsigned long) statbuf.st_uid,
1104 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001105#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001106 tprintf("st_blksize=%lu, ",
1107 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001108#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1109#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001110 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001111#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001112 }
1113 else
1114 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1115 switch (statbuf.st_mode & S_IFMT) {
1116 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001117#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001118 tprintf("st_rdev=makedev(%lu, %lu), ",
1119 (unsigned long) major(statbuf.st_rdev),
1120 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001121#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001122 tprintf("st_size=makedev(%lu, %lu), ",
1123 (unsigned long) major(statbuf.st_size),
1124 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001125#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001126 break;
1127 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001128#ifdef HAVE_LONG_LONG
1129 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1130#else
1131 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1132#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001133 break;
1134 }
1135 if (!abbrev(tcp)) {
1136 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1137 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001138 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001139#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +00001140 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001141 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001142#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001143#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001144 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1145#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001146#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001147 tprintf(", st_level=%ld", statbuf.st_level);
1148#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001149#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001150 tprintf(", st_fstype=%.*s",
1151 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1152#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001153#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001154 tprintf(", st_gen=%u", statbuf.st_gen);
1155#endif
1156 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001157 }
1158 else
1159 tprintf("...}");
1160}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001161#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001162
Roland McGrath79db8af2003-06-27 21:20:09 +00001163#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001164static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001165convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001166{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001167 newbuf->st_dev = oldbuf->st_dev;
1168 newbuf->st_ino = oldbuf->st_ino;
1169 newbuf->st_mode = oldbuf->st_mode;
1170 newbuf->st_nlink = oldbuf->st_nlink;
1171 newbuf->st_uid = oldbuf->st_uid;
1172 newbuf->st_gid = oldbuf->st_gid;
1173 newbuf->st_rdev = oldbuf->st_rdev;
1174 newbuf->st_size = oldbuf->st_size;
1175 newbuf->st_atime = oldbuf->st_atime;
1176 newbuf->st_mtime = oldbuf->st_mtime;
1177 newbuf->st_ctime = oldbuf->st_ctime;
1178 newbuf->st_blksize = 0; /* not supported in old_stat */
1179 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001180}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001181
1182
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001183static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001184printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001185{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001186 struct __old_kernel_stat statbuf;
1187 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001188
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001189 if (!addr) {
1190 tprintf("NULL");
1191 return;
1192 }
1193 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001194 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001195 return;
1196 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001197
1198#ifdef LINUXSPARC
1199 if (current_personality == 1) {
1200 printstatsol(tcp, addr);
1201 return;
1202 }
1203#endif /* LINUXSPARC */
1204
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001205 if (umove(tcp, addr, &statbuf) < 0) {
1206 tprintf("{...}");
1207 return;
1208 }
1209
1210 convertoldstat(&statbuf, &newstatbuf);
1211 realprintstat(tcp, &newstatbuf);
1212}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001213#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001214
John Hughes70623be2001-03-08 13:59:00 +00001215#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001216int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001217sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001218{
1219 if (entering(tcp)) {
1220 printpath(tcp, tcp->u_arg[0]);
1221 tprintf(", ");
1222 } else {
1223 printstat(tcp, tcp->u_arg[1]);
1224 }
1225 return 0;
1226}
John Hughesb8c9f772001-03-07 16:53:07 +00001227#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001228
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001229int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001230sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001231{
1232#ifdef HAVE_STAT64
1233 if (entering(tcp)) {
1234 printpath(tcp, tcp->u_arg[0]);
1235 tprintf(", ");
1236 } else {
1237 printstat64(tcp, tcp->u_arg[1]);
1238 }
1239 return 0;
1240#else
1241 return printargs(tcp);
1242#endif
1243}
1244
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001245#ifdef LINUX
1246static const struct xlat fstatatflags[] = {
1247#ifndef AT_SYMLINK_NOFOLLOW
1248# define AT_SYMLINK_NOFOLLOW 0x100
1249#endif
1250 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1251 { 0, NULL },
1252};
Roland McGrath6afc5652007-07-24 01:57:11 +00001253#define utimensatflags fstatatflags
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001254
1255int
1256sys_newfstatat(struct tcb *tcp)
1257{
1258 if (entering(tcp)) {
1259 print_dirfd(tcp->u_arg[0]);
1260 printpath(tcp, tcp->u_arg[1]);
1261 tprintf(", ");
1262 } else {
Roland McGrath359c8ed2007-07-05 19:01:17 +00001263#if defined HAVE_STAT64 && !(defined POWERPC && defined __powerpc64__)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001264 printstat64(tcp, tcp->u_arg[2]);
1265#else
1266 printstat(tcp, tcp->u_arg[2]);
1267#endif
1268 tprintf(", ");
1269 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1270 }
1271 return 0;
1272}
1273#endif
1274
Roland McGrath79db8af2003-06-27 21:20:09 +00001275#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001276int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001277sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001278{
1279 if (entering(tcp)) {
1280 printpath(tcp, tcp->u_arg[0]);
1281 tprintf(", ");
1282 } else {
1283 printoldstat(tcp, tcp->u_arg[1]);
1284 }
1285 return 0;
1286}
Roland McGrath79db8af2003-06-27 21:20:09 +00001287#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001288
John Hughes70623be2001-03-08 13:59:00 +00001289#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001290int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001291sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292{
1293 if (entering(tcp))
1294 tprintf("%ld, ", tcp->u_arg[0]);
1295 else {
1296 printstat(tcp, tcp->u_arg[1]);
1297 }
1298 return 0;
1299}
John Hughesb8c9f772001-03-07 16:53:07 +00001300#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001301
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001302int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001303sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001304{
1305#ifdef HAVE_STAT64
1306 if (entering(tcp))
1307 tprintf("%ld, ", tcp->u_arg[0]);
1308 else {
1309 printstat64(tcp, tcp->u_arg[1]);
1310 }
1311 return 0;
1312#else
1313 return printargs(tcp);
1314#endif
1315}
1316
Roland McGrath79db8af2003-06-27 21:20:09 +00001317#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001318int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001319sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001320{
1321 if (entering(tcp))
1322 tprintf("%ld, ", tcp->u_arg[0]);
1323 else {
1324 printoldstat(tcp, tcp->u_arg[1]);
1325 }
1326 return 0;
1327}
Roland McGrath79db8af2003-06-27 21:20:09 +00001328#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001329
John Hughes70623be2001-03-08 13:59:00 +00001330#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001331int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001332sys_lstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001333{
1334 if (entering(tcp)) {
1335 printpath(tcp, tcp->u_arg[0]);
1336 tprintf(", ");
1337 } else {
1338 printstat(tcp, tcp->u_arg[1]);
1339 }
1340 return 0;
1341}
John Hughesb8c9f772001-03-07 16:53:07 +00001342#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001343
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001344int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001345sys_lstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001346{
1347#ifdef HAVE_STAT64
1348 if (entering(tcp)) {
1349 printpath(tcp, tcp->u_arg[0]);
1350 tprintf(", ");
1351 } else {
1352 printstat64(tcp, tcp->u_arg[1]);
1353 }
1354 return 0;
1355#else
1356 return printargs(tcp);
1357#endif
1358}
1359
Roland McGrath79db8af2003-06-27 21:20:09 +00001360#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001361int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001362sys_oldlstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001363{
1364 if (entering(tcp)) {
1365 printpath(tcp, tcp->u_arg[0]);
1366 tprintf(", ");
1367 } else {
1368 printoldstat(tcp, tcp->u_arg[1]);
1369 }
1370 return 0;
1371}
Roland McGrath79db8af2003-06-27 21:20:09 +00001372#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001373
1374
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001375#if defined(SVR4) || defined(LINUXSPARC)
1376
1377int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001378sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001379{
1380 if (entering(tcp)) {
1381 tprintf("%ld, ", tcp->u_arg[0]);
1382 printpath(tcp, tcp->u_arg[1]);
1383 tprintf(", ");
1384 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001385#ifdef _STAT64_VER
1386 if (tcp->u_arg[0] == _STAT64_VER)
1387 printstat64 (tcp, tcp->u_arg[2]);
1388 else
1389#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001390 printstat(tcp, tcp->u_arg[2]);
1391 }
1392 return 0;
1393}
1394
1395int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001396sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001397{
1398 if (entering(tcp))
1399 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1400 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001401#ifdef _STAT64_VER
1402 if (tcp->u_arg[0] == _STAT64_VER)
1403 printstat64 (tcp, tcp->u_arg[2]);
1404 else
1405#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001406 printstat(tcp, tcp->u_arg[2]);
1407 }
1408 return 0;
1409}
1410
1411int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001412sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413{
1414 if (entering(tcp)) {
1415 tprintf("%ld, ", tcp->u_arg[0]);
1416 printpath(tcp, tcp->u_arg[1]);
1417 tprintf(", ");
1418 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001419#ifdef _STAT64_VER
1420 if (tcp->u_arg[0] == _STAT64_VER)
1421 printstat64 (tcp, tcp->u_arg[2]);
1422 else
1423#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001424 printstat(tcp, tcp->u_arg[2]);
1425 }
1426 return 0;
1427}
1428
1429int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001430sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001431{
1432 int mode = tcp->u_arg[2];
1433
1434 if (entering(tcp)) {
1435 tprintf("%ld, ", tcp->u_arg[0]);
1436 printpath(tcp, tcp->u_arg[1]);
1437 tprintf(", %s", sprintmode(mode));
1438 switch (mode & S_IFMT) {
1439 case S_IFCHR: case S_IFBLK:
1440#ifdef LINUXSPARC
1441 tprintf(", makedev(%lu, %lu)",
1442 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1443 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001444#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001445 tprintf(", makedev(%lu, %lu)",
1446 (unsigned long) major(tcp->u_arg[3]),
1447 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001448#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001449 break;
1450 default:
1451 break;
1452 }
1453 }
1454 return 0;
1455}
1456
Wichert Akkerman8829a551999-06-11 13:18:40 +00001457#ifdef HAVE_SYS_ACL_H
1458
1459#include <sys/acl.h>
1460
Roland McGratha4d48532005-06-08 20:45:28 +00001461static const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001462#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001463 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001464#endif
1465#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001466 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001467#endif
1468#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001469 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001470#endif
1471#ifdef ACL_GET
1472 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001473#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001474#ifdef ACL_SET
1475 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001476#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001477#ifdef ACL_CNT
1478 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001479#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001480 { 0, NULL },
1481};
1482
1483int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001484sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001485{
1486 if (entering(tcp)) {
1487 printpath(tcp, tcp->u_arg[0]);
1488 tprintf(", ");
1489 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1490 tprintf(", %ld", tcp->u_arg[2]);
1491 /*
1492 * FIXME - dump out the list of aclent_t's pointed to
1493 * by "tcp->u_arg[3]" if it's not NULL.
1494 */
1495 if (tcp->u_arg[3])
1496 tprintf(", %#lx", tcp->u_arg[3]);
1497 else
1498 tprintf(", NULL");
1499 }
1500 return 0;
1501}
1502
1503
1504int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001505sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001506{
1507 if (entering(tcp)) {
1508 tprintf("%ld, ", tcp->u_arg[0]);
1509 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1510 tprintf(", %ld", tcp->u_arg[2]);
1511 /*
1512 * FIXME - dump out the list of aclent_t's pointed to
1513 * by "tcp->u_arg[3]" if it's not NULL.
1514 */
1515 if (tcp->u_arg[3])
1516 tprintf(", %#lx", tcp->u_arg[3]);
1517 else
1518 tprintf(", NULL");
1519 }
1520 return 0;
1521}
1522
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001523
Roland McGratha4d48532005-06-08 20:45:28 +00001524static const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001525#ifdef IPC_SHM
1526 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001527#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001528#ifdef IPC_SEM
1529 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001530#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001531#ifdef IPC_MSG
1532 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001533#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001534 { 0, NULL },
1535};
1536
1537
1538int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001539sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001540{
1541 if (entering(tcp)) {
1542 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1543 tprintf(", %#lx, ", tcp->u_arg[1]);
1544 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1545 tprintf(", %ld", tcp->u_arg[3]);
1546 /*
1547 * FIXME - dump out the list of aclent_t's pointed to
1548 * by "tcp->u_arg[4]" if it's not NULL.
1549 */
1550 if (tcp->u_arg[4])
1551 tprintf(", %#lx", tcp->u_arg[4]);
1552 else
1553 tprintf(", NULL");
1554 }
1555 return 0;
1556}
1557
Wichert Akkerman8829a551999-06-11 13:18:40 +00001558#endif /* HAVE_SYS_ACL_H */
1559
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001560#endif /* SVR4 || LINUXSPARC */
1561
Michal Ludvig53b320f2002-09-23 13:30:09 +00001562#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001563
Roland McGrathd9f816f2004-09-04 03:39:20 +00001564static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001565 { 0x73757245, "CODA_SUPER_MAGIC" },
1566 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1567 { 0x1373, "DEVFS_SUPER_MAGIC" },
1568 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1569 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001570 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1571 { 0xef53, "EXT2_SUPER_MAGIC" },
1572 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001573 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001574 { 0x9660, "ISOFS_SUPER_MAGIC" },
1575 { 0x137f, "MINIX_SUPER_MAGIC" },
1576 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001577 { 0x2468, "MINIX2_SUPER_MAGIC" },
1578 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001579 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001580 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001581 { 0x6969, "NFS_SUPER_MAGIC" },
1582 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001583 { 0x002f, "QNX4_SUPER_MAGIC" },
1584 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1585 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1586 { 0x517b, "SMB_SUPER_MAGIC" },
1587 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1588 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1589 { 0x00011954, "UFS_MAGIC" },
1590 { 0x54190100, "UFS_CIGAM" },
1591 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001592 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001593 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001594 { 0, NULL },
1595};
1596
Michal Ludvig53b320f2002-09-23 13:30:09 +00001597#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001598
1599#ifndef SVR4
1600
Roland McGrathf9c49b22004-10-06 22:11:54 +00001601static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001602sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001603{
1604 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001605#ifdef LINUX
Roland McGrathf9c49b22004-10-06 22:11:54 +00001606 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001607
1608 s = xlookup(fsmagic, magic);
1609 if (s) {
1610 sprintf(buf, "\"%s\"", s);
1611 return buf;
1612 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001613#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001614 sprintf(buf, "%#x", magic);
1615 return buf;
1616}
1617
1618static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001619printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001620{
1621 struct statfs statbuf;
1622
1623 if (syserror(tcp) || !verbose(tcp)) {
1624 tprintf("%#lx", addr);
1625 return;
1626 }
1627 if (umove(tcp, addr, &statbuf) < 0) {
1628 tprintf("{...}");
1629 return;
1630 }
1631#ifdef ALPHA
1632
1633 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1634 sprintfstype(statbuf.f_type),
1635 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001636 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1637 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1638 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1639 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001640#else /* !ALPHA */
1641 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1642 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001643 (unsigned long)statbuf.f_bsize,
1644 (unsigned long)statbuf.f_blocks,
1645 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001646 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1647 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001648 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001649 (unsigned long)statbuf.f_ffree,
1650 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001651#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001652 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001653#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001654#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001655#ifdef _STATFS_F_FRSIZE
1656 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1657#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001658 tprintf("}");
1659}
1660
1661int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001662sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001663{
1664 if (entering(tcp)) {
1665 printpath(tcp, tcp->u_arg[0]);
1666 tprintf(", ");
1667 } else {
1668 printstatfs(tcp, tcp->u_arg[1]);
1669 }
1670 return 0;
1671}
1672
1673int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001674sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001675{
1676 if (entering(tcp)) {
1677 tprintf("%lu, ", tcp->u_arg[0]);
1678 } else {
1679 printstatfs(tcp, tcp->u_arg[1]);
1680 }
1681 return 0;
1682}
1683
Roland McGrathab147c52003-07-17 09:03:02 +00001684#ifdef LINUX
1685static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001686printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001687{
1688 struct statfs64 statbuf;
1689
1690 if (syserror(tcp) || !verbose(tcp)) {
1691 tprintf("%#lx", addr);
1692 return;
1693 }
1694 if (umove(tcp, addr, &statbuf) < 0) {
1695 tprintf("{...}");
1696 return;
1697 }
Roland McGrath08738432005-06-03 02:40:39 +00001698 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001699 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001700 (unsigned long long)statbuf.f_bsize,
1701 (unsigned long long)statbuf.f_blocks,
1702 (unsigned long long)statbuf.f_bfree);
1703 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1704 (unsigned long long)statbuf.f_bavail,
1705 (unsigned long long)statbuf.f_files,
1706 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001707 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1708 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001709#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001710 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001711#endif
1712 tprintf("}");
1713}
1714
1715int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001716sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001717{
1718 if (entering(tcp)) {
1719 printpath(tcp, tcp->u_arg[0]);
1720 tprintf(", %lu, ", tcp->u_arg[1]);
1721 } else {
1722 if (tcp->u_arg[1] == sizeof (struct statfs64))
1723 printstatfs64(tcp, tcp->u_arg[2]);
1724 else
1725 tprintf("{???}");
1726 }
1727 return 0;
1728}
1729
1730int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001731sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001732{
1733 if (entering(tcp)) {
1734 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1735 } else {
1736 if (tcp->u_arg[1] == sizeof (struct statfs64))
1737 printstatfs64(tcp, tcp->u_arg[2]);
1738 else
1739 tprintf("{???}");
1740 }
1741 return 0;
1742}
1743#endif
1744
Michal Ludvig53b320f2002-09-23 13:30:09 +00001745#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001746
1747int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001748osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001749{
1750 if (entering(tcp)) {
1751 printpath(tcp, tcp->u_arg[0]);
1752 tprintf(", ");
1753 } else {
1754 printstatfs(tcp, tcp->u_arg[1]);
1755 tprintf(", %lu", tcp->u_arg[2]);
1756 }
1757 return 0;
1758}
1759
1760int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001761osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001762{
1763 if (entering(tcp)) {
1764 tprintf("%lu, ", tcp->u_arg[0]);
1765 } else {
1766 printstatfs(tcp, tcp->u_arg[1]);
1767 tprintf(", %lu", tcp->u_arg[2]);
1768 }
1769 return 0;
1770}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001771#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001772
1773#endif /* !SVR4 */
1774
1775#ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001776int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001777sys_ustat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001778{
1779 struct ustat statbuf;
1780
1781 if (entering(tcp)) {
1782 tprintf("makedev(%lu, %lu), ",
1783 (long) major(tcp->u_arg[0]),
1784 (long) minor(tcp->u_arg[0]));
1785 }
1786 else {
1787 if (syserror(tcp) || !verbose(tcp))
1788 tprintf("%#lx", tcp->u_arg[1]);
1789 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1790 tprintf("{...}");
1791 else {
1792 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1793 statbuf.f_tfree, statbuf.f_tinode);
1794 tprintf("f_fname=\"%.*s\", ",
1795 (int) sizeof(statbuf.f_fname),
1796 statbuf.f_fname);
1797 tprintf("f_fpack=\"%.*s\"}",
1798 (int) sizeof(statbuf.f_fpack),
1799 statbuf.f_fpack);
1800 }
1801 }
1802 return 0;
1803}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001804#endif /* SUNOS4 */
1805
Wichert Akkermanc7926982000-04-10 22:22:31 +00001806int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001807sys_pivotroot(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +00001808{
1809 if (entering(tcp)) {
1810 printpath(tcp, tcp->u_arg[0]);
1811 tprintf(", ");
1812 printpath(tcp, tcp->u_arg[1]);
1813 }
1814 return 0;
1815}
1816
1817
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001818/* directory */
1819int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001820sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001821{
1822 if (entering(tcp)) {
1823 printpath(tcp, tcp->u_arg[0]);
1824 }
1825 return 0;
1826}
1827
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001828static int
1829decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001830{
1831 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001832 printpath(tcp, tcp->u_arg[offset]);
1833 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001834 }
1835 return 0;
1836}
1837
1838int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001839sys_mkdir(struct tcb *tcp)
1840{
1841 return decode_mkdir(tcp, 0);
1842}
1843
1844#ifdef LINUX
1845int
1846sys_mkdirat(struct tcb *tcp)
1847{
1848 if (entering(tcp))
1849 print_dirfd(tcp->u_arg[0]);
1850 return decode_mkdir(tcp, 1);
1851}
1852#endif
1853
1854int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001855sys_rmdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001856{
1857 if (entering(tcp)) {
1858 printpath(tcp, tcp->u_arg[0]);
1859 }
1860 return 0;
1861}
1862
1863int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001864sys_fchdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001865{
1866 if (entering(tcp)) {
1867 tprintf("%ld", tcp->u_arg[0]);
1868 }
1869 return 0;
1870}
1871
1872int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001873sys_chroot(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001874{
1875 if (entering(tcp)) {
1876 printpath(tcp, tcp->u_arg[0]);
1877 }
1878 return 0;
1879}
1880
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001881#if defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001882int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001883sys_fchroot(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001884{
1885 if (entering(tcp)) {
1886 tprintf("%ld", tcp->u_arg[0]);
1887 }
1888 return 0;
1889}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001890#endif /* SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001891
1892int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001893sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001894{
1895 if (entering(tcp)) {
1896 printpath(tcp, tcp->u_arg[0]);
1897 tprintf(", ");
1898 printpath(tcp, tcp->u_arg[1]);
1899 }
1900 return 0;
1901}
1902
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001903#ifdef LINUX
1904int
1905sys_linkat(struct tcb *tcp)
1906{
1907 if (entering(tcp)) {
1908 print_dirfd(tcp->u_arg[0]);
1909 printpath(tcp, tcp->u_arg[1]);
1910 tprintf(", ");
1911 print_dirfd(tcp->u_arg[2]);
1912 printpath(tcp, tcp->u_arg[3]);
1913 tprintf(", %ld", tcp->u_arg[4]);
1914 }
1915 return 0;
1916}
1917#endif
1918
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001919int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001920sys_unlink(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001921{
1922 if (entering(tcp)) {
1923 printpath(tcp, tcp->u_arg[0]);
1924 }
1925 return 0;
1926}
1927
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001928#ifdef LINUX
1929static const struct xlat unlinkatflags[] = {
1930#ifndef AT_REMOVEDIR
1931# define AT_REMOVEDIR 0x200
1932#endif
1933 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1934 { 0, NULL },
1935};
1936
1937int
1938sys_unlinkat(struct tcb *tcp)
1939{
1940 if (entering(tcp)) {
1941 print_dirfd(tcp->u_arg[0]);
1942 printpath(tcp, tcp->u_arg[1]);
1943 tprintf(", ");
1944 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1945 }
1946 return 0;
1947}
1948#endif
1949
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001950int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001951sys_symlink(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001952{
1953 if (entering(tcp)) {
1954 printpath(tcp, tcp->u_arg[0]);
1955 tprintf(", ");
1956 printpath(tcp, tcp->u_arg[1]);
1957 }
1958 return 0;
1959}
1960
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001961#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001962int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001963sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001964{
1965 if (entering(tcp)) {
1966 printpath(tcp, tcp->u_arg[0]);
1967 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001968 print_dirfd(tcp->u_arg[1]);
1969 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001970 }
1971 return 0;
1972}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001973#endif
1974
1975static int
1976decode_readlink(struct tcb *tcp, int offset)
1977{
1978 if (entering(tcp)) {
1979 printpath(tcp, tcp->u_arg[offset]);
1980 tprintf(", ");
1981 } else {
1982 if (syserror(tcp))
1983 tprintf("%#lx", tcp->u_arg[offset + 1]);
1984 else
1985 printpathn(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1986 tprintf(", %lu", tcp->u_arg[offset + 2]);
1987 }
1988 return 0;
1989}
1990
1991int
1992sys_readlink(struct tcb *tcp)
1993{
1994 return decode_readlink(tcp, 0);
1995}
1996
1997#ifdef LINUX
1998int
1999sys_readlinkat(struct tcb *tcp)
2000{
2001 if (entering(tcp))
2002 print_dirfd(tcp->u_arg[0]);
2003 return decode_readlink(tcp, 1);
2004}
2005#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002006
2007int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002008sys_rename(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002009{
2010 if (entering(tcp)) {
2011 printpath(tcp, tcp->u_arg[0]);
2012 tprintf(", ");
2013 printpath(tcp, tcp->u_arg[1]);
2014 }
2015 return 0;
2016}
2017
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002018#ifdef LINUX
2019int
2020sys_renameat(struct tcb *tcp)
2021{
2022 if (entering(tcp)) {
2023 print_dirfd(tcp->u_arg[0]);
2024 printpath(tcp, tcp->u_arg[1]);
2025 tprintf(", ");
2026 print_dirfd(tcp->u_arg[2]);
2027 printpath(tcp, tcp->u_arg[3]);
2028 }
2029 return 0;
2030}
2031#endif
2032
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002033int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002034sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002035{
2036 if (entering(tcp)) {
2037 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002038 printuid(", ", tcp->u_arg[1]);
2039 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002040 }
2041 return 0;
2042}
2043
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002044#ifdef LINUX
2045int
2046sys_fchownat(struct tcb *tcp)
2047{
2048 if (entering(tcp)) {
2049 print_dirfd(tcp->u_arg[0]);
2050 printpath(tcp, tcp->u_arg[1]);
2051 printuid(", ", tcp->u_arg[2]);
2052 printuid(", ", tcp->u_arg[3]);
2053 tprintf(", ");
2054 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
2055 }
2056 return 0;
2057}
2058#endif
2059
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002060int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002061sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002062{
2063 if (entering(tcp)) {
Roland McGrath6bc12202003-11-13 22:32:27 +00002064 tprintf("%ld", tcp->u_arg[0]);
2065 printuid(", ", tcp->u_arg[1]);
2066 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002067 }
2068 return 0;
2069}
2070
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002071static int
2072decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002073{
2074 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002075 printpath(tcp, tcp->u_arg[offset]);
2076 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002077 }
2078 return 0;
2079}
2080
2081int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002082sys_chmod(struct tcb *tcp)
2083{
2084 return decode_chmod(tcp, 0);
2085}
2086
2087#ifdef LINUX
2088int
2089sys_fchmodat(struct tcb *tcp)
2090{
2091 if (entering(tcp))
2092 print_dirfd(tcp->u_arg[0]);
2093 return decode_chmod(tcp, 1);
2094}
2095#endif
2096
2097int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002098sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002099{
2100 if (entering(tcp)) {
2101 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
2102 }
2103 return 0;
2104}
2105
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002106#ifdef ALPHA
2107int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002108sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002109{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002110 if (entering(tcp)) {
2111 printpath(tcp, tcp->u_arg[0]);
2112 tprintf(", ");
2113 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2114 }
2115 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002116}
2117#endif
2118
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002119static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002120decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002121{
2122 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002123 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002124 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002125 if (tcp->u_arg[offset + 1] == 0)
2126 tprintf("NULL");
2127 else {
2128 tprintf("{");
2129 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2130 BITNESS_CURRENT, special);
2131 tprintf(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002132 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Roland McGrath6afc5652007-07-24 01:57:11 +00002133 + sizeof (struct timeval),
2134 BITNESS_CURRENT, special);
2135 tprintf("}");
2136 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002137 }
2138 return 0;
2139}
2140
2141int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002142sys_utimes(struct tcb *tcp)
2143{
Roland McGrath6afc5652007-07-24 01:57:11 +00002144 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002145}
2146
2147#ifdef LINUX
2148int
2149sys_futimesat(struct tcb *tcp)
2150{
2151 if (entering(tcp))
2152 print_dirfd(tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002153 return decode_utimes(tcp, 1, 0);
2154}
2155
2156int
2157sys_utimensat(struct tcb *tcp)
2158{
2159 if (entering(tcp)) {
2160 print_dirfd(tcp->u_arg[0]);
2161 decode_utimes(tcp, 1, 1);
2162 tprintf(", ");
2163 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2164 }
2165 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002166}
2167#endif
2168
2169int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002170sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002171{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002172 union {
2173 long utl[2];
2174 int uti[2];
2175 } u;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002176
2177 if (entering(tcp)) {
2178 printpath(tcp, tcp->u_arg[0]);
2179 tprintf(", ");
2180 if (!tcp->u_arg[1])
2181 tprintf("NULL");
2182 else if (!verbose(tcp))
2183 tprintf("%#lx", tcp->u_arg[1]);
Roland McGrath7e9817c2007-07-05 20:31:58 +00002184 else if (umoven(tcp, tcp->u_arg[1],
2185 2 * personality_wordsize[current_personality],
2186 (char *) &u) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002187 tprintf("[?, ?]");
Roland McGrath7e9817c2007-07-05 20:31:58 +00002188 else if (personality_wordsize[current_personality]
2189 == sizeof u.utl[0]) {
2190 tprintf("[%s,", sprinttime(u.utl[0]));
2191 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002192 }
Roland McGrath7e9817c2007-07-05 20:31:58 +00002193 else if (personality_wordsize[current_personality]
2194 == sizeof u.uti[0]) {
2195 tprintf("[%s,", sprinttime(u.uti[0]));
2196 tprintf(" %s]", sprinttime(u.uti[1]));
2197 }
2198 else
2199 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002200 }
2201 return 0;
2202}
2203
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002204static int
2205decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002206{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002207 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002208
2209 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002210 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002211 tprintf(", %s", sprintmode(mode));
2212 switch (mode & S_IFMT) {
2213 case S_IFCHR: case S_IFBLK:
2214#ifdef LINUXSPARC
2215 if (current_personality == 1)
2216 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002217 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2218 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002219 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002220#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002221 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002222 (unsigned long) major(tcp->u_arg[offset + 2]),
2223 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002224 break;
2225 default:
2226 break;
2227 }
2228 }
2229 return 0;
2230}
2231
2232int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002233sys_mknod(struct tcb *tcp)
2234{
2235 return decode_mknod(tcp, 0);
2236}
2237
2238#ifdef LINUX
2239int
2240sys_mknodat(struct tcb *tcp)
2241{
2242 if (entering(tcp))
2243 print_dirfd(tcp->u_arg[0]);
2244 return decode_mknod(tcp, 1);
2245}
2246#endif
2247
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002248#ifdef FREEBSD
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002249int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002250sys_mkfifo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002251{
2252 if (entering(tcp)) {
2253 printpath(tcp, tcp->u_arg[0]);
2254 tprintf(", %#lo", tcp->u_arg[1]);
2255 }
2256 return 0;
2257}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002258#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002259
2260int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002261sys_fsync(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002262{
2263 if (entering(tcp)) {
2264 tprintf("%ld", tcp->u_arg[0]);
2265 }
2266 return 0;
2267}
2268
Michal Ludvig53b320f2002-09-23 13:30:09 +00002269#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002270
2271static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002272printdir(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002273{
2274 struct dirent d;
2275
2276 if (!verbose(tcp)) {
2277 tprintf("%#lx", addr);
2278 return;
2279 }
2280 if (umove(tcp, addr, &d) < 0) {
2281 tprintf("{...}");
2282 return;
2283 }
2284 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002285 tprintf("d_name=");
2286 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2287 tprintf("}");
2288}
2289
2290int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002291sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002292{
2293 if (entering(tcp)) {
2294 tprintf("%lu, ", tcp->u_arg[0]);
2295 } else {
2296 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2297 tprintf("%#lx", tcp->u_arg[1]);
2298 else
2299 printdir(tcp, tcp->u_arg[1]);
2300 /* Not much point in printing this out, it is always 1. */
2301 if (tcp->u_arg[2] != 1)
2302 tprintf(", %lu", tcp->u_arg[2]);
2303 }
2304 return 0;
2305}
2306
Michal Ludvig53b320f2002-09-23 13:30:09 +00002307#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002308
Roland McGrath40542842004-01-13 09:47:49 +00002309#if defined FREEBSD || defined LINUX
Roland McGratha4d48532005-06-08 20:45:28 +00002310static const struct xlat direnttypes[] = {
Roland McGrath40542842004-01-13 09:47:49 +00002311 { DT_UNKNOWN, "DT_UNKNOWN" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002312 { DT_FIFO, "DT_FIFO" },
2313 { DT_CHR, "DT_CHR" },
2314 { DT_DIR, "DT_DIR" },
2315 { DT_BLK, "DT_BLK" },
2316 { DT_REG, "DT_REG" },
2317 { DT_LNK, "DT_LNK" },
2318 { DT_SOCK, "DT_SOCK" },
2319 { DT_WHT, "DT_WHT" },
2320 { 0, NULL },
2321};
2322
2323#endif
2324
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002325int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002326sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002327{
2328 int i, len, dents = 0;
2329 char *buf;
2330
2331 if (entering(tcp)) {
2332 tprintf("%lu, ", tcp->u_arg[0]);
2333 return 0;
2334 }
2335 if (syserror(tcp) || !verbose(tcp)) {
2336 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2337 return 0;
2338 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002339 len = tcp->u_rval;
2340 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002341 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2342 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002343 return 0;
2344 }
2345 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002346 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002347 free(buf);
2348 return 0;
2349 }
2350 if (!abbrev(tcp))
2351 tprintf("{");
2352 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002353 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002354#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002355 if (!abbrev(tcp)) {
2356 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2357 i ? " " : "", d->d_ino, d->d_off);
2358 tprintf("d_reclen=%u, d_name=\"%s\"}",
2359 d->d_reclen, d->d_name);
2360 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002361#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002362#ifdef SVR4
2363 if (!abbrev(tcp)) {
2364 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002365 i ? " " : "",
2366 (unsigned long) d->d_ino,
2367 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002368 tprintf("d_reclen=%u, d_name=\"%s\"}",
2369 d->d_reclen, d->d_name);
2370 }
2371#endif /* SVR4 */
2372#ifdef SUNOS4
2373 if (!abbrev(tcp)) {
2374 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2375 i ? " " : "", d->d_off, d->d_fileno,
2376 d->d_reclen);
2377 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2378 d->d_namlen, d->d_namlen, d->d_name);
2379 }
2380#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002381#ifdef FREEBSD
2382 if (!abbrev(tcp)) {
2383 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2384 i ? " " : "", d->d_fileno, d->d_reclen);
2385 printxval(direnttypes, d->d_type, "DT_???");
2386 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2387 d->d_namlen, d->d_namlen, d->d_name);
2388 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002389#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002390 if (!d->d_reclen) {
2391 tprintf("/* d_reclen == 0, problem here */");
2392 break;
2393 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002394 i += d->d_reclen;
2395 dents++;
2396 }
2397 if (!abbrev(tcp))
2398 tprintf("}");
2399 else
2400 tprintf("/* %u entries */", dents);
2401 tprintf(", %lu", tcp->u_arg[2]);
2402 free(buf);
2403 return 0;
2404}
2405
John Hughesbdf48f52001-03-06 15:08:09 +00002406
2407#if _LFS64_LARGEFILE
2408int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002409sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002410{
2411 int i, len, dents = 0;
2412 char *buf;
2413
2414 if (entering(tcp)) {
2415 tprintf("%lu, ", tcp->u_arg[0]);
2416 return 0;
2417 }
2418 if (syserror(tcp) || !verbose(tcp)) {
2419 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2420 return 0;
2421 }
2422 len = tcp->u_rval;
2423 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002424 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2425 fprintf(stderr, "out of memory\n");
John Hughesbdf48f52001-03-06 15:08:09 +00002426 return 0;
2427 }
2428 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002429 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002430 free(buf);
2431 return 0;
2432 }
2433 if (!abbrev(tcp))
2434 tprintf("{");
2435 for (i = 0; i < len;) {
2436 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002437#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002438 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002439 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002440 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002441 d->d_ino,
2442 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002443#ifdef LINUX
2444 tprintf("d_type=");
2445 printxval(direnttypes, d->d_type, "DT_???");
2446 tprintf(", ");
2447#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002448 tprintf("d_reclen=%u, d_name=\"%s\"}",
2449 d->d_reclen, d->d_name);
2450 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002451#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002452#ifdef SUNOS4
2453 if (!abbrev(tcp)) {
2454 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2455 i ? " " : "", d->d_off, d->d_fileno,
2456 d->d_reclen);
2457 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2458 d->d_namlen, d->d_namlen, d->d_name);
2459 }
2460#endif /* SUNOS4 */
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002461 if (!d->d_reclen) {
2462 tprintf("/* d_reclen == 0, problem here */");
2463 break;
2464 }
John Hughesbdf48f52001-03-06 15:08:09 +00002465 i += d->d_reclen;
2466 dents++;
2467 }
2468 if (!abbrev(tcp))
2469 tprintf("}");
2470 else
2471 tprintf("/* %u entries */", dents);
2472 tprintf(", %lu", tcp->u_arg[2]);
2473 free(buf);
2474 return 0;
2475}
2476#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002477
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002478#ifdef FREEBSD
2479int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002480sys_getdirentries(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002481{
2482 int i, len, dents = 0;
2483 long basep;
2484 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002485
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002486 if (entering(tcp)) {
2487 tprintf("%lu, ", tcp->u_arg[0]);
2488 return 0;
2489 }
2490 if (syserror(tcp) || !verbose(tcp)) {
2491 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2492 return 0;
2493 }
2494 len = tcp->u_rval;
2495 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002496 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2497 fprintf(stderr, "out of memory\n");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002498 return 0;
2499 }
2500 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002501 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002502 free(buf);
2503 return 0;
2504 }
2505 if (!abbrev(tcp))
2506 tprintf("{");
2507 for (i = 0; i < len;) {
2508 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2509 if (!abbrev(tcp)) {
2510 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2511 i ? " " : "", d->d_fileno, d->d_reclen);
2512 printxval(direnttypes, d->d_type, "DT_???");
2513 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2514 d->d_namlen, d->d_namlen, d->d_name);
2515 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002516 if (!d->d_reclen) {
2517 tprintf("/* d_reclen == 0, problem here */");
2518 break;
2519 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002520 i += d->d_reclen;
2521 dents++;
2522 }
2523 if (!abbrev(tcp))
2524 tprintf("}");
2525 else
2526 tprintf("/* %u entries */", dents);
2527 free(buf);
2528 tprintf(", %lu", tcp->u_arg[2]);
2529 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2530 tprintf(", %#lx", tcp->u_arg[3]);
2531 else
2532 tprintf(", [%lu]", basep);
2533 return 0;
2534}
2535#endif
2536
Michal Ludvig53b320f2002-09-23 13:30:09 +00002537#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002538int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002539sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002540{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002541 if (exiting(tcp)) {
2542 if (syserror(tcp))
2543 tprintf("%#lx", tcp->u_arg[0]);
2544 else
2545 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2546 tprintf(", %lu", tcp->u_arg[1]);
2547 }
2548 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002549}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002550#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002551
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002552#ifdef FREEBSD
2553int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002554sys___getcwd(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002555{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002556 if (exiting(tcp)) {
2557 if (syserror(tcp))
2558 tprintf("%#lx", tcp->u_arg[0]);
2559 else
2560 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2561 tprintf(", %lu", tcp->u_arg[1]);
2562 }
2563 return 0;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002564}
2565#endif
2566
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002567#ifdef HAVE_SYS_ASYNCH_H
2568
2569int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002570sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002571{
2572 struct aio_result_t res;
2573
2574 if (entering(tcp)) {
2575 tprintf("%lu, ", tcp->u_arg[0]);
2576 } else {
2577 if (syserror(tcp))
2578 tprintf("%#lx", tcp->u_arg[1]);
2579 else
2580 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2581 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2582 printxval(whence, tcp->u_arg[4], "L_???");
2583 if (syserror(tcp) || tcp->u_arg[5] == 0
2584 || umove(tcp, tcp->u_arg[5], &res) < 0)
2585 tprintf(", %#lx", tcp->u_arg[5]);
2586 else
2587 tprintf(", {aio_return %d aio_errno %d}",
2588 res.aio_return, res.aio_errno);
2589 }
2590 return 0;
2591}
2592
2593int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002594sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002595{
2596 struct aio_result_t res;
2597
2598 if (entering(tcp)) {
2599 tprintf("%lu, ", tcp->u_arg[0]);
2600 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2601 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2602 printxval(whence, tcp->u_arg[4], "L_???");
2603 }
2604 else {
2605 if (tcp->u_arg[5] == 0)
2606 tprintf(", NULL");
2607 else if (syserror(tcp)
2608 || umove(tcp, tcp->u_arg[5], &res) < 0)
2609 tprintf(", %#lx", tcp->u_arg[5]);
2610 else
2611 tprintf(", {aio_return %d aio_errno %d}",
2612 res.aio_return, res.aio_errno);
2613 }
2614 return 0;
2615}
2616
2617int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002618sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002619{
2620 if (entering(tcp))
2621 printtv(tcp, tcp->u_arg[0]);
2622 return 0;
2623}
2624
2625int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002626sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002627{
2628 struct aio_result_t res;
2629
2630 if (exiting(tcp)) {
2631 if (tcp->u_arg[0] == 0)
2632 tprintf("NULL");
2633 else if (syserror(tcp)
2634 || umove(tcp, tcp->u_arg[0], &res) < 0)
2635 tprintf("%#lx", tcp->u_arg[0]);
2636 else
2637 tprintf("{aio_return %d aio_errno %d}",
2638 res.aio_return, res.aio_errno);
2639 }
2640 return 0;
2641}
2642
2643#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002644
Roland McGratha4d48532005-06-08 20:45:28 +00002645static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002646#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002647 { XATTR_CREATE, "XATTR_CREATE" },
2648 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002649#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002650 { 0, NULL }
2651};
2652
Roland McGrath3292e222004-08-31 06:30:48 +00002653static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002654print_xattr_val(struct tcb *tcp, int failed,
2655 unsigned long arg,
2656 unsigned long insize,
2657 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002658{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002659 if (!failed) {
2660 unsigned long capacity = 4 * size + 1;
2661 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2662 if (buf == NULL || /* probably a bogus size argument */
2663 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2664 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002665 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002666 else {
2667 unsigned char *out = buf;
2668 unsigned char *in = &buf[3 * size];
2669 size_t i;
2670 for (i = 0; i < size; ++i) {
2671 if (isprint(in[i]))
2672 *out++ = in[i];
2673 else {
2674#define tohex(n) "0123456789abcdef"[n]
2675 *out++ = '\\';
2676 *out++ = 'x';
2677 *out++ = tohex(in[i] / 16);
2678 *out++ = tohex(in[i] % 16);
2679 }
2680 }
2681 /* Don't print terminating NUL if there is one. */
2682 if (i > 0 && in[i - 1] == '\0')
2683 out -= 4;
2684 *out = '\0';
2685 tprintf(", \"%s\", %ld", buf, insize);
2686 }
2687 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002688 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002689 if (failed)
2690 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002691}
2692
Roland McGrath186c5ac2002-12-15 23:58:23 +00002693int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002694sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002695{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002696 if (entering(tcp)) {
2697 printpath(tcp, tcp->u_arg[0]);
2698 tprintf(", ");
2699 printstr(tcp, tcp->u_arg[1], -1);
2700 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2701 tprintf(", ");
2702 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2703 }
2704 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002705}
2706
2707int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002708sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002709{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002710 if (entering(tcp)) {
2711 tprintf("%ld, ", tcp->u_arg[0]);
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_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002722{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002723 if (entering(tcp)) {
2724 printpath(tcp, tcp->u_arg[0]);
2725 tprintf(", ");
2726 printstr(tcp, tcp->u_arg[1], -1);
2727 } else {
2728 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2729 tcp->u_rval);
2730 }
2731 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002732}
2733
2734int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002735sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002736{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002737 if (entering(tcp)) {
2738 tprintf("%ld, ", tcp->u_arg[0]);
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_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002749{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002750 if (entering(tcp)) {
2751 printpath(tcp, tcp->u_arg[0]);
2752 } else {
2753 /* XXX Print value in format */
2754 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2755 }
2756 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002757}
2758
2759int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002760sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002761{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002762 if (entering(tcp)) {
2763 tprintf("%ld", tcp->u_arg[0]);
2764 } else {
2765 /* XXX Print value in format */
2766 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2767 }
2768 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002769}
2770
2771int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002772sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002773{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002774 if (entering(tcp)) {
2775 printpath(tcp, tcp->u_arg[0]);
2776 tprintf(", ");
2777 printstr(tcp, tcp->u_arg[1], -1);
2778 }
2779 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002780}
2781
2782int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002783sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002784{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002785 if (entering(tcp)) {
2786 tprintf("%ld, ", tcp->u_arg[0]);
2787 printstr(tcp, tcp->u_arg[1], -1);
2788 }
2789 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002790}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002791
2792
2793static const struct xlat advise[] = {
2794 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2795 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2796 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2797 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2798 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2799 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2800 { 0, NULL }
2801};
2802
2803
Roland McGrathe27ed342004-10-20 02:24:19 +00002804#ifdef LINUX
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002805int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002806sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002807{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002808 if (entering(tcp)) {
2809 tprintf("%ld, %lld, %ld, ",
2810 tcp->u_arg[0],
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002811# if defined IA64 || defined X86_64 || defined ALPHA
Denys Vlasenko1d632462009-04-14 12:51:00 +00002812 (long long int) tcp->u_arg[1], tcp->u_arg[2]);
2813 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002814#else
Denys Vlasenko1d632462009-04-14 12:51:00 +00002815 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
2816 printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002817#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002818 }
2819 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002820}
2821#endif
2822
2823
2824int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002825sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002826{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002827 if (entering(tcp)) {
2828 tprintf("%ld, %lld, %lld, ",
2829 tcp->u_arg[0],
Roland McGrath542c2c62008-05-20 01:11:56 +00002830#if defined LINUX_MIPSN32
Denys Vlasenko1d632462009-04-14 12:51:00 +00002831 tcp->ext_arg[1], tcp->ext_arg[2]);
2832 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
Roland McGrath542c2c62008-05-20 01:11:56 +00002833#elif defined IA64 || defined X86_64 || defined ALPHA || defined LINUX_MIPSN64
Denys Vlasenko1d632462009-04-14 12:51:00 +00002834 (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
2835 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002836#else
Denys Vlasenko1d632462009-04-14 12:51:00 +00002837 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
2838 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
2839 printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002840#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002841 }
2842 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002843}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002844
2845#ifdef LINUX
2846static const struct xlat inotify_modes[] = {
2847 { 0x00000001, "IN_ACCESS" },
2848 { 0x00000002, "IN_MODIFY" },
2849 { 0x00000004, "IN_ATTRIB" },
2850 { 0x00000008, "IN_CLOSE_WRITE" },
2851 { 0x00000010, "IN_CLOSE_NOWRITE" },
2852 { 0x00000020, "IN_OPEN" },
2853 { 0x00000040, "IN_MOVED_FROM" },
2854 { 0x00000080, "IN_MOVED_TO" },
2855 { 0x00000100, "IN_CREATE" },
2856 { 0x00000200, "IN_DELETE" },
2857 { 0x00000400, "IN_DELETE_SELF" },
2858 { 0x00000800, "IN_MOVE_SELF" },
2859 { 0x00002000, "IN_UNMOUNT" },
2860 { 0x00004000, "IN_Q_OVERFLOW" },
2861 { 0x00008000, "IN_IGNORED" },
2862 { 0x01000000, "IN_ONLYDIR" },
2863 { 0x02000000, "IN_DONT_FOLLOW" },
2864 { 0x20000000, "IN_MASK_ADD" },
2865 { 0x40000000, "IN_ISDIR" },
2866 { 0x80000000, "IN_ONESHOT" }
2867};
2868
2869int
2870sys_inotify_add_watch(struct tcb *tcp)
2871{
2872 if (entering(tcp)) {
2873 tprintf("%ld, ", tcp->u_arg[0]);
2874 printpath(tcp, tcp->u_arg[1]);
2875 tprintf(", ");
2876 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2877 }
2878 return 0;
2879}
2880
2881int
2882sys_inotify_rm_watch(struct tcb *tcp)
2883{
2884 if (entering(tcp)) {
2885 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
2886 }
2887 return 0;
2888}
Roland McGrath96a96612008-05-20 04:56:18 +00002889
2890int
2891sys_fallocate(struct tcb *tcp)
2892{
2893 if (entering(tcp)) {
2894 tprintf("%ld, ", tcp->u_arg[0]); /* fd */
2895 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
2896 tprintf("%llu, ", LONG_LONG(tcp->u_arg[2],
2897 tcp->u_arg[3])); /* offset */
2898 tprintf("%llu", LONG_LONG(tcp->u_arg[4],
2899 tcp->u_arg[5])); /* len */
2900 }
2901 return 0;
2902}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002903#endif