blob: a8401cfa4bbd9cec4ca5d21b7e159373bafba6d7 [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
330static void
331print_dirfd(long fd)
332{
333 if (fd == AT_FDCWD)
334 tprintf("AT_FDCWD, ");
335 else
336 tprintf("%ld, ", fd);
337}
338#endif
339
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000340/*
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000341 * Pity stpcpy() is not standardized...
342 */
343static char *
344str_append(char *dst, const char *src)
345{
346 while ((*dst = *src++) != '\0')
347 dst++;
348 return dst;
349}
350
351/*
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000352 * low bits of the open(2) flags define access mode,
353 * other bits are real flags.
354 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000355const char *
356sprint_open_modes(mode_t flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000357{
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000358 static char outstr[1024];
359 char *p;
360 char sep = 0;
361 const char *str;
362 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000363
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000364 p = str_append(outstr, "flags ");
365 str = xlookup(open_access_modes, flags & 3);
366 if (str) {
367 p = str_append(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000368 flags &= ~3;
369 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000370 return outstr;
371 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000372 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000373
374 for (x = open_mode_flags; x->str; x++) {
375 if ((flags & x->val) == x->val) {
376 if (sep)
377 *p++ = sep;
378 p = str_append(p, x->str);
379 flags &= ~x->val;
380 if (!flags)
381 return outstr;
382 sep = '|';
383 }
384 }
385 /* flags is still nonzero */
386 if (sep)
387 *p++ = sep;
388 sprintf(p, "%#x", flags);
389 return outstr;
390}
391
392void
393tprint_open_modes(mode_t flags)
394{
395 tprintf(sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000396}
397
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000398static int
399decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000400{
401 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000402 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000403 tprintf(", ");
404 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000405 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000406 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000407 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000408 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000409 }
410 }
411 return 0;
412}
413
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000414int
415sys_open(struct tcb *tcp)
416{
417 return decode_open(tcp, 0);
418}
419
420#ifdef LINUX
421int
422sys_openat(struct tcb *tcp)
423{
424 if (entering(tcp))
425 print_dirfd(tcp->u_arg[0]);
426 return decode_open(tcp, 1);
427}
428#endif
429
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000430#ifdef LINUXSPARC
Roland McGratha4d48532005-06-08 20:45:28 +0000431static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000432 { 0, "O_RDWR" },
433 { 1, "O_RDONLY" },
434 { 2, "O_WRONLY" },
435 { 0x80, "O_NONBLOCK" },
436 { 8, "O_APPEND" },
437 { 0x100, "O_CREAT" },
438 { 0x200, "O_TRUNC" },
439 { 0x400, "O_EXCL" },
440 { 0x800, "O_NOCTTY" },
441 { 0x10, "O_SYNC" },
442 { 0x40, "O_DSYNC" },
443 { 0x8000, "O_RSYNC" },
444 { 4, "O_NDELAY" },
445 { 0x1000, "O_PRIV" },
446 { 0, NULL },
447};
448
449int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000450solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000451{
452 if (entering(tcp)) {
453 printpath(tcp, tcp->u_arg[0]);
454 tprintf(", ");
455 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000456 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000457 if (tcp->u_arg[1] & 0x100) {
458 /* mode */
459 tprintf(", %#lo", tcp->u_arg[2]);
460 }
461 }
462 return 0;
463}
464
465#endif
466
467int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000468sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000469{
470 if (entering(tcp)) {
471 printpath(tcp, tcp->u_arg[0]);
472 tprintf(", %#lo", tcp->u_arg[1]);
473 }
474 return 0;
475}
476
Roland McGrathd9f816f2004-09-04 03:39:20 +0000477static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000478 { F_OK, "F_OK", },
479 { R_OK, "R_OK" },
480 { W_OK, "W_OK" },
481 { X_OK, "X_OK" },
482#ifdef EFF_ONLY_OK
483 { EFF_ONLY_OK, "EFF_ONLY_OK" },
484#endif
485#ifdef EX_OK
486 { EX_OK, "EX_OK" },
487#endif
488 { 0, NULL },
489};
490
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000491static int
492decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000493{
494 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000495 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000496 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000497 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000498 }
499 return 0;
500}
501
502int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000503sys_access(struct tcb *tcp)
504{
505 return decode_access(tcp, 0);
506}
507
508#ifdef LINUX
509int
510sys_faccessat(struct tcb *tcp)
511{
512 if (entering(tcp))
513 print_dirfd(tcp->u_arg[0]);
514 return decode_access(tcp, 1);
515}
516#endif
517
518int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000519sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520{
521 if (entering(tcp)) {
522 tprintf("%#lo", tcp->u_arg[0]);
523 }
524 return RVAL_OCTAL;
525}
526
Roland McGrathd9f816f2004-09-04 03:39:20 +0000527static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000528 { SEEK_SET, "SEEK_SET" },
529 { SEEK_CUR, "SEEK_CUR" },
530 { SEEK_END, "SEEK_END" },
531 { 0, NULL },
532};
533
John Hughes70623be2001-03-08 13:59:00 +0000534#ifndef HAVE_LONG_LONG_OFF_T
Roland McGrath542c2c62008-05-20 01:11:56 +0000535#if defined (LINUX_MIPSN32)
536int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000537sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000538{
539 long long offset;
540 int _whence;
541
542 if (entering(tcp)) {
543 tprintf("%ld, ", tcp->u_arg[0]);
544 offset = tcp->ext_arg[1];
545 _whence = tcp->u_arg[2];
546 if (_whence == SEEK_SET)
547 tprintf("%llu, ", offset);
548 else
549 tprintf("%lld, ", offset);
550 printxval(whence, _whence, "SEEK_???");
551 }
552 return RVAL_UDECIMAL;
553}
554#else /* !LINUX_MIPSN32 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000555int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000556sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000557{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000558 off_t offset;
559 int _whence;
560
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000561 if (entering(tcp)) {
562 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000563 offset = tcp->u_arg[1];
564 _whence = tcp->u_arg[2];
565 if (_whence == SEEK_SET)
566 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000567 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000568 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000569 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000570 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000571 return RVAL_UDECIMAL;
572}
Roland McGrath542c2c62008-05-20 01:11:56 +0000573#endif /* LINUX_MIPSN32 */
John Hughes5a826b82001-03-07 13:21:24 +0000574#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000575
Michal Ludvig53b320f2002-09-23 13:30:09 +0000576#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000577int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000578sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000579{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000580 if (entering(tcp)) {
581 /*
582 * This one call takes explicitly two 32-bit arguments hi, lo,
583 * rather than one 64-bit argument for which LONG_LONG works
584 * appropriate for the native byte order.
585 */
586 if (tcp->u_arg[4] == SEEK_SET)
587 tprintf("%ld, %llu, ", tcp->u_arg[0],
588 (((long long int) tcp->u_arg[1]) << 32
589 | (unsigned long long) (unsigned) tcp->u_arg[2]));
590 else
591 tprintf("%ld, %lld, ", tcp->u_arg[0],
592 (((long long int) tcp->u_arg[1]) << 32
593 | (unsigned long long) (unsigned) tcp->u_arg[2]));
594 }
595 else {
596 long long int off;
597 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
598 tprintf("%#lx, ", tcp->u_arg[3]);
599 else
600 tprintf("[%llu], ", off);
601 printxval(whence, tcp->u_arg[4], "SEEK_???");
602 }
603 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000604}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000605
606int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000607sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000608{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000609 if (entering(tcp)) {
610 tprintf("%ld, %lld, %ld", tcp->u_arg[0],
Roland McGrath542c2c62008-05-20 01:11:56 +0000611# if defined LINUX_MIPSN32
Denys Vlasenko1d632462009-04-14 12:51:00 +0000612 tcp->ext_arg[1], tcp->u_arg[2]
Roland McGrath542c2c62008-05-20 01:11:56 +0000613# elif defined IA64 || defined X86_64 || defined ALPHA || defined LINUX_MIPSN64
Denys Vlasenko1d632462009-04-14 12:51:00 +0000614 (long long int) tcp->u_arg[1], tcp->u_arg[2]
Roland McGrath186c5ac2002-12-15 23:58:23 +0000615# else
Denys Vlasenko1d632462009-04-14 12:51:00 +0000616 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]
Roland McGrath186c5ac2002-12-15 23:58:23 +0000617# endif
618 );
Denys Vlasenko1d632462009-04-14 12:51:00 +0000619 }
620 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000621}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000622#endif
623
John Hughes70623be2001-03-08 13:59:00 +0000624#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000625int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000626sys_lseek64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +0000627{
628 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000629 long long offset;
630 ALIGN64 (tcp, 1); /* FreeBSD aligns off_t args */
John Hughes0c79e012001-03-08 14:40:06 +0000631 offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +0000632 if (tcp->u_arg[3] == SEEK_SET)
633 tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
634 else
635 tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
636 printxval(whence, tcp->u_arg[3], "SEEK_???");
637 }
638 return RVAL_LUDECIMAL;
639}
640#endif
641
John Hughes70623be2001-03-08 13:59:00 +0000642#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000643int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000644sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000645{
646 if (entering(tcp)) {
647 printpath(tcp, tcp->u_arg[0]);
648 tprintf(", %lu", tcp->u_arg[1]);
649 }
650 return 0;
651}
John Hughes5a826b82001-03-07 13:21:24 +0000652#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000653
John Hughes70623be2001-03-08 13:59:00 +0000654#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000655int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000656sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000657{
658 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000659 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000660 printpath(tcp, tcp->u_arg[0]);
John Hughes0c79e012001-03-08 14:40:06 +0000661 tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000662 }
663 return 0;
664}
665#endif
666
John Hughes70623be2001-03-08 13:59:00 +0000667#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000668int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000669sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000670{
671 if (entering(tcp)) {
672 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
673 }
674 return 0;
675}
John Hughes5a826b82001-03-07 13:21:24 +0000676#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000677
John Hughes70623be2001-03-08 13:59:00 +0000678#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000679int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000680sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000681{
682 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000683 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000684 tprintf("%ld, %llu", tcp->u_arg[0],
John Hughes0c79e012001-03-08 14:40:06 +0000685 LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000686 }
687 return 0;
688}
689#endif
690
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000691/* several stats */
692
Roland McGrathd9f816f2004-09-04 03:39:20 +0000693static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000694 { S_IFREG, "S_IFREG" },
695 { S_IFSOCK, "S_IFSOCK" },
696 { S_IFIFO, "S_IFIFO" },
697 { S_IFLNK, "S_IFLNK" },
698 { S_IFDIR, "S_IFDIR" },
699 { S_IFBLK, "S_IFBLK" },
700 { S_IFCHR, "S_IFCHR" },
701 { 0, NULL },
702};
703
Roland McGrathf9c49b22004-10-06 22:11:54 +0000704static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000705sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000706{
707 static char buf[64];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000708 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000709
710 if ((mode & S_IFMT) == 0)
711 s = "";
712 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
713 sprintf(buf, "%#o", mode);
714 return buf;
715 }
716 sprintf(buf, "%s%s%s%s", s,
717 (mode & S_ISUID) ? "|S_ISUID" : "",
718 (mode & S_ISGID) ? "|S_ISGID" : "",
719 (mode & S_ISVTX) ? "|S_ISVTX" : "");
720 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
721 if (mode)
722 sprintf(buf + strlen(buf), "|%#o", mode);
723 s = (*buf == '|') ? buf + 1 : buf;
724 return *s ? s : "0";
725}
726
727static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000728sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000729{
730 struct tm *tmp;
731 static char buf[32];
732
733 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000734 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000735 return buf;
736 }
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000737 if ((tmp = localtime(&t)))
738 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
739 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
740 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
741 else
742 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
743
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000744 return buf;
745}
746
747#ifdef LINUXSPARC
748typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000749 int tv_sec;
750 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000751} timestruct_t;
752
753struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000754 unsigned st_dev;
755 int st_pad1[3]; /* network id */
756 unsigned st_ino;
757 unsigned st_mode;
758 unsigned st_nlink;
759 unsigned st_uid;
760 unsigned st_gid;
761 unsigned st_rdev;
762 int st_pad2[2];
763 int st_size;
764 int st_pad3; /* st_size, off_t expansion */
765 timestruct_t st_atime;
766 timestruct_t st_mtime;
767 timestruct_t st_ctime;
768 int st_blksize;
769 int st_blocks;
770 char st_fstype[16];
771 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000772};
773
774static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000775printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000776{
777 struct solstat statbuf;
778
779 if (!addr) {
780 tprintf("NULL");
781 return;
782 }
783 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000784 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000785 return;
786 }
787 if (umove(tcp, addr, &statbuf) < 0) {
788 tprintf("{...}");
789 return;
790 }
791 if (!abbrev(tcp)) {
792 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
793 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
794 (unsigned long) (statbuf.st_dev & 0x3ffff),
795 (unsigned long) statbuf.st_ino,
796 sprintmode(statbuf.st_mode));
797 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
798 (unsigned long) statbuf.st_nlink,
799 (unsigned long) statbuf.st_uid,
800 (unsigned long) statbuf.st_gid);
801 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
802 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
803 }
804 else
805 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
806 switch (statbuf.st_mode & S_IFMT) {
807 case S_IFCHR: case S_IFBLK:
808 tprintf("st_rdev=makedev(%lu, %lu), ",
809 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
810 (unsigned long) (statbuf.st_rdev & 0x3ffff));
811 break;
812 default:
813 tprintf("st_size=%u, ", statbuf.st_size);
814 break;
815 }
816 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000817 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
818 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
819 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000820 }
821 else
822 tprintf("...}");
823}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000824
825#if defined (SPARC64)
826static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000827printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000828{
829 struct stat_sparc64 statbuf;
830
831 if (!addr) {
832 tprintf("NULL");
833 return;
834 }
835 if (syserror(tcp) || !verbose(tcp)) {
836 tprintf("%#lx", addr);
837 return;
838 }
839 if (umove(tcp, addr, &statbuf) < 0) {
840 tprintf("{...}");
841 return;
842 }
843
844 if (!abbrev(tcp)) {
845 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
846 (unsigned long) major(statbuf.st_dev),
847 (unsigned long) minor(statbuf.st_dev),
848 (unsigned long) statbuf.st_ino,
849 sprintmode(statbuf.st_mode));
850 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
851 (unsigned long) statbuf.st_nlink,
852 (unsigned long) statbuf.st_uid,
853 (unsigned long) statbuf.st_gid);
854 tprintf("st_blksize=%lu, ",
855 (unsigned long) statbuf.st_blksize);
856 tprintf("st_blocks=%lu, ",
857 (unsigned long) statbuf.st_blocks);
858 }
859 else
860 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
861 switch (statbuf.st_mode & S_IFMT) {
862 case S_IFCHR: case S_IFBLK:
863 tprintf("st_rdev=makedev(%lu, %lu), ",
864 (unsigned long) major(statbuf.st_rdev),
865 (unsigned long) minor(statbuf.st_rdev));
866 break;
867 default:
868 tprintf("st_size=%lu, ", statbuf.st_size);
869 break;
870 }
871 if (!abbrev(tcp)) {
872 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
873 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
874 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
875 tprintf("}");
876 }
877 else
878 tprintf("...}");
879}
880#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000881#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000882
Roland McGratha4d48532005-06-08 20:45:28 +0000883static const struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000884#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000885 { UF_NODUMP, "UF_NODUMP" },
886 { UF_IMMUTABLE, "UF_IMMUTABLE" },
887 { UF_APPEND, "UF_APPEND" },
888 { UF_OPAQUE, "UF_OPAQUE" },
889 { UF_NOUNLINK, "UF_NOUNLINK" },
890 { SF_ARCHIVED, "SF_ARCHIVED" },
891 { SF_IMMUTABLE, "SF_IMMUTABLE" },
892 { SF_APPEND, "SF_APPEND" },
893 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000894#elif UNIXWARE >= 2
895#ifdef _S_ISMLD
896 { _S_ISMLD, "_S_ISMLD" },
897#endif
898#ifdef _S_ISMOUNTED
899 { _S_ISMOUNTED, "_S_ISMOUNTED" },
900#endif
901#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000902 { 0, NULL },
903};
904
John Hughesc0fc3fd2001-03-08 16:10:40 +0000905#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000906int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000907sys_chflags(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000908{
909 if (entering(tcp)) {
910 printpath(tcp, tcp->u_arg[0]);
911 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000912 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000913 }
914 return 0;
915}
916
917int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000918sys_fchflags(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000919{
920 if (entering(tcp)) {
921 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000922 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000923 }
924 return 0;
925}
926#endif
927
John Hughes70623be2001-03-08 13:59:00 +0000928#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000929static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000930realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000931{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000932 if (!abbrev(tcp)) {
933 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
934 (unsigned long) major(statbuf->st_dev),
935 (unsigned long) minor(statbuf->st_dev),
936 (unsigned long) statbuf->st_ino,
937 sprintmode(statbuf->st_mode));
938 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
939 (unsigned long) statbuf->st_nlink,
940 (unsigned long) statbuf->st_uid,
941 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000942#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000943 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
944#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000945#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000946 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
947#endif
948 }
949 else
950 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
951 switch (statbuf->st_mode & S_IFMT) {
952 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000953#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000954 tprintf("st_rdev=makedev(%lu, %lu), ",
955 (unsigned long) major(statbuf->st_rdev),
956 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000957#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000958 tprintf("st_size=makedev(%lu, %lu), ",
959 (unsigned long) major(statbuf->st_size),
960 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000961#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000962 break;
963 default:
964 tprintf("st_size=%lu, ", statbuf->st_size);
965 break;
966 }
967 if (!abbrev(tcp)) {
968 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
969 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
970 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000971#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000972 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000973 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000974#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000975#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000976 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
977#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000978#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000979 tprintf(", st_level=%ld", statbuf->st_level);
980#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000981#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000982 tprintf(", st_fstype=%.*s",
983 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
984#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000985#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000986 tprintf(", st_gen=%u", statbuf->st_gen);
987#endif
988 tprintf("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000989 }
990 else
991 tprintf("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000992}
993
Nate Sammons771a6ff1999-04-05 22:39:31 +0000994
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000995static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000996printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000997{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000998 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000999
1000#ifdef LINUXSPARC
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001001 if (current_personality == 1) {
1002 printstatsol(tcp, addr);
1003 return;
1004 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001005#ifdef SPARC64
1006 else if (current_personality == 2) {
1007 printstat_sparc64(tcp, addr);
1008 return;
1009 }
1010#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001011#endif /* LINUXSPARC */
1012
1013 if (!addr) {
1014 tprintf("NULL");
1015 return;
1016 }
1017 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001018 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001019 return;
1020 }
1021 if (umove(tcp, addr, &statbuf) < 0) {
1022 tprintf("{...}");
1023 return;
1024 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001025
1026 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001027}
John Hughes70623be2001-03-08 13:59:00 +00001028#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001029
Roland McGrathe6d0f712007-08-07 01:22:49 +00001030#if !defined HAVE_STAT64 && defined LINUX && defined X86_64
1031/*
1032 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1033 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1034 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1035 * __GNUC__ is needed for the required __attribute__ below.
1036 */
1037struct stat64 {
1038 unsigned long long st_dev;
1039 unsigned char __pad0[4];
1040 unsigned int __st_ino;
1041 unsigned int st_mode;
1042 unsigned int st_nlink;
1043 unsigned int st_uid;
1044 unsigned int st_gid;
1045 unsigned long long st_rdev;
1046 unsigned char __pad3[4];
1047 long long st_size;
1048 unsigned int st_blksize;
1049 unsigned long long st_blocks;
1050 unsigned int st_atime;
1051 unsigned int st_atime_nsec;
1052 unsigned int st_mtime;
1053 unsigned int st_mtime_nsec;
1054 unsigned int st_ctime;
1055 unsigned int st_ctime_nsec;
1056 unsigned long long st_ino;
1057} __attribute__((packed));
1058# define HAVE_STAT64 1
1059# define STAT64_SIZE 96
1060#endif
1061
Wichert Akkermanc7926982000-04-10 22:22:31 +00001062#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001063static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001064printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001065{
1066 struct stat64 statbuf;
1067
Roland McGrathe6d0f712007-08-07 01:22:49 +00001068#ifdef STAT64_SIZE
1069 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1070#endif
1071
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001072#ifdef LINUXSPARC
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001073 if (current_personality == 1) {
1074 printstatsol(tcp, addr);
1075 return;
1076 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001077#ifdef SPARC64
1078 else if (current_personality == 2) {
1079 printstat_sparc64(tcp, addr);
1080 return;
1081 }
1082#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001083#endif /* LINUXSPARC */
1084
1085 if (!addr) {
1086 tprintf("NULL");
1087 return;
1088 }
1089 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001090 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001091 return;
1092 }
1093 if (umove(tcp, addr, &statbuf) < 0) {
1094 tprintf("{...}");
1095 return;
1096 }
1097
1098 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001099#ifdef HAVE_LONG_LONG
1100 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1101#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001102 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001103#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001104 (unsigned long) major(statbuf.st_dev),
1105 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001106#ifdef HAVE_LONG_LONG
1107 (unsigned long long) statbuf.st_ino,
1108#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001109 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001110#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001111 sprintmode(statbuf.st_mode));
1112 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1113 (unsigned long) statbuf.st_nlink,
1114 (unsigned long) statbuf.st_uid,
1115 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001116#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001117 tprintf("st_blksize=%lu, ",
1118 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001119#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1120#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001121 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001122#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001123 }
1124 else
1125 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1126 switch (statbuf.st_mode & S_IFMT) {
1127 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001128#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001129 tprintf("st_rdev=makedev(%lu, %lu), ",
1130 (unsigned long) major(statbuf.st_rdev),
1131 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001132#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001133 tprintf("st_size=makedev(%lu, %lu), ",
1134 (unsigned long) major(statbuf.st_size),
1135 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001136#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001137 break;
1138 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001139#ifdef HAVE_LONG_LONG
1140 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1141#else
1142 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1143#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001144 break;
1145 }
1146 if (!abbrev(tcp)) {
1147 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1148 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001149 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001150#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +00001151 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001152 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001153#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001154#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001155 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1156#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001157#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001158 tprintf(", st_level=%ld", statbuf.st_level);
1159#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001160#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001161 tprintf(", st_fstype=%.*s",
1162 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1163#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001164#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001165 tprintf(", st_gen=%u", statbuf.st_gen);
1166#endif
1167 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001168 }
1169 else
1170 tprintf("...}");
1171}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001172#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001173
Roland McGrath79db8af2003-06-27 21:20:09 +00001174#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001175static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001176convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001177{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001178 newbuf->st_dev = oldbuf->st_dev;
1179 newbuf->st_ino = oldbuf->st_ino;
1180 newbuf->st_mode = oldbuf->st_mode;
1181 newbuf->st_nlink = oldbuf->st_nlink;
1182 newbuf->st_uid = oldbuf->st_uid;
1183 newbuf->st_gid = oldbuf->st_gid;
1184 newbuf->st_rdev = oldbuf->st_rdev;
1185 newbuf->st_size = oldbuf->st_size;
1186 newbuf->st_atime = oldbuf->st_atime;
1187 newbuf->st_mtime = oldbuf->st_mtime;
1188 newbuf->st_ctime = oldbuf->st_ctime;
1189 newbuf->st_blksize = 0; /* not supported in old_stat */
1190 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001191}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001192
1193
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001194static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001195printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001196{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001197 struct __old_kernel_stat statbuf;
1198 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001199
1200#ifdef LINUXSPARC
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001201 if (current_personality == 1) {
1202 printstatsol(tcp, addr);
1203 return;
1204 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001205#endif /* LINUXSPARC */
1206
1207 if (!addr) {
1208 tprintf("NULL");
1209 return;
1210 }
1211 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001212 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001213 return;
1214 }
1215 if (umove(tcp, addr, &statbuf) < 0) {
1216 tprintf("{...}");
1217 return;
1218 }
1219
1220 convertoldstat(&statbuf, &newstatbuf);
1221 realprintstat(tcp, &newstatbuf);
1222}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001223#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001224
John Hughes70623be2001-03-08 13:59:00 +00001225#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001226int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001227sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001228{
1229 if (entering(tcp)) {
1230 printpath(tcp, tcp->u_arg[0]);
1231 tprintf(", ");
1232 } else {
1233 printstat(tcp, tcp->u_arg[1]);
1234 }
1235 return 0;
1236}
John Hughesb8c9f772001-03-07 16:53:07 +00001237#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001238
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001239int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001240sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001241{
1242#ifdef HAVE_STAT64
1243 if (entering(tcp)) {
1244 printpath(tcp, tcp->u_arg[0]);
1245 tprintf(", ");
1246 } else {
1247 printstat64(tcp, tcp->u_arg[1]);
1248 }
1249 return 0;
1250#else
1251 return printargs(tcp);
1252#endif
1253}
1254
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001255#ifdef LINUX
1256static const struct xlat fstatatflags[] = {
1257#ifndef AT_SYMLINK_NOFOLLOW
1258# define AT_SYMLINK_NOFOLLOW 0x100
1259#endif
1260 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1261 { 0, NULL },
1262};
Roland McGrath6afc5652007-07-24 01:57:11 +00001263#define utimensatflags fstatatflags
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001264
1265int
1266sys_newfstatat(struct tcb *tcp)
1267{
1268 if (entering(tcp)) {
1269 print_dirfd(tcp->u_arg[0]);
1270 printpath(tcp, tcp->u_arg[1]);
1271 tprintf(", ");
1272 } else {
Roland McGrath359c8ed2007-07-05 19:01:17 +00001273#if defined HAVE_STAT64 && !(defined POWERPC && defined __powerpc64__)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001274 printstat64(tcp, tcp->u_arg[2]);
1275#else
1276 printstat(tcp, tcp->u_arg[2]);
1277#endif
1278 tprintf(", ");
1279 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1280 }
1281 return 0;
1282}
1283#endif
1284
Roland McGrath79db8af2003-06-27 21:20:09 +00001285#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001286int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001287sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001288{
1289 if (entering(tcp)) {
1290 printpath(tcp, tcp->u_arg[0]);
1291 tprintf(", ");
1292 } else {
1293 printoldstat(tcp, tcp->u_arg[1]);
1294 }
1295 return 0;
1296}
Roland McGrath79db8af2003-06-27 21:20:09 +00001297#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001298
John Hughes70623be2001-03-08 13:59:00 +00001299#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001300int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001301sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001302{
1303 if (entering(tcp))
1304 tprintf("%ld, ", tcp->u_arg[0]);
1305 else {
1306 printstat(tcp, tcp->u_arg[1]);
1307 }
1308 return 0;
1309}
John Hughesb8c9f772001-03-07 16:53:07 +00001310#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001311
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001312int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001313sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001314{
1315#ifdef HAVE_STAT64
1316 if (entering(tcp))
1317 tprintf("%ld, ", tcp->u_arg[0]);
1318 else {
1319 printstat64(tcp, tcp->u_arg[1]);
1320 }
1321 return 0;
1322#else
1323 return printargs(tcp);
1324#endif
1325}
1326
Roland McGrath79db8af2003-06-27 21:20:09 +00001327#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001328int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001329sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001330{
1331 if (entering(tcp))
1332 tprintf("%ld, ", tcp->u_arg[0]);
1333 else {
1334 printoldstat(tcp, tcp->u_arg[1]);
1335 }
1336 return 0;
1337}
Roland McGrath79db8af2003-06-27 21:20:09 +00001338#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001339
John Hughes70623be2001-03-08 13:59:00 +00001340#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001341int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001342sys_lstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001343{
1344 if (entering(tcp)) {
1345 printpath(tcp, tcp->u_arg[0]);
1346 tprintf(", ");
1347 } else {
1348 printstat(tcp, tcp->u_arg[1]);
1349 }
1350 return 0;
1351}
John Hughesb8c9f772001-03-07 16:53:07 +00001352#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001353
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001354int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001355sys_lstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001356{
1357#ifdef HAVE_STAT64
1358 if (entering(tcp)) {
1359 printpath(tcp, tcp->u_arg[0]);
1360 tprintf(", ");
1361 } else {
1362 printstat64(tcp, tcp->u_arg[1]);
1363 }
1364 return 0;
1365#else
1366 return printargs(tcp);
1367#endif
1368}
1369
Roland McGrath79db8af2003-06-27 21:20:09 +00001370#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001371int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001372sys_oldlstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001373{
1374 if (entering(tcp)) {
1375 printpath(tcp, tcp->u_arg[0]);
1376 tprintf(", ");
1377 } else {
1378 printoldstat(tcp, tcp->u_arg[1]);
1379 }
1380 return 0;
1381}
Roland McGrath79db8af2003-06-27 21:20:09 +00001382#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001383
1384
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001385#if defined(SVR4) || defined(LINUXSPARC)
1386
1387int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001388sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001389{
1390 if (entering(tcp)) {
1391 tprintf("%ld, ", tcp->u_arg[0]);
1392 printpath(tcp, tcp->u_arg[1]);
1393 tprintf(", ");
1394 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001395#ifdef _STAT64_VER
1396 if (tcp->u_arg[0] == _STAT64_VER)
1397 printstat64 (tcp, tcp->u_arg[2]);
1398 else
1399#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001400 printstat(tcp, tcp->u_arg[2]);
1401 }
1402 return 0;
1403}
1404
1405int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001406sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001407{
1408 if (entering(tcp))
1409 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1410 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001411#ifdef _STAT64_VER
1412 if (tcp->u_arg[0] == _STAT64_VER)
1413 printstat64 (tcp, tcp->u_arg[2]);
1414 else
1415#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001416 printstat(tcp, tcp->u_arg[2]);
1417 }
1418 return 0;
1419}
1420
1421int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001422sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001423{
1424 if (entering(tcp)) {
1425 tprintf("%ld, ", tcp->u_arg[0]);
1426 printpath(tcp, tcp->u_arg[1]);
1427 tprintf(", ");
1428 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001429#ifdef _STAT64_VER
1430 if (tcp->u_arg[0] == _STAT64_VER)
1431 printstat64 (tcp, tcp->u_arg[2]);
1432 else
1433#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001434 printstat(tcp, tcp->u_arg[2]);
1435 }
1436 return 0;
1437}
1438
1439int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001440sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001441{
1442 int mode = tcp->u_arg[2];
1443
1444 if (entering(tcp)) {
1445 tprintf("%ld, ", tcp->u_arg[0]);
1446 printpath(tcp, tcp->u_arg[1]);
1447 tprintf(", %s", sprintmode(mode));
1448 switch (mode & S_IFMT) {
1449 case S_IFCHR: case S_IFBLK:
1450#ifdef LINUXSPARC
1451 tprintf(", makedev(%lu, %lu)",
1452 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1453 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001454#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001455 tprintf(", makedev(%lu, %lu)",
1456 (unsigned long) major(tcp->u_arg[3]),
1457 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001458#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001459 break;
1460 default:
1461 break;
1462 }
1463 }
1464 return 0;
1465}
1466
Wichert Akkerman8829a551999-06-11 13:18:40 +00001467#ifdef HAVE_SYS_ACL_H
1468
1469#include <sys/acl.h>
1470
Roland McGratha4d48532005-06-08 20:45:28 +00001471static const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001472#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001473 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001474#endif
1475#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001476 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001477#endif
1478#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001479 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001480#endif
1481#ifdef ACL_GET
1482 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001483#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001484#ifdef ACL_SET
1485 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001486#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001487#ifdef ACL_CNT
1488 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001489#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001490 { 0, NULL },
1491};
1492
1493int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001494sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001495{
1496 if (entering(tcp)) {
1497 printpath(tcp, tcp->u_arg[0]);
1498 tprintf(", ");
1499 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1500 tprintf(", %ld", tcp->u_arg[2]);
1501 /*
1502 * FIXME - dump out the list of aclent_t's pointed to
1503 * by "tcp->u_arg[3]" if it's not NULL.
1504 */
1505 if (tcp->u_arg[3])
1506 tprintf(", %#lx", tcp->u_arg[3]);
1507 else
1508 tprintf(", NULL");
1509 }
1510 return 0;
1511}
1512
1513
1514int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001515sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001516{
1517 if (entering(tcp)) {
1518 tprintf("%ld, ", tcp->u_arg[0]);
1519 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1520 tprintf(", %ld", tcp->u_arg[2]);
1521 /*
1522 * FIXME - dump out the list of aclent_t's pointed to
1523 * by "tcp->u_arg[3]" if it's not NULL.
1524 */
1525 if (tcp->u_arg[3])
1526 tprintf(", %#lx", tcp->u_arg[3]);
1527 else
1528 tprintf(", NULL");
1529 }
1530 return 0;
1531}
1532
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001533
Roland McGratha4d48532005-06-08 20:45:28 +00001534static const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001535#ifdef IPC_SHM
1536 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001537#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001538#ifdef IPC_SEM
1539 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001540#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001541#ifdef IPC_MSG
1542 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001543#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001544 { 0, NULL },
1545};
1546
1547
1548int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001549sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001550{
1551 if (entering(tcp)) {
1552 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1553 tprintf(", %#lx, ", tcp->u_arg[1]);
1554 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1555 tprintf(", %ld", tcp->u_arg[3]);
1556 /*
1557 * FIXME - dump out the list of aclent_t's pointed to
1558 * by "tcp->u_arg[4]" if it's not NULL.
1559 */
1560 if (tcp->u_arg[4])
1561 tprintf(", %#lx", tcp->u_arg[4]);
1562 else
1563 tprintf(", NULL");
1564 }
1565 return 0;
1566}
1567
Wichert Akkerman8829a551999-06-11 13:18:40 +00001568#endif /* HAVE_SYS_ACL_H */
1569
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001570#endif /* SVR4 || LINUXSPARC */
1571
Michal Ludvig53b320f2002-09-23 13:30:09 +00001572#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001573
Roland McGrathd9f816f2004-09-04 03:39:20 +00001574static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001575 { 0x73757245, "CODA_SUPER_MAGIC" },
1576 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1577 { 0x1373, "DEVFS_SUPER_MAGIC" },
1578 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1579 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001580 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1581 { 0xef53, "EXT2_SUPER_MAGIC" },
1582 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001583 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001584 { 0x9660, "ISOFS_SUPER_MAGIC" },
1585 { 0x137f, "MINIX_SUPER_MAGIC" },
1586 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001587 { 0x2468, "MINIX2_SUPER_MAGIC" },
1588 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001589 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001590 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001591 { 0x6969, "NFS_SUPER_MAGIC" },
1592 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001593 { 0x002f, "QNX4_SUPER_MAGIC" },
1594 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1595 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1596 { 0x517b, "SMB_SUPER_MAGIC" },
1597 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1598 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1599 { 0x00011954, "UFS_MAGIC" },
1600 { 0x54190100, "UFS_CIGAM" },
1601 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001602 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001603 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001604 { 0, NULL },
1605};
1606
Michal Ludvig53b320f2002-09-23 13:30:09 +00001607#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001608
1609#ifndef SVR4
1610
Roland McGrathf9c49b22004-10-06 22:11:54 +00001611static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001612sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001613{
1614 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001615#ifdef LINUX
Roland McGrathf9c49b22004-10-06 22:11:54 +00001616 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001617
1618 s = xlookup(fsmagic, magic);
1619 if (s) {
1620 sprintf(buf, "\"%s\"", s);
1621 return buf;
1622 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001623#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001624 sprintf(buf, "%#x", magic);
1625 return buf;
1626}
1627
1628static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001629printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001630{
1631 struct statfs statbuf;
1632
1633 if (syserror(tcp) || !verbose(tcp)) {
1634 tprintf("%#lx", addr);
1635 return;
1636 }
1637 if (umove(tcp, addr, &statbuf) < 0) {
1638 tprintf("{...}");
1639 return;
1640 }
1641#ifdef ALPHA
1642
1643 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1644 sprintfstype(statbuf.f_type),
1645 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001646 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1647 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1648 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1649 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001650#else /* !ALPHA */
1651 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1652 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001653 (unsigned long)statbuf.f_bsize,
1654 (unsigned long)statbuf.f_blocks,
1655 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001656 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1657 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001658 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001659 (unsigned long)statbuf.f_ffree,
1660 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001661#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001662 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001663#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001664#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001665#ifdef _STATFS_F_FRSIZE
1666 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1667#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001668 tprintf("}");
1669}
1670
1671int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001672sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001673{
1674 if (entering(tcp)) {
1675 printpath(tcp, tcp->u_arg[0]);
1676 tprintf(", ");
1677 } else {
1678 printstatfs(tcp, tcp->u_arg[1]);
1679 }
1680 return 0;
1681}
1682
1683int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001684sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001685{
1686 if (entering(tcp)) {
1687 tprintf("%lu, ", tcp->u_arg[0]);
1688 } else {
1689 printstatfs(tcp, tcp->u_arg[1]);
1690 }
1691 return 0;
1692}
1693
Roland McGrathab147c52003-07-17 09:03:02 +00001694#ifdef LINUX
1695static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001696printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001697{
1698 struct statfs64 statbuf;
1699
1700 if (syserror(tcp) || !verbose(tcp)) {
1701 tprintf("%#lx", addr);
1702 return;
1703 }
1704 if (umove(tcp, addr, &statbuf) < 0) {
1705 tprintf("{...}");
1706 return;
1707 }
Roland McGrath08738432005-06-03 02:40:39 +00001708 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001709 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001710 (unsigned long long)statbuf.f_bsize,
1711 (unsigned long long)statbuf.f_blocks,
1712 (unsigned long long)statbuf.f_bfree);
1713 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1714 (unsigned long long)statbuf.f_bavail,
1715 (unsigned long long)statbuf.f_files,
1716 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001717 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1718 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001719#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001720 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001721#endif
1722 tprintf("}");
1723}
1724
1725int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001726sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001727{
1728 if (entering(tcp)) {
1729 printpath(tcp, tcp->u_arg[0]);
1730 tprintf(", %lu, ", tcp->u_arg[1]);
1731 } else {
1732 if (tcp->u_arg[1] == sizeof (struct statfs64))
1733 printstatfs64(tcp, tcp->u_arg[2]);
1734 else
1735 tprintf("{???}");
1736 }
1737 return 0;
1738}
1739
1740int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001741sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001742{
1743 if (entering(tcp)) {
1744 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1745 } else {
1746 if (tcp->u_arg[1] == sizeof (struct statfs64))
1747 printstatfs64(tcp, tcp->u_arg[2]);
1748 else
1749 tprintf("{???}");
1750 }
1751 return 0;
1752}
1753#endif
1754
Michal Ludvig53b320f2002-09-23 13:30:09 +00001755#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001756
1757int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001758osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001759{
1760 if (entering(tcp)) {
1761 printpath(tcp, tcp->u_arg[0]);
1762 tprintf(", ");
1763 } else {
1764 printstatfs(tcp, tcp->u_arg[1]);
1765 tprintf(", %lu", tcp->u_arg[2]);
1766 }
1767 return 0;
1768}
1769
1770int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001771osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001772{
1773 if (entering(tcp)) {
1774 tprintf("%lu, ", tcp->u_arg[0]);
1775 } else {
1776 printstatfs(tcp, tcp->u_arg[1]);
1777 tprintf(", %lu", tcp->u_arg[2]);
1778 }
1779 return 0;
1780}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001781#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001782
1783#endif /* !SVR4 */
1784
1785#ifdef SUNOS4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001786int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001787sys_ustat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001788{
1789 struct ustat statbuf;
1790
1791 if (entering(tcp)) {
1792 tprintf("makedev(%lu, %lu), ",
1793 (long) major(tcp->u_arg[0]),
1794 (long) minor(tcp->u_arg[0]));
1795 }
1796 else {
1797 if (syserror(tcp) || !verbose(tcp))
1798 tprintf("%#lx", tcp->u_arg[1]);
1799 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1800 tprintf("{...}");
1801 else {
1802 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1803 statbuf.f_tfree, statbuf.f_tinode);
1804 tprintf("f_fname=\"%.*s\", ",
1805 (int) sizeof(statbuf.f_fname),
1806 statbuf.f_fname);
1807 tprintf("f_fpack=\"%.*s\"}",
1808 (int) sizeof(statbuf.f_fpack),
1809 statbuf.f_fpack);
1810 }
1811 }
1812 return 0;
1813}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001814#endif /* SUNOS4 */
1815
Wichert Akkermanc7926982000-04-10 22:22:31 +00001816int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001817sys_pivotroot(struct tcb *tcp)
Wichert Akkermanc7926982000-04-10 22:22:31 +00001818{
1819 if (entering(tcp)) {
1820 printpath(tcp, tcp->u_arg[0]);
1821 tprintf(", ");
1822 printpath(tcp, tcp->u_arg[1]);
1823 }
1824 return 0;
1825}
1826
1827
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001828/* directory */
1829int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001830sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001831{
1832 if (entering(tcp)) {
1833 printpath(tcp, tcp->u_arg[0]);
1834 }
1835 return 0;
1836}
1837
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001838static int
1839decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001840{
1841 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001842 printpath(tcp, tcp->u_arg[offset]);
1843 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001844 }
1845 return 0;
1846}
1847
1848int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001849sys_mkdir(struct tcb *tcp)
1850{
1851 return decode_mkdir(tcp, 0);
1852}
1853
1854#ifdef LINUX
1855int
1856sys_mkdirat(struct tcb *tcp)
1857{
1858 if (entering(tcp))
1859 print_dirfd(tcp->u_arg[0]);
1860 return decode_mkdir(tcp, 1);
1861}
1862#endif
1863
1864int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001865sys_rmdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001866{
1867 if (entering(tcp)) {
1868 printpath(tcp, tcp->u_arg[0]);
1869 }
1870 return 0;
1871}
1872
1873int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001874sys_fchdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001875{
1876 if (entering(tcp)) {
1877 tprintf("%ld", tcp->u_arg[0]);
1878 }
1879 return 0;
1880}
1881
1882int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001883sys_chroot(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001884{
1885 if (entering(tcp)) {
1886 printpath(tcp, tcp->u_arg[0]);
1887 }
1888 return 0;
1889}
1890
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001891#if defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001892int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001893sys_fchroot(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001894{
1895 if (entering(tcp)) {
1896 tprintf("%ld", tcp->u_arg[0]);
1897 }
1898 return 0;
1899}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001900#endif /* SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001901
1902int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001903sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001904{
1905 if (entering(tcp)) {
1906 printpath(tcp, tcp->u_arg[0]);
1907 tprintf(", ");
1908 printpath(tcp, tcp->u_arg[1]);
1909 }
1910 return 0;
1911}
1912
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001913#ifdef LINUX
1914int
1915sys_linkat(struct tcb *tcp)
1916{
1917 if (entering(tcp)) {
1918 print_dirfd(tcp->u_arg[0]);
1919 printpath(tcp, tcp->u_arg[1]);
1920 tprintf(", ");
1921 print_dirfd(tcp->u_arg[2]);
1922 printpath(tcp, tcp->u_arg[3]);
1923 tprintf(", %ld", tcp->u_arg[4]);
1924 }
1925 return 0;
1926}
1927#endif
1928
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001929int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001930sys_unlink(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001931{
1932 if (entering(tcp)) {
1933 printpath(tcp, tcp->u_arg[0]);
1934 }
1935 return 0;
1936}
1937
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001938#ifdef LINUX
1939static const struct xlat unlinkatflags[] = {
1940#ifndef AT_REMOVEDIR
1941# define AT_REMOVEDIR 0x200
1942#endif
1943 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1944 { 0, NULL },
1945};
1946
1947int
1948sys_unlinkat(struct tcb *tcp)
1949{
1950 if (entering(tcp)) {
1951 print_dirfd(tcp->u_arg[0]);
1952 printpath(tcp, tcp->u_arg[1]);
1953 tprintf(", ");
1954 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1955 }
1956 return 0;
1957}
1958#endif
1959
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001960int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001961sys_symlink(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001962{
1963 if (entering(tcp)) {
1964 printpath(tcp, tcp->u_arg[0]);
1965 tprintf(", ");
1966 printpath(tcp, tcp->u_arg[1]);
1967 }
1968 return 0;
1969}
1970
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001971#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001972int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001973sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001974{
1975 if (entering(tcp)) {
1976 printpath(tcp, tcp->u_arg[0]);
1977 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001978 print_dirfd(tcp->u_arg[1]);
1979 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001980 }
1981 return 0;
1982}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001983#endif
1984
1985static int
1986decode_readlink(struct tcb *tcp, int offset)
1987{
1988 if (entering(tcp)) {
1989 printpath(tcp, tcp->u_arg[offset]);
1990 tprintf(", ");
1991 } else {
1992 if (syserror(tcp))
1993 tprintf("%#lx", tcp->u_arg[offset + 1]);
1994 else
1995 printpathn(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1996 tprintf(", %lu", tcp->u_arg[offset + 2]);
1997 }
1998 return 0;
1999}
2000
2001int
2002sys_readlink(struct tcb *tcp)
2003{
2004 return decode_readlink(tcp, 0);
2005}
2006
2007#ifdef LINUX
2008int
2009sys_readlinkat(struct tcb *tcp)
2010{
2011 if (entering(tcp))
2012 print_dirfd(tcp->u_arg[0]);
2013 return decode_readlink(tcp, 1);
2014}
2015#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002016
2017int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002018sys_rename(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002019{
2020 if (entering(tcp)) {
2021 printpath(tcp, tcp->u_arg[0]);
2022 tprintf(", ");
2023 printpath(tcp, tcp->u_arg[1]);
2024 }
2025 return 0;
2026}
2027
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002028#ifdef LINUX
2029int
2030sys_renameat(struct tcb *tcp)
2031{
2032 if (entering(tcp)) {
2033 print_dirfd(tcp->u_arg[0]);
2034 printpath(tcp, tcp->u_arg[1]);
2035 tprintf(", ");
2036 print_dirfd(tcp->u_arg[2]);
2037 printpath(tcp, tcp->u_arg[3]);
2038 }
2039 return 0;
2040}
2041#endif
2042
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002043int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002044sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002045{
2046 if (entering(tcp)) {
2047 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002048 printuid(", ", tcp->u_arg[1]);
2049 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002050 }
2051 return 0;
2052}
2053
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002054#ifdef LINUX
2055int
2056sys_fchownat(struct tcb *tcp)
2057{
2058 if (entering(tcp)) {
2059 print_dirfd(tcp->u_arg[0]);
2060 printpath(tcp, tcp->u_arg[1]);
2061 printuid(", ", tcp->u_arg[2]);
2062 printuid(", ", tcp->u_arg[3]);
2063 tprintf(", ");
2064 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
2065 }
2066 return 0;
2067}
2068#endif
2069
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002070int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002071sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002072{
2073 if (entering(tcp)) {
Roland McGrath6bc12202003-11-13 22:32:27 +00002074 tprintf("%ld", tcp->u_arg[0]);
2075 printuid(", ", tcp->u_arg[1]);
2076 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002077 }
2078 return 0;
2079}
2080
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002081static int
2082decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002083{
2084 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002085 printpath(tcp, tcp->u_arg[offset]);
2086 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002087 }
2088 return 0;
2089}
2090
2091int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002092sys_chmod(struct tcb *tcp)
2093{
2094 return decode_chmod(tcp, 0);
2095}
2096
2097#ifdef LINUX
2098int
2099sys_fchmodat(struct tcb *tcp)
2100{
2101 if (entering(tcp))
2102 print_dirfd(tcp->u_arg[0]);
2103 return decode_chmod(tcp, 1);
2104}
2105#endif
2106
2107int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002108sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002109{
2110 if (entering(tcp)) {
2111 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
2112 }
2113 return 0;
2114}
2115
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002116#ifdef ALPHA
2117int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002118sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002119{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002120 if (entering(tcp)) {
2121 printpath(tcp, tcp->u_arg[0]);
2122 tprintf(", ");
2123 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2124 }
2125 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002126}
2127#endif
2128
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002129static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002130decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002131{
2132 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002133 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002134 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002135 if (tcp->u_arg[offset + 1] == 0)
2136 tprintf("NULL");
2137 else {
2138 tprintf("{");
2139 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2140 BITNESS_CURRENT, special);
2141 tprintf(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002142 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Roland McGrath6afc5652007-07-24 01:57:11 +00002143 + sizeof (struct timeval),
2144 BITNESS_CURRENT, special);
2145 tprintf("}");
2146 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002147 }
2148 return 0;
2149}
2150
2151int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002152sys_utimes(struct tcb *tcp)
2153{
Roland McGrath6afc5652007-07-24 01:57:11 +00002154 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002155}
2156
2157#ifdef LINUX
2158int
2159sys_futimesat(struct tcb *tcp)
2160{
2161 if (entering(tcp))
2162 print_dirfd(tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002163 return decode_utimes(tcp, 1, 0);
2164}
2165
2166int
2167sys_utimensat(struct tcb *tcp)
2168{
2169 if (entering(tcp)) {
2170 print_dirfd(tcp->u_arg[0]);
2171 decode_utimes(tcp, 1, 1);
2172 tprintf(", ");
2173 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2174 }
2175 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002176}
2177#endif
2178
2179int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002180sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002181{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002182 union {
2183 long utl[2];
2184 int uti[2];
2185 } u;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002186
2187 if (entering(tcp)) {
2188 printpath(tcp, tcp->u_arg[0]);
2189 tprintf(", ");
2190 if (!tcp->u_arg[1])
2191 tprintf("NULL");
2192 else if (!verbose(tcp))
2193 tprintf("%#lx", tcp->u_arg[1]);
Roland McGrath7e9817c2007-07-05 20:31:58 +00002194 else if (umoven(tcp, tcp->u_arg[1],
2195 2 * personality_wordsize[current_personality],
2196 (char *) &u) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002197 tprintf("[?, ?]");
Roland McGrath7e9817c2007-07-05 20:31:58 +00002198 else if (personality_wordsize[current_personality]
2199 == sizeof u.utl[0]) {
2200 tprintf("[%s,", sprinttime(u.utl[0]));
2201 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002202 }
Roland McGrath7e9817c2007-07-05 20:31:58 +00002203 else if (personality_wordsize[current_personality]
2204 == sizeof u.uti[0]) {
2205 tprintf("[%s,", sprinttime(u.uti[0]));
2206 tprintf(" %s]", sprinttime(u.uti[1]));
2207 }
2208 else
2209 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002210 }
2211 return 0;
2212}
2213
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002214static int
2215decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002216{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002217 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002218
2219 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002220 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002221 tprintf(", %s", sprintmode(mode));
2222 switch (mode & S_IFMT) {
2223 case S_IFCHR: case S_IFBLK:
2224#ifdef LINUXSPARC
2225 if (current_personality == 1)
2226 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002227 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2228 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002229 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002230#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002231 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002232 (unsigned long) major(tcp->u_arg[offset + 2]),
2233 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002234 break;
2235 default:
2236 break;
2237 }
2238 }
2239 return 0;
2240}
2241
2242int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002243sys_mknod(struct tcb *tcp)
2244{
2245 return decode_mknod(tcp, 0);
2246}
2247
2248#ifdef LINUX
2249int
2250sys_mknodat(struct tcb *tcp)
2251{
2252 if (entering(tcp))
2253 print_dirfd(tcp->u_arg[0]);
2254 return decode_mknod(tcp, 1);
2255}
2256#endif
2257
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002258#ifdef FREEBSD
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002259int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002260sys_mkfifo(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002261{
2262 if (entering(tcp)) {
2263 printpath(tcp, tcp->u_arg[0]);
2264 tprintf(", %#lo", tcp->u_arg[1]);
2265 }
2266 return 0;
2267}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002268#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002269
2270int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002271sys_fsync(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002272{
2273 if (entering(tcp)) {
2274 tprintf("%ld", tcp->u_arg[0]);
2275 }
2276 return 0;
2277}
2278
Michal Ludvig53b320f2002-09-23 13:30:09 +00002279#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002280
2281static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002282printdir(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002283{
2284 struct dirent d;
2285
2286 if (!verbose(tcp)) {
2287 tprintf("%#lx", addr);
2288 return;
2289 }
2290 if (umove(tcp, addr, &d) < 0) {
2291 tprintf("{...}");
2292 return;
2293 }
2294 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002295 tprintf("d_name=");
2296 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2297 tprintf("}");
2298}
2299
2300int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002301sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002302{
2303 if (entering(tcp)) {
2304 tprintf("%lu, ", tcp->u_arg[0]);
2305 } else {
2306 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2307 tprintf("%#lx", tcp->u_arg[1]);
2308 else
2309 printdir(tcp, tcp->u_arg[1]);
2310 /* Not much point in printing this out, it is always 1. */
2311 if (tcp->u_arg[2] != 1)
2312 tprintf(", %lu", tcp->u_arg[2]);
2313 }
2314 return 0;
2315}
2316
Michal Ludvig53b320f2002-09-23 13:30:09 +00002317#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002318
Roland McGrath40542842004-01-13 09:47:49 +00002319#if defined FREEBSD || defined LINUX
Roland McGratha4d48532005-06-08 20:45:28 +00002320static const struct xlat direnttypes[] = {
Roland McGrath40542842004-01-13 09:47:49 +00002321 { DT_UNKNOWN, "DT_UNKNOWN" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002322 { DT_FIFO, "DT_FIFO" },
2323 { DT_CHR, "DT_CHR" },
2324 { DT_DIR, "DT_DIR" },
2325 { DT_BLK, "DT_BLK" },
2326 { DT_REG, "DT_REG" },
2327 { DT_LNK, "DT_LNK" },
2328 { DT_SOCK, "DT_SOCK" },
2329 { DT_WHT, "DT_WHT" },
2330 { 0, NULL },
2331};
2332
2333#endif
2334
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002335int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002336sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002337{
2338 int i, len, dents = 0;
2339 char *buf;
2340
2341 if (entering(tcp)) {
2342 tprintf("%lu, ", tcp->u_arg[0]);
2343 return 0;
2344 }
2345 if (syserror(tcp) || !verbose(tcp)) {
2346 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2347 return 0;
2348 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002349 len = tcp->u_rval;
2350 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002351 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2352 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002353 return 0;
2354 }
2355 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002356 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002357 free(buf);
2358 return 0;
2359 }
2360 if (!abbrev(tcp))
2361 tprintf("{");
2362 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002363 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002364#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002365 if (!abbrev(tcp)) {
2366 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2367 i ? " " : "", d->d_ino, d->d_off);
2368 tprintf("d_reclen=%u, d_name=\"%s\"}",
2369 d->d_reclen, d->d_name);
2370 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002371#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002372#ifdef SVR4
2373 if (!abbrev(tcp)) {
2374 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002375 i ? " " : "",
2376 (unsigned long) d->d_ino,
2377 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002378 tprintf("d_reclen=%u, d_name=\"%s\"}",
2379 d->d_reclen, d->d_name);
2380 }
2381#endif /* SVR4 */
2382#ifdef SUNOS4
2383 if (!abbrev(tcp)) {
2384 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2385 i ? " " : "", d->d_off, d->d_fileno,
2386 d->d_reclen);
2387 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2388 d->d_namlen, d->d_namlen, d->d_name);
2389 }
2390#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002391#ifdef FREEBSD
2392 if (!abbrev(tcp)) {
2393 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2394 i ? " " : "", d->d_fileno, d->d_reclen);
2395 printxval(direnttypes, d->d_type, "DT_???");
2396 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2397 d->d_namlen, d->d_namlen, d->d_name);
2398 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002399#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002400 if (!d->d_reclen) {
2401 tprintf("/* d_reclen == 0, problem here */");
2402 break;
2403 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002404 i += d->d_reclen;
2405 dents++;
2406 }
2407 if (!abbrev(tcp))
2408 tprintf("}");
2409 else
2410 tprintf("/* %u entries */", dents);
2411 tprintf(", %lu", tcp->u_arg[2]);
2412 free(buf);
2413 return 0;
2414}
2415
John Hughesbdf48f52001-03-06 15:08:09 +00002416
2417#if _LFS64_LARGEFILE
2418int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002419sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002420{
2421 int i, len, dents = 0;
2422 char *buf;
2423
2424 if (entering(tcp)) {
2425 tprintf("%lu, ", tcp->u_arg[0]);
2426 return 0;
2427 }
2428 if (syserror(tcp) || !verbose(tcp)) {
2429 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2430 return 0;
2431 }
2432 len = tcp->u_rval;
2433 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002434 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2435 fprintf(stderr, "out of memory\n");
John Hughesbdf48f52001-03-06 15:08:09 +00002436 return 0;
2437 }
2438 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002439 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002440 free(buf);
2441 return 0;
2442 }
2443 if (!abbrev(tcp))
2444 tprintf("{");
2445 for (i = 0; i < len;) {
2446 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002447#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002448 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002449 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002450 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002451 d->d_ino,
2452 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002453#ifdef LINUX
2454 tprintf("d_type=");
2455 printxval(direnttypes, d->d_type, "DT_???");
2456 tprintf(", ");
2457#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002458 tprintf("d_reclen=%u, d_name=\"%s\"}",
2459 d->d_reclen, d->d_name);
2460 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002461#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002462#ifdef SUNOS4
2463 if (!abbrev(tcp)) {
2464 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2465 i ? " " : "", d->d_off, d->d_fileno,
2466 d->d_reclen);
2467 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2468 d->d_namlen, d->d_namlen, d->d_name);
2469 }
2470#endif /* SUNOS4 */
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002471 if (!d->d_reclen) {
2472 tprintf("/* d_reclen == 0, problem here */");
2473 break;
2474 }
John Hughesbdf48f52001-03-06 15:08:09 +00002475 i += d->d_reclen;
2476 dents++;
2477 }
2478 if (!abbrev(tcp))
2479 tprintf("}");
2480 else
2481 tprintf("/* %u entries */", dents);
2482 tprintf(", %lu", tcp->u_arg[2]);
2483 free(buf);
2484 return 0;
2485}
2486#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002487
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002488#ifdef FREEBSD
2489int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002490sys_getdirentries(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002491{
2492 int i, len, dents = 0;
2493 long basep;
2494 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002495
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002496 if (entering(tcp)) {
2497 tprintf("%lu, ", tcp->u_arg[0]);
2498 return 0;
2499 }
2500 if (syserror(tcp) || !verbose(tcp)) {
2501 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2502 return 0;
2503 }
2504 len = tcp->u_rval;
2505 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002506 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2507 fprintf(stderr, "out of memory\n");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002508 return 0;
2509 }
2510 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002511 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002512 free(buf);
2513 return 0;
2514 }
2515 if (!abbrev(tcp))
2516 tprintf("{");
2517 for (i = 0; i < len;) {
2518 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2519 if (!abbrev(tcp)) {
2520 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2521 i ? " " : "", d->d_fileno, d->d_reclen);
2522 printxval(direnttypes, d->d_type, "DT_???");
2523 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2524 d->d_namlen, d->d_namlen, d->d_name);
2525 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002526 if (!d->d_reclen) {
2527 tprintf("/* d_reclen == 0, problem here */");
2528 break;
2529 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002530 i += d->d_reclen;
2531 dents++;
2532 }
2533 if (!abbrev(tcp))
2534 tprintf("}");
2535 else
2536 tprintf("/* %u entries */", dents);
2537 free(buf);
2538 tprintf(", %lu", tcp->u_arg[2]);
2539 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2540 tprintf(", %#lx", tcp->u_arg[3]);
2541 else
2542 tprintf(", [%lu]", basep);
2543 return 0;
2544}
2545#endif
2546
Michal Ludvig53b320f2002-09-23 13:30:09 +00002547#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002548int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002549sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002550{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002551 if (exiting(tcp)) {
2552 if (syserror(tcp))
2553 tprintf("%#lx", tcp->u_arg[0]);
2554 else
2555 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2556 tprintf(", %lu", tcp->u_arg[1]);
2557 }
2558 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002559}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002560#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002561
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002562#ifdef FREEBSD
2563int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002564sys___getcwd(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002565{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002566 if (exiting(tcp)) {
2567 if (syserror(tcp))
2568 tprintf("%#lx", tcp->u_arg[0]);
2569 else
2570 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2571 tprintf(", %lu", tcp->u_arg[1]);
2572 }
2573 return 0;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002574}
2575#endif
2576
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002577#ifdef HAVE_SYS_ASYNCH_H
2578
2579int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002580sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002581{
2582 struct aio_result_t res;
2583
2584 if (entering(tcp)) {
2585 tprintf("%lu, ", tcp->u_arg[0]);
2586 } else {
2587 if (syserror(tcp))
2588 tprintf("%#lx", tcp->u_arg[1]);
2589 else
2590 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2591 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2592 printxval(whence, tcp->u_arg[4], "L_???");
2593 if (syserror(tcp) || tcp->u_arg[5] == 0
2594 || umove(tcp, tcp->u_arg[5], &res) < 0)
2595 tprintf(", %#lx", tcp->u_arg[5]);
2596 else
2597 tprintf(", {aio_return %d aio_errno %d}",
2598 res.aio_return, res.aio_errno);
2599 }
2600 return 0;
2601}
2602
2603int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002604sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002605{
2606 struct aio_result_t res;
2607
2608 if (entering(tcp)) {
2609 tprintf("%lu, ", tcp->u_arg[0]);
2610 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2611 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2612 printxval(whence, tcp->u_arg[4], "L_???");
2613 }
2614 else {
2615 if (tcp->u_arg[5] == 0)
2616 tprintf(", NULL");
2617 else if (syserror(tcp)
2618 || umove(tcp, tcp->u_arg[5], &res) < 0)
2619 tprintf(", %#lx", tcp->u_arg[5]);
2620 else
2621 tprintf(", {aio_return %d aio_errno %d}",
2622 res.aio_return, res.aio_errno);
2623 }
2624 return 0;
2625}
2626
2627int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002628sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002629{
2630 if (entering(tcp))
2631 printtv(tcp, tcp->u_arg[0]);
2632 return 0;
2633}
2634
2635int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002636sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002637{
2638 struct aio_result_t res;
2639
2640 if (exiting(tcp)) {
2641 if (tcp->u_arg[0] == 0)
2642 tprintf("NULL");
2643 else if (syserror(tcp)
2644 || umove(tcp, tcp->u_arg[0], &res) < 0)
2645 tprintf("%#lx", tcp->u_arg[0]);
2646 else
2647 tprintf("{aio_return %d aio_errno %d}",
2648 res.aio_return, res.aio_errno);
2649 }
2650 return 0;
2651}
2652
2653#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002654
Roland McGratha4d48532005-06-08 20:45:28 +00002655static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002656#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002657 { XATTR_CREATE, "XATTR_CREATE" },
2658 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002659#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002660 { 0, NULL }
2661};
2662
Roland McGrath3292e222004-08-31 06:30:48 +00002663static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002664print_xattr_val(struct tcb *tcp, int failed,
2665 unsigned long arg,
2666 unsigned long insize,
2667 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002668{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002669 if (!failed) {
2670 unsigned long capacity = 4 * size + 1;
2671 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2672 if (buf == NULL || /* probably a bogus size argument */
2673 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2674 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002675 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002676 else {
2677 unsigned char *out = buf;
2678 unsigned char *in = &buf[3 * size];
2679 size_t i;
2680 for (i = 0; i < size; ++i) {
2681 if (isprint(in[i]))
2682 *out++ = in[i];
2683 else {
2684#define tohex(n) "0123456789abcdef"[n]
2685 *out++ = '\\';
2686 *out++ = 'x';
2687 *out++ = tohex(in[i] / 16);
2688 *out++ = tohex(in[i] % 16);
2689 }
2690 }
2691 /* Don't print terminating NUL if there is one. */
2692 if (i > 0 && in[i - 1] == '\0')
2693 out -= 4;
2694 *out = '\0';
2695 tprintf(", \"%s\", %ld", buf, insize);
2696 }
2697 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002698 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002699 if (failed)
2700 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002701}
2702
Roland McGrath186c5ac2002-12-15 23:58:23 +00002703int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002704sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002705{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002706 if (entering(tcp)) {
2707 printpath(tcp, tcp->u_arg[0]);
2708 tprintf(", ");
2709 printstr(tcp, tcp->u_arg[1], -1);
2710 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2711 tprintf(", ");
2712 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2713 }
2714 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002715}
2716
2717int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002718sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002719{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002720 if (entering(tcp)) {
2721 tprintf("%ld, ", tcp->u_arg[0]);
2722 printstr(tcp, tcp->u_arg[1], -1);
2723 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2724 tprintf(", ");
2725 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2726 }
2727 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002728}
2729
2730int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002731sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002732{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002733 if (entering(tcp)) {
2734 printpath(tcp, tcp->u_arg[0]);
2735 tprintf(", ");
2736 printstr(tcp, tcp->u_arg[1], -1);
2737 } else {
2738 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2739 tcp->u_rval);
2740 }
2741 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002742}
2743
2744int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002745sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002746{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002747 if (entering(tcp)) {
2748 tprintf("%ld, ", tcp->u_arg[0]);
2749 printstr(tcp, tcp->u_arg[1], -1);
2750 } else {
2751 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2752 tcp->u_rval);
2753 }
2754 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002755}
2756
2757int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002758sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002759{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002760 if (entering(tcp)) {
2761 printpath(tcp, tcp->u_arg[0]);
2762 } else {
2763 /* XXX Print value in format */
2764 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2765 }
2766 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002767}
2768
2769int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002770sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002771{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002772 if (entering(tcp)) {
2773 tprintf("%ld", tcp->u_arg[0]);
2774 } else {
2775 /* XXX Print value in format */
2776 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2777 }
2778 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002779}
2780
2781int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002782sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002783{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002784 if (entering(tcp)) {
2785 printpath(tcp, tcp->u_arg[0]);
2786 tprintf(", ");
2787 printstr(tcp, tcp->u_arg[1], -1);
2788 }
2789 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002790}
2791
2792int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002793sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002794{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002795 if (entering(tcp)) {
2796 tprintf("%ld, ", tcp->u_arg[0]);
2797 printstr(tcp, tcp->u_arg[1], -1);
2798 }
2799 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002800}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002801
2802
2803static const struct xlat advise[] = {
2804 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2805 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2806 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2807 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2808 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2809 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2810 { 0, NULL }
2811};
2812
2813
Roland McGrathe27ed342004-10-20 02:24:19 +00002814#ifdef LINUX
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002815int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002816sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002817{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002818 if (entering(tcp)) {
2819 tprintf("%ld, %lld, %ld, ",
2820 tcp->u_arg[0],
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002821# if defined IA64 || defined X86_64 || defined ALPHA
Denys Vlasenko1d632462009-04-14 12:51:00 +00002822 (long long int) tcp->u_arg[1], tcp->u_arg[2]);
2823 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002824#else
Denys Vlasenko1d632462009-04-14 12:51:00 +00002825 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
2826 printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002827#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002828 }
2829 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002830}
2831#endif
2832
2833
2834int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002835sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002836{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002837 if (entering(tcp)) {
2838 tprintf("%ld, %lld, %lld, ",
2839 tcp->u_arg[0],
Roland McGrath542c2c62008-05-20 01:11:56 +00002840#if defined LINUX_MIPSN32
Denys Vlasenko1d632462009-04-14 12:51:00 +00002841 tcp->ext_arg[1], tcp->ext_arg[2]);
2842 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
Roland McGrath542c2c62008-05-20 01:11:56 +00002843#elif defined IA64 || defined X86_64 || defined ALPHA || defined LINUX_MIPSN64
Denys Vlasenko1d632462009-04-14 12:51:00 +00002844 (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
2845 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002846#else
Denys Vlasenko1d632462009-04-14 12:51:00 +00002847 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
2848 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
2849 printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002850#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002851 }
2852 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002853}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002854
2855#ifdef LINUX
2856static const struct xlat inotify_modes[] = {
2857 { 0x00000001, "IN_ACCESS" },
2858 { 0x00000002, "IN_MODIFY" },
2859 { 0x00000004, "IN_ATTRIB" },
2860 { 0x00000008, "IN_CLOSE_WRITE" },
2861 { 0x00000010, "IN_CLOSE_NOWRITE" },
2862 { 0x00000020, "IN_OPEN" },
2863 { 0x00000040, "IN_MOVED_FROM" },
2864 { 0x00000080, "IN_MOVED_TO" },
2865 { 0x00000100, "IN_CREATE" },
2866 { 0x00000200, "IN_DELETE" },
2867 { 0x00000400, "IN_DELETE_SELF" },
2868 { 0x00000800, "IN_MOVE_SELF" },
2869 { 0x00002000, "IN_UNMOUNT" },
2870 { 0x00004000, "IN_Q_OVERFLOW" },
2871 { 0x00008000, "IN_IGNORED" },
2872 { 0x01000000, "IN_ONLYDIR" },
2873 { 0x02000000, "IN_DONT_FOLLOW" },
2874 { 0x20000000, "IN_MASK_ADD" },
2875 { 0x40000000, "IN_ISDIR" },
2876 { 0x80000000, "IN_ONESHOT" }
2877};
2878
2879int
2880sys_inotify_add_watch(struct tcb *tcp)
2881{
2882 if (entering(tcp)) {
2883 tprintf("%ld, ", tcp->u_arg[0]);
2884 printpath(tcp, tcp->u_arg[1]);
2885 tprintf(", ");
2886 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2887 }
2888 return 0;
2889}
2890
2891int
2892sys_inotify_rm_watch(struct tcb *tcp)
2893{
2894 if (entering(tcp)) {
2895 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
2896 }
2897 return 0;
2898}
Roland McGrath96a96612008-05-20 04:56:18 +00002899
2900int
2901sys_fallocate(struct tcb *tcp)
2902{
2903 if (entering(tcp)) {
2904 tprintf("%ld, ", tcp->u_arg[0]); /* fd */
2905 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
2906 tprintf("%llu, ", LONG_LONG(tcp->u_arg[2],
2907 tcp->u_arg[3])); /* offset */
2908 tprintf("%llu", LONG_LONG(tcp->u_arg[4],
2909 tcp->u_arg[5])); /* len */
2910 }
2911 return 0;
2912}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002913#endif