blob: ec327b08b97b14eeb44071c87117c9f3b8e994bf [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
Michal Ludvig53b320f2002-09-23 13:30:09 +00002#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
4 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
5 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00006 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00007 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * $Id$
32 */
33
34#include "defs.h"
35
36#include <dirent.h>
Michal Ludvig53b320f2002-09-23 13:30:09 +000037#ifdef LINUX
Wichert Akkerman9524bb91999-05-25 23:11:18 +000038#define dirent kernel_dirent
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +000039#define dirent64 kernel_dirent64
Wichert Akkerman9524bb91999-05-25 23:11:18 +000040#include <linux/types.h>
41#include <linux/dirent.h>
42#undef dirent
Michal Ludvig10a88d02002-10-07 14:31:00 +000043#undef dirent64
Wichert Akkerman9524bb91999-05-25 23:11:18 +000044#else
45#define kernel_dirent dirent
46#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
241#ifdef O_NDELAY
242 { 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/*
341 * low bits of the open(2) flags define access mode,
342 * other bits are real flags.
343 */
344void
345tprint_open_modes(struct tcb *tcp, mode_t flags)
346{
347 const char *str = xlookup(open_access_modes, flags & 3);
348
349 if (str)
350 {
351 tprintf("%s", str);
352 flags &= ~3;
353 if (!flags)
354 return;
355 tprintf("|");
356 }
357 printflags(open_mode_flags, flags, "O_???");
358}
359
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000360static int
361decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000362{
363 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000364 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000365 tprintf(", ");
366 /* flags */
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000367 tprint_open_modes(tcp, tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000368 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000369 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000370 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000371 }
372 }
373 return 0;
374}
375
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000376int
377sys_open(struct tcb *tcp)
378{
379 return decode_open(tcp, 0);
380}
381
382#ifdef LINUX
383int
384sys_openat(struct tcb *tcp)
385{
386 if (entering(tcp))
387 print_dirfd(tcp->u_arg[0]);
388 return decode_open(tcp, 1);
389}
390#endif
391
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000392#ifdef LINUXSPARC
Roland McGratha4d48532005-06-08 20:45:28 +0000393static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000394 { 0, "O_RDWR" },
395 { 1, "O_RDONLY" },
396 { 2, "O_WRONLY" },
397 { 0x80, "O_NONBLOCK" },
398 { 8, "O_APPEND" },
399 { 0x100, "O_CREAT" },
400 { 0x200, "O_TRUNC" },
401 { 0x400, "O_EXCL" },
402 { 0x800, "O_NOCTTY" },
403 { 0x10, "O_SYNC" },
404 { 0x40, "O_DSYNC" },
405 { 0x8000, "O_RSYNC" },
406 { 4, "O_NDELAY" },
407 { 0x1000, "O_PRIV" },
408 { 0, NULL },
409};
410
411int
412solaris_open(tcp)
413struct tcb *tcp;
414{
415 if (entering(tcp)) {
416 printpath(tcp, tcp->u_arg[0]);
417 tprintf(", ");
418 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000419 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000420 if (tcp->u_arg[1] & 0x100) {
421 /* mode */
422 tprintf(", %#lo", tcp->u_arg[2]);
423 }
424 }
425 return 0;
426}
427
428#endif
429
430int
431sys_creat(tcp)
432struct tcb *tcp;
433{
434 if (entering(tcp)) {
435 printpath(tcp, tcp->u_arg[0]);
436 tprintf(", %#lo", tcp->u_arg[1]);
437 }
438 return 0;
439}
440
Roland McGrathd9f816f2004-09-04 03:39:20 +0000441static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000442 { F_OK, "F_OK", },
443 { R_OK, "R_OK" },
444 { W_OK, "W_OK" },
445 { X_OK, "X_OK" },
446#ifdef EFF_ONLY_OK
447 { EFF_ONLY_OK, "EFF_ONLY_OK" },
448#endif
449#ifdef EX_OK
450 { EX_OK, "EX_OK" },
451#endif
452 { 0, NULL },
453};
454
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000455static int
456decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000457{
458 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000459 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000460 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000461 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000462 }
463 return 0;
464}
465
466int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000467sys_access(struct tcb *tcp)
468{
469 return decode_access(tcp, 0);
470}
471
472#ifdef LINUX
473int
474sys_faccessat(struct tcb *tcp)
475{
476 if (entering(tcp))
477 print_dirfd(tcp->u_arg[0]);
478 return decode_access(tcp, 1);
479}
480#endif
481
482int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000483sys_umask(tcp)
484struct tcb *tcp;
485{
486 if (entering(tcp)) {
487 tprintf("%#lo", tcp->u_arg[0]);
488 }
489 return RVAL_OCTAL;
490}
491
Roland McGrathd9f816f2004-09-04 03:39:20 +0000492static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000493 { SEEK_SET, "SEEK_SET" },
494 { SEEK_CUR, "SEEK_CUR" },
495 { SEEK_END, "SEEK_END" },
496 { 0, NULL },
497};
498
John Hughes70623be2001-03-08 13:59:00 +0000499#ifndef HAVE_LONG_LONG_OFF_T
Roland McGrath542c2c62008-05-20 01:11:56 +0000500#if defined (LINUX_MIPSN32)
501int
502sys_lseek(tcp)
503struct tcb *tcp;
504{
505 long long offset;
506 int _whence;
507
508 if (entering(tcp)) {
509 tprintf("%ld, ", tcp->u_arg[0]);
510 offset = tcp->ext_arg[1];
511 _whence = tcp->u_arg[2];
512 if (_whence == SEEK_SET)
513 tprintf("%llu, ", offset);
514 else
515 tprintf("%lld, ", offset);
516 printxval(whence, _whence, "SEEK_???");
517 }
518 return RVAL_UDECIMAL;
519}
520#else /* !LINUX_MIPSN32 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000521int
522sys_lseek(tcp)
523struct tcb *tcp;
524{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000525 off_t offset;
526 int _whence;
527
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000528 if (entering(tcp)) {
529 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000530 offset = tcp->u_arg[1];
531 _whence = tcp->u_arg[2];
532 if (_whence == SEEK_SET)
533 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000534 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000535 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000536 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000537 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000538 return RVAL_UDECIMAL;
539}
Roland McGrath542c2c62008-05-20 01:11:56 +0000540#endif /* LINUX_MIPSN32 */
John Hughes5a826b82001-03-07 13:21:24 +0000541#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000542
Michal Ludvig53b320f2002-09-23 13:30:09 +0000543#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000544int
545sys_llseek (tcp)
546struct tcb *tcp;
547{
548 if (entering(tcp)) {
Roland McGrath8c304bc2004-10-19 22:59:55 +0000549 /*
550 * This one call takes explicitly two 32-bit arguments hi, lo,
551 * rather than one 64-bit argument for which LONG_LONG works
552 * appropriate for the native byte order.
553 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000554 if (tcp->u_arg[4] == SEEK_SET)
555 tprintf("%ld, %llu, ", tcp->u_arg[0],
Roland McGrath8c304bc2004-10-19 22:59:55 +0000556 (((long long int) tcp->u_arg[1]) << 32
557 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558 else
559 tprintf("%ld, %lld, ", tcp->u_arg[0],
Roland McGrath8c304bc2004-10-19 22:59:55 +0000560 (((long long int) tcp->u_arg[1]) << 32
561 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000562 }
563 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000564 long long int off;
565 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000566 tprintf("%#lx, ", tcp->u_arg[3]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000567 else
568 tprintf("[%llu], ", off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000569 printxval(whence, tcp->u_arg[4], "SEEK_???");
570 }
571 return 0;
572}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000573
574int
575sys_readahead (tcp)
576struct tcb *tcp;
577{
578 if (entering(tcp)) {
579 tprintf("%ld, %lld, %ld", tcp->u_arg[0],
Roland McGrath542c2c62008-05-20 01:11:56 +0000580# if defined LINUX_MIPSN32
581 tcp->ext_arg[1], tcp->u_arg[2]
582# elif defined IA64 || defined X86_64 || defined ALPHA || defined LINUX_MIPSN64
Roland McGrath186c5ac2002-12-15 23:58:23 +0000583 (long long int) tcp->u_arg[1], tcp->u_arg[2]
584# else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +0000585 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]
Roland McGrath186c5ac2002-12-15 23:58:23 +0000586# endif
587 );
588 }
589 return 0;
590}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000591#endif
592
John Hughes70623be2001-03-08 13:59:00 +0000593#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000594int
595sys_lseek64 (tcp)
596struct tcb *tcp;
597{
598 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000599 long long offset;
600 ALIGN64 (tcp, 1); /* FreeBSD aligns off_t args */
John Hughes0c79e012001-03-08 14:40:06 +0000601 offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +0000602 if (tcp->u_arg[3] == SEEK_SET)
603 tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
604 else
605 tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
606 printxval(whence, tcp->u_arg[3], "SEEK_???");
607 }
608 return RVAL_LUDECIMAL;
609}
610#endif
611
John Hughes70623be2001-03-08 13:59:00 +0000612#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000613int
614sys_truncate(tcp)
615struct tcb *tcp;
616{
617 if (entering(tcp)) {
618 printpath(tcp, tcp->u_arg[0]);
619 tprintf(", %lu", tcp->u_arg[1]);
620 }
621 return 0;
622}
John Hughes5a826b82001-03-07 13:21:24 +0000623#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000624
John Hughes70623be2001-03-08 13:59:00 +0000625#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000626int
627sys_truncate64(tcp)
628struct tcb *tcp;
629{
630 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000631 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000632 printpath(tcp, tcp->u_arg[0]);
John Hughes0c79e012001-03-08 14:40:06 +0000633 tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000634 }
635 return 0;
636}
637#endif
638
John Hughes70623be2001-03-08 13:59:00 +0000639#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000640int
641sys_ftruncate(tcp)
642struct tcb *tcp;
643{
644 if (entering(tcp)) {
645 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
646 }
647 return 0;
648}
John Hughes5a826b82001-03-07 13:21:24 +0000649#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000650
John Hughes70623be2001-03-08 13:59:00 +0000651#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000652int
653sys_ftruncate64(tcp)
654struct tcb *tcp;
655{
656 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000657 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000658 tprintf("%ld, %llu", tcp->u_arg[0],
John Hughes0c79e012001-03-08 14:40:06 +0000659 LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000660 }
661 return 0;
662}
663#endif
664
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000665/* several stats */
666
Roland McGrathd9f816f2004-09-04 03:39:20 +0000667static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000668 { S_IFREG, "S_IFREG" },
669 { S_IFSOCK, "S_IFSOCK" },
670 { S_IFIFO, "S_IFIFO" },
671 { S_IFLNK, "S_IFLNK" },
672 { S_IFDIR, "S_IFDIR" },
673 { S_IFBLK, "S_IFBLK" },
674 { S_IFCHR, "S_IFCHR" },
675 { 0, NULL },
676};
677
Roland McGrathf9c49b22004-10-06 22:11:54 +0000678static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000679sprintmode(mode)
680int mode;
681{
682 static char buf[64];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000683 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000684
685 if ((mode & S_IFMT) == 0)
686 s = "";
687 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
688 sprintf(buf, "%#o", mode);
689 return buf;
690 }
691 sprintf(buf, "%s%s%s%s", s,
692 (mode & S_ISUID) ? "|S_ISUID" : "",
693 (mode & S_ISGID) ? "|S_ISGID" : "",
694 (mode & S_ISVTX) ? "|S_ISVTX" : "");
695 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
696 if (mode)
697 sprintf(buf + strlen(buf), "|%#o", mode);
698 s = (*buf == '|') ? buf + 1 : buf;
699 return *s ? s : "0";
700}
701
702static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000703sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000704{
705 struct tm *tmp;
706 static char buf[32];
707
708 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000709 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000710 return buf;
711 }
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000712 if ((tmp = localtime(&t)))
713 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
714 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
715 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
716 else
717 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
718
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000719 return buf;
720}
721
722#ifdef LINUXSPARC
723typedef struct {
724 int tv_sec;
725 int tv_nsec;
726} timestruct_t;
727
728struct solstat {
729 unsigned st_dev;
730 int st_pad1[3]; /* network id */
731 unsigned st_ino;
732 unsigned st_mode;
733 unsigned st_nlink;
734 unsigned st_uid;
735 unsigned st_gid;
736 unsigned st_rdev;
737 int st_pad2[2];
738 int st_size;
739 int st_pad3; /* st_size, off_t expansion */
740 timestruct_t st_atime;
741 timestruct_t st_mtime;
742 timestruct_t st_ctime;
743 int st_blksize;
744 int st_blocks;
745 char st_fstype[16];
746 int st_pad4[8]; /* expansion area */
747};
748
749static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000750printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000751{
752 struct solstat statbuf;
753
754 if (!addr) {
755 tprintf("NULL");
756 return;
757 }
758 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000759 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000760 return;
761 }
762 if (umove(tcp, addr, &statbuf) < 0) {
763 tprintf("{...}");
764 return;
765 }
766 if (!abbrev(tcp)) {
767 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
768 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
769 (unsigned long) (statbuf.st_dev & 0x3ffff),
770 (unsigned long) statbuf.st_ino,
771 sprintmode(statbuf.st_mode));
772 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
773 (unsigned long) statbuf.st_nlink,
774 (unsigned long) statbuf.st_uid,
775 (unsigned long) statbuf.st_gid);
776 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
777 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
778 }
779 else
780 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
781 switch (statbuf.st_mode & S_IFMT) {
782 case S_IFCHR: case S_IFBLK:
783 tprintf("st_rdev=makedev(%lu, %lu), ",
784 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
785 (unsigned long) (statbuf.st_rdev & 0x3ffff));
786 break;
787 default:
788 tprintf("st_size=%u, ", statbuf.st_size);
789 break;
790 }
791 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000792 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
793 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
794 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000795 }
796 else
797 tprintf("...}");
798}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000799
800#if defined (SPARC64)
801static void
802printstat_sparc64(tcp, addr)
803struct tcb *tcp;
804long addr;
805{
806 struct stat_sparc64 statbuf;
807
808 if (!addr) {
809 tprintf("NULL");
810 return;
811 }
812 if (syserror(tcp) || !verbose(tcp)) {
813 tprintf("%#lx", addr);
814 return;
815 }
816 if (umove(tcp, addr, &statbuf) < 0) {
817 tprintf("{...}");
818 return;
819 }
820
821 if (!abbrev(tcp)) {
822 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
823 (unsigned long) major(statbuf.st_dev),
824 (unsigned long) minor(statbuf.st_dev),
825 (unsigned long) statbuf.st_ino,
826 sprintmode(statbuf.st_mode));
827 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
828 (unsigned long) statbuf.st_nlink,
829 (unsigned long) statbuf.st_uid,
830 (unsigned long) statbuf.st_gid);
831 tprintf("st_blksize=%lu, ",
832 (unsigned long) statbuf.st_blksize);
833 tprintf("st_blocks=%lu, ",
834 (unsigned long) statbuf.st_blocks);
835 }
836 else
837 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
838 switch (statbuf.st_mode & S_IFMT) {
839 case S_IFCHR: case S_IFBLK:
840 tprintf("st_rdev=makedev(%lu, %lu), ",
841 (unsigned long) major(statbuf.st_rdev),
842 (unsigned long) minor(statbuf.st_rdev));
843 break;
844 default:
845 tprintf("st_size=%lu, ", statbuf.st_size);
846 break;
847 }
848 if (!abbrev(tcp)) {
849 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
850 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
851 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
852 tprintf("}");
853 }
854 else
855 tprintf("...}");
856}
857#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000858#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000859
Roland McGratha4d48532005-06-08 20:45:28 +0000860static const struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000861#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000862 { UF_NODUMP, "UF_NODUMP" },
863 { UF_IMMUTABLE, "UF_IMMUTABLE" },
864 { UF_APPEND, "UF_APPEND" },
865 { UF_OPAQUE, "UF_OPAQUE" },
866 { UF_NOUNLINK, "UF_NOUNLINK" },
867 { SF_ARCHIVED, "SF_ARCHIVED" },
868 { SF_IMMUTABLE, "SF_IMMUTABLE" },
869 { SF_APPEND, "SF_APPEND" },
870 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000871#elif UNIXWARE >= 2
872#ifdef _S_ISMLD
873 { _S_ISMLD, "_S_ISMLD" },
874#endif
875#ifdef _S_ISMOUNTED
876 { _S_ISMOUNTED, "_S_ISMOUNTED" },
877#endif
878#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000879 { 0, NULL },
880};
881
John Hughesc0fc3fd2001-03-08 16:10:40 +0000882#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000883int
884sys_chflags(tcp)
885struct tcb *tcp;
886{
887 if (entering(tcp)) {
888 printpath(tcp, tcp->u_arg[0]);
889 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000890 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000891 }
892 return 0;
893}
894
895int
896sys_fchflags(tcp)
897struct tcb *tcp;
898{
899 if (entering(tcp)) {
900 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000901 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000902 }
903 return 0;
904}
905#endif
906
John Hughes70623be2001-03-08 13:59:00 +0000907#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000908static void
909realprintstat(tcp, statbuf)
910struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000911struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000912{
913 if (!abbrev(tcp)) {
914 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
915 (unsigned long) major(statbuf->st_dev),
916 (unsigned long) minor(statbuf->st_dev),
917 (unsigned long) statbuf->st_ino,
918 sprintmode(statbuf->st_mode));
919 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
920 (unsigned long) statbuf->st_nlink,
921 (unsigned long) statbuf->st_uid,
922 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000923#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000924 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000925#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
926#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000927 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000928#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000929 }
930 else
931 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
932 switch (statbuf->st_mode & S_IFMT) {
933 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000934#ifdef HAVE_STRUCT_STAT_ST_RDEV
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000935 tprintf("st_rdev=makedev(%lu, %lu), ",
936 (unsigned long) major(statbuf->st_rdev),
937 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000938#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000939 tprintf("st_size=makedev(%lu, %lu), ",
940 (unsigned long) major(statbuf->st_size),
941 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000942#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000943 break;
944 default:
945 tprintf("st_size=%lu, ", statbuf->st_size);
946 break;
947 }
948 if (!abbrev(tcp)) {
949 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
950 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000951 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000952#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000953 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000954 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000955#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000956#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000957 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
958#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000959#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000960 tprintf(", st_level=%ld", statbuf->st_level);
961#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000962#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000963 tprintf(", st_fstype=%.*s",
964 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
965#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000966#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000967 tprintf(", st_gen=%u", statbuf->st_gen);
968#endif
969 tprintf("}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000970 }
971 else
972 tprintf("...}");
973}
974
Nate Sammons771a6ff1999-04-05 22:39:31 +0000975
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000976static void
977printstat(tcp, addr)
978struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000979long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000980{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000981 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000982
983#ifdef LINUXSPARC
984 if (current_personality == 1) {
985 printstatsol(tcp, addr);
986 return;
987 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000988#ifdef SPARC64
989 else if (current_personality == 2) {
990 printstat_sparc64(tcp, addr);
991 return;
992 }
993#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000994#endif /* LINUXSPARC */
995
996 if (!addr) {
997 tprintf("NULL");
998 return;
999 }
1000 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001001 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001002 return;
1003 }
1004 if (umove(tcp, addr, &statbuf) < 0) {
1005 tprintf("{...}");
1006 return;
1007 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001008
1009 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001010}
John Hughes70623be2001-03-08 13:59:00 +00001011#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001012
Roland McGrathe6d0f712007-08-07 01:22:49 +00001013#if !defined HAVE_STAT64 && defined LINUX && defined X86_64
1014/*
1015 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1016 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1017 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1018 * __GNUC__ is needed for the required __attribute__ below.
1019 */
1020struct stat64 {
1021 unsigned long long st_dev;
1022 unsigned char __pad0[4];
1023 unsigned int __st_ino;
1024 unsigned int st_mode;
1025 unsigned int st_nlink;
1026 unsigned int st_uid;
1027 unsigned int st_gid;
1028 unsigned long long st_rdev;
1029 unsigned char __pad3[4];
1030 long long st_size;
1031 unsigned int st_blksize;
1032 unsigned long long st_blocks;
1033 unsigned int st_atime;
1034 unsigned int st_atime_nsec;
1035 unsigned int st_mtime;
1036 unsigned int st_mtime_nsec;
1037 unsigned int st_ctime;
1038 unsigned int st_ctime_nsec;
1039 unsigned long long st_ino;
1040} __attribute__((packed));
1041# define HAVE_STAT64 1
1042# define STAT64_SIZE 96
1043#endif
1044
Wichert Akkermanc7926982000-04-10 22:22:31 +00001045#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001046static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001047printstat64(tcp, addr)
1048struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001049long addr;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001050{
1051 struct stat64 statbuf;
1052
Roland McGrathe6d0f712007-08-07 01:22:49 +00001053#ifdef STAT64_SIZE
1054 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1055#endif
1056
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001057#ifdef LINUXSPARC
1058 if (current_personality == 1) {
1059 printstatsol(tcp, addr);
1060 return;
1061 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001062#ifdef SPARC64
1063 else if (current_personality == 2) {
1064 printstat_sparc64(tcp, addr);
1065 return;
1066 }
1067#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001068#endif /* LINUXSPARC */
1069
1070 if (!addr) {
1071 tprintf("NULL");
1072 return;
1073 }
1074 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001075 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001076 return;
1077 }
1078 if (umove(tcp, addr, &statbuf) < 0) {
1079 tprintf("{...}");
1080 return;
1081 }
1082
1083 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001084#ifdef HAVE_LONG_LONG
1085 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1086#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001087 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001088#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001089 (unsigned long) major(statbuf.st_dev),
1090 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001091#ifdef HAVE_LONG_LONG
1092 (unsigned long long) statbuf.st_ino,
1093#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001094 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001095#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001096 sprintmode(statbuf.st_mode));
1097 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1098 (unsigned long) statbuf.st_nlink,
1099 (unsigned long) statbuf.st_uid,
1100 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001101#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001102 tprintf("st_blksize=%lu, ",
1103 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001104#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1105#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001106 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001107#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001108 }
1109 else
1110 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1111 switch (statbuf.st_mode & S_IFMT) {
1112 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001113#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001114 tprintf("st_rdev=makedev(%lu, %lu), ",
1115 (unsigned long) major(statbuf.st_rdev),
1116 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001117#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001118 tprintf("st_size=makedev(%lu, %lu), ",
1119 (unsigned long) major(statbuf.st_size),
1120 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001121#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001122 break;
1123 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001124#ifdef HAVE_LONG_LONG
1125 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1126#else
1127 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1128#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001129 break;
1130 }
1131 if (!abbrev(tcp)) {
1132 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1133 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001134 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001135#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +00001136 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001137 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001138#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001139#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001140 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1141#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001142#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001143 tprintf(", st_level=%ld", statbuf.st_level);
1144#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001145#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001146 tprintf(", st_fstype=%.*s",
1147 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1148#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001149#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001150 tprintf(", st_gen=%u", statbuf.st_gen);
1151#endif
1152 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001153 }
1154 else
1155 tprintf("...}");
1156}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001157#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001158
Roland McGrath79db8af2003-06-27 21:20:09 +00001159#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001160static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001161convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001162const struct __old_kernel_stat *oldbuf;
1163struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001164{
1165 newbuf->st_dev=oldbuf->st_dev;
1166 newbuf->st_ino=oldbuf->st_ino;
1167 newbuf->st_mode=oldbuf->st_mode;
1168 newbuf->st_nlink=oldbuf->st_nlink;
1169 newbuf->st_uid=oldbuf->st_uid;
1170 newbuf->st_gid=oldbuf->st_gid;
1171 newbuf->st_rdev=oldbuf->st_rdev;
1172 newbuf->st_size=oldbuf->st_size;
1173 newbuf->st_atime=oldbuf->st_atime;
1174 newbuf->st_mtime=oldbuf->st_mtime;
1175 newbuf->st_ctime=oldbuf->st_ctime;
1176 newbuf->st_blksize=0; /* not supported in old_stat */
1177 newbuf->st_blocks=0; /* not supported in old_stat */
1178}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001179
1180
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001181static void
1182printoldstat(tcp, addr)
1183struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001184long addr;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001185{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001186 struct __old_kernel_stat statbuf;
1187 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001188
1189#ifdef LINUXSPARC
1190 if (current_personality == 1) {
1191 printstatsol(tcp, addr);
1192 return;
1193 }
1194#endif /* LINUXSPARC */
1195
1196 if (!addr) {
1197 tprintf("NULL");
1198 return;
1199 }
1200 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001201 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001202 return;
1203 }
1204 if (umove(tcp, addr, &statbuf) < 0) {
1205 tprintf("{...}");
1206 return;
1207 }
1208
1209 convertoldstat(&statbuf, &newstatbuf);
1210 realprintstat(tcp, &newstatbuf);
1211}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001212#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001213
John Hughes70623be2001-03-08 13:59:00 +00001214#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001215int
1216sys_stat(tcp)
1217struct tcb *tcp;
1218{
1219 if (entering(tcp)) {
1220 printpath(tcp, tcp->u_arg[0]);
1221 tprintf(", ");
1222 } else {
1223 printstat(tcp, tcp->u_arg[1]);
1224 }
1225 return 0;
1226}
John Hughesb8c9f772001-03-07 16:53:07 +00001227#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001228
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001229int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001230sys_stat64(tcp)
1231struct tcb *tcp;
1232{
1233#ifdef HAVE_STAT64
1234 if (entering(tcp)) {
1235 printpath(tcp, tcp->u_arg[0]);
1236 tprintf(", ");
1237 } else {
1238 printstat64(tcp, tcp->u_arg[1]);
1239 }
1240 return 0;
1241#else
1242 return printargs(tcp);
1243#endif
1244}
1245
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001246#ifdef LINUX
1247static const struct xlat fstatatflags[] = {
1248#ifndef AT_SYMLINK_NOFOLLOW
1249# define AT_SYMLINK_NOFOLLOW 0x100
1250#endif
1251 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1252 { 0, NULL },
1253};
Roland McGrath6afc5652007-07-24 01:57:11 +00001254#define utimensatflags fstatatflags
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001255
1256int
1257sys_newfstatat(struct tcb *tcp)
1258{
1259 if (entering(tcp)) {
1260 print_dirfd(tcp->u_arg[0]);
1261 printpath(tcp, tcp->u_arg[1]);
1262 tprintf(", ");
1263 } else {
Roland McGrath359c8ed2007-07-05 19:01:17 +00001264#if defined HAVE_STAT64 && !(defined POWERPC && defined __powerpc64__)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001265 printstat64(tcp, tcp->u_arg[2]);
1266#else
1267 printstat(tcp, tcp->u_arg[2]);
1268#endif
1269 tprintf(", ");
1270 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1271 }
1272 return 0;
1273}
1274#endif
1275
Roland McGrath79db8af2003-06-27 21:20:09 +00001276#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001277int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001278sys_oldstat(tcp)
1279struct tcb *tcp;
1280{
1281 if (entering(tcp)) {
1282 printpath(tcp, tcp->u_arg[0]);
1283 tprintf(", ");
1284 } else {
1285 printoldstat(tcp, tcp->u_arg[1]);
1286 }
1287 return 0;
1288}
Roland McGrath79db8af2003-06-27 21:20:09 +00001289#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001290
John Hughes70623be2001-03-08 13:59:00 +00001291#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292int
1293sys_fstat(tcp)
1294struct tcb *tcp;
1295{
1296 if (entering(tcp))
1297 tprintf("%ld, ", tcp->u_arg[0]);
1298 else {
1299 printstat(tcp, tcp->u_arg[1]);
1300 }
1301 return 0;
1302}
John Hughesb8c9f772001-03-07 16:53:07 +00001303#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001304
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001305int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001306sys_fstat64(tcp)
1307struct tcb *tcp;
1308{
1309#ifdef HAVE_STAT64
1310 if (entering(tcp))
1311 tprintf("%ld, ", tcp->u_arg[0]);
1312 else {
1313 printstat64(tcp, tcp->u_arg[1]);
1314 }
1315 return 0;
1316#else
1317 return printargs(tcp);
1318#endif
1319}
1320
Roland McGrath79db8af2003-06-27 21:20:09 +00001321#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001322int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001323sys_oldfstat(tcp)
1324struct tcb *tcp;
1325{
1326 if (entering(tcp))
1327 tprintf("%ld, ", tcp->u_arg[0]);
1328 else {
1329 printoldstat(tcp, tcp->u_arg[1]);
1330 }
1331 return 0;
1332}
Roland McGrath79db8af2003-06-27 21:20:09 +00001333#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001334
John Hughes70623be2001-03-08 13:59:00 +00001335#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001336int
1337sys_lstat(tcp)
1338struct tcb *tcp;
1339{
1340 if (entering(tcp)) {
1341 printpath(tcp, tcp->u_arg[0]);
1342 tprintf(", ");
1343 } else {
1344 printstat(tcp, tcp->u_arg[1]);
1345 }
1346 return 0;
1347}
John Hughesb8c9f772001-03-07 16:53:07 +00001348#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001349
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001350int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001351sys_lstat64(tcp)
1352struct tcb *tcp;
1353{
1354#ifdef HAVE_STAT64
1355 if (entering(tcp)) {
1356 printpath(tcp, tcp->u_arg[0]);
1357 tprintf(", ");
1358 } else {
1359 printstat64(tcp, tcp->u_arg[1]);
1360 }
1361 return 0;
1362#else
1363 return printargs(tcp);
1364#endif
1365}
1366
Roland McGrath79db8af2003-06-27 21:20:09 +00001367#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001368int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001369sys_oldlstat(tcp)
1370struct tcb *tcp;
1371{
1372 if (entering(tcp)) {
1373 printpath(tcp, tcp->u_arg[0]);
1374 tprintf(", ");
1375 } else {
1376 printoldstat(tcp, tcp->u_arg[1]);
1377 }
1378 return 0;
1379}
Roland McGrath79db8af2003-06-27 21:20:09 +00001380#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001381
1382
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001383#if defined(SVR4) || defined(LINUXSPARC)
1384
1385int
1386sys_xstat(tcp)
1387struct tcb *tcp;
1388{
1389 if (entering(tcp)) {
1390 tprintf("%ld, ", tcp->u_arg[0]);
1391 printpath(tcp, tcp->u_arg[1]);
1392 tprintf(", ");
1393 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001394#ifdef _STAT64_VER
1395 if (tcp->u_arg[0] == _STAT64_VER)
1396 printstat64 (tcp, tcp->u_arg[2]);
1397 else
1398#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001399 printstat(tcp, tcp->u_arg[2]);
1400 }
1401 return 0;
1402}
1403
1404int
1405sys_fxstat(tcp)
1406struct tcb *tcp;
1407{
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
1422sys_lxstat(tcp)
1423struct tcb *tcp;
1424{
1425 if (entering(tcp)) {
1426 tprintf("%ld, ", tcp->u_arg[0]);
1427 printpath(tcp, tcp->u_arg[1]);
1428 tprintf(", ");
1429 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001430#ifdef _STAT64_VER
1431 if (tcp->u_arg[0] == _STAT64_VER)
1432 printstat64 (tcp, tcp->u_arg[2]);
1433 else
1434#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001435 printstat(tcp, tcp->u_arg[2]);
1436 }
1437 return 0;
1438}
1439
1440int
1441sys_xmknod(tcp)
1442struct tcb *tcp;
1443{
1444 int mode = tcp->u_arg[2];
1445
1446 if (entering(tcp)) {
1447 tprintf("%ld, ", tcp->u_arg[0]);
1448 printpath(tcp, tcp->u_arg[1]);
1449 tprintf(", %s", sprintmode(mode));
1450 switch (mode & S_IFMT) {
1451 case S_IFCHR: case S_IFBLK:
1452#ifdef LINUXSPARC
1453 tprintf(", makedev(%lu, %lu)",
1454 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1455 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001456#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001457 tprintf(", makedev(%lu, %lu)",
1458 (unsigned long) major(tcp->u_arg[3]),
1459 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001460#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001461 break;
1462 default:
1463 break;
1464 }
1465 }
1466 return 0;
1467}
1468
Wichert Akkerman8829a551999-06-11 13:18:40 +00001469#ifdef HAVE_SYS_ACL_H
1470
1471#include <sys/acl.h>
1472
Roland McGratha4d48532005-06-08 20:45:28 +00001473static const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001474#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001475 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001476#endif
1477#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001478 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001479#endif
1480#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001481 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001482#endif
1483#ifdef ACL_GET
1484 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001485#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001486#ifdef ACL_SET
1487 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001488#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001489#ifdef ACL_CNT
1490 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001491#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001492 { 0, NULL },
1493};
1494
1495int
1496sys_acl(tcp)
1497struct tcb *tcp;
1498{
1499 if (entering(tcp)) {
1500 printpath(tcp, tcp->u_arg[0]);
1501 tprintf(", ");
1502 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1503 tprintf(", %ld", tcp->u_arg[2]);
1504 /*
1505 * FIXME - dump out the list of aclent_t's pointed to
1506 * by "tcp->u_arg[3]" if it's not NULL.
1507 */
1508 if (tcp->u_arg[3])
1509 tprintf(", %#lx", tcp->u_arg[3]);
1510 else
1511 tprintf(", NULL");
1512 }
1513 return 0;
1514}
1515
1516
1517int
1518sys_facl(tcp)
1519struct tcb *tcp;
1520{
1521 if (entering(tcp)) {
1522 tprintf("%ld, ", tcp->u_arg[0]);
1523 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1524 tprintf(", %ld", tcp->u_arg[2]);
1525 /*
1526 * FIXME - dump out the list of aclent_t's pointed to
1527 * by "tcp->u_arg[3]" if it's not NULL.
1528 */
1529 if (tcp->u_arg[3])
1530 tprintf(", %#lx", tcp->u_arg[3]);
1531 else
1532 tprintf(", NULL");
1533 }
1534 return 0;
1535}
1536
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001537
Roland McGratha4d48532005-06-08 20:45:28 +00001538static const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001539#ifdef IPC_SHM
1540 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001541#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001542#ifdef IPC_SEM
1543 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001544#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001545#ifdef IPC_MSG
1546 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001547#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001548 { 0, NULL },
1549};
1550
1551
1552int
1553sys_aclipc(tcp)
1554struct tcb *tcp;
1555{
1556 if (entering(tcp)) {
1557 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1558 tprintf(", %#lx, ", tcp->u_arg[1]);
1559 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1560 tprintf(", %ld", tcp->u_arg[3]);
1561 /*
1562 * FIXME - dump out the list of aclent_t's pointed to
1563 * by "tcp->u_arg[4]" if it's not NULL.
1564 */
1565 if (tcp->u_arg[4])
1566 tprintf(", %#lx", tcp->u_arg[4]);
1567 else
1568 tprintf(", NULL");
1569 }
1570 return 0;
1571}
1572
1573
1574
Wichert Akkerman8829a551999-06-11 13:18:40 +00001575#endif /* HAVE_SYS_ACL_H */
1576
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001577#endif /* SVR4 || LINUXSPARC */
1578
Michal Ludvig53b320f2002-09-23 13:30:09 +00001579#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001580
Roland McGrathd9f816f2004-09-04 03:39:20 +00001581static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001582 { 0x73757245, "CODA_SUPER_MAGIC" },
1583 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1584 { 0x1373, "DEVFS_SUPER_MAGIC" },
1585 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1586 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001587 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1588 { 0xef53, "EXT2_SUPER_MAGIC" },
1589 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001590 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001591 { 0x9660, "ISOFS_SUPER_MAGIC" },
1592 { 0x137f, "MINIX_SUPER_MAGIC" },
1593 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001594 { 0x2468, "MINIX2_SUPER_MAGIC" },
1595 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001596 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001597 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001598 { 0x6969, "NFS_SUPER_MAGIC" },
1599 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001600 { 0x002f, "QNX4_SUPER_MAGIC" },
1601 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1602 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1603 { 0x517b, "SMB_SUPER_MAGIC" },
1604 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1605 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1606 { 0x00011954, "UFS_MAGIC" },
1607 { 0x54190100, "UFS_CIGAM" },
1608 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001609 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001610 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001611 { 0, NULL },
1612};
1613
Michal Ludvig53b320f2002-09-23 13:30:09 +00001614#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001615
1616#ifndef SVR4
1617
Roland McGrathf9c49b22004-10-06 22:11:54 +00001618static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001619sprintfstype(magic)
1620int magic;
1621{
1622 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001623#ifdef LINUX
Roland McGrathf9c49b22004-10-06 22:11:54 +00001624 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001625
1626 s = xlookup(fsmagic, magic);
1627 if (s) {
1628 sprintf(buf, "\"%s\"", s);
1629 return buf;
1630 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001631#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001632 sprintf(buf, "%#x", magic);
1633 return buf;
1634}
1635
1636static void
1637printstatfs(tcp, addr)
1638struct tcb *tcp;
1639long addr;
1640{
1641 struct statfs statbuf;
1642
1643 if (syserror(tcp) || !verbose(tcp)) {
1644 tprintf("%#lx", addr);
1645 return;
1646 }
1647 if (umove(tcp, addr, &statbuf) < 0) {
1648 tprintf("{...}");
1649 return;
1650 }
1651#ifdef ALPHA
1652
1653 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1654 sprintfstype(statbuf.f_type),
1655 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001656 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1657 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1658 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1659 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001660#else /* !ALPHA */
1661 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1662 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001663 (unsigned long)statbuf.f_bsize,
1664 (unsigned long)statbuf.f_blocks,
1665 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001666 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1667 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001668 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001669 (unsigned long)statbuf.f_ffree,
1670 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001671#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001672 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001673#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001674#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001675#ifdef _STATFS_F_FRSIZE
1676 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1677#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001678 tprintf("}");
1679}
1680
1681int
1682sys_statfs(tcp)
1683struct tcb *tcp;
1684{
1685 if (entering(tcp)) {
1686 printpath(tcp, tcp->u_arg[0]);
1687 tprintf(", ");
1688 } else {
1689 printstatfs(tcp, tcp->u_arg[1]);
1690 }
1691 return 0;
1692}
1693
1694int
1695sys_fstatfs(tcp)
1696struct tcb *tcp;
1697{
1698 if (entering(tcp)) {
1699 tprintf("%lu, ", tcp->u_arg[0]);
1700 } else {
1701 printstatfs(tcp, tcp->u_arg[1]);
1702 }
1703 return 0;
1704}
1705
Roland McGrathab147c52003-07-17 09:03:02 +00001706#ifdef LINUX
1707static void
1708printstatfs64(tcp, addr)
1709struct tcb *tcp;
1710long addr;
1711{
1712 struct statfs64 statbuf;
1713
1714 if (syserror(tcp) || !verbose(tcp)) {
1715 tprintf("%#lx", addr);
1716 return;
1717 }
1718 if (umove(tcp, addr, &statbuf) < 0) {
1719 tprintf("{...}");
1720 return;
1721 }
Roland McGrath08738432005-06-03 02:40:39 +00001722 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001723 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001724 (unsigned long long)statbuf.f_bsize,
1725 (unsigned long long)statbuf.f_blocks,
1726 (unsigned long long)statbuf.f_bfree);
1727 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1728 (unsigned long long)statbuf.f_bavail,
1729 (unsigned long long)statbuf.f_files,
1730 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001731 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1732 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001733#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001734 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001735#endif
1736 tprintf("}");
1737}
1738
1739int
1740sys_statfs64(tcp)
1741struct tcb *tcp;
1742{
1743 if (entering(tcp)) {
1744 printpath(tcp, tcp->u_arg[0]);
1745 tprintf(", %lu, ", tcp->u_arg[1]);
1746 } else {
1747 if (tcp->u_arg[1] == sizeof (struct statfs64))
1748 printstatfs64(tcp, tcp->u_arg[2]);
1749 else
1750 tprintf("{???}");
1751 }
1752 return 0;
1753}
1754
1755int
1756sys_fstatfs64(tcp)
1757struct tcb *tcp;
1758{
1759 if (entering(tcp)) {
1760 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1761 } else {
1762 if (tcp->u_arg[1] == sizeof (struct statfs64))
1763 printstatfs64(tcp, tcp->u_arg[2]);
1764 else
1765 tprintf("{???}");
1766 }
1767 return 0;
1768}
1769#endif
1770
Michal Ludvig53b320f2002-09-23 13:30:09 +00001771#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001772
1773int
1774osf_statfs(tcp)
1775struct tcb *tcp;
1776{
1777 if (entering(tcp)) {
1778 printpath(tcp, tcp->u_arg[0]);
1779 tprintf(", ");
1780 } else {
1781 printstatfs(tcp, tcp->u_arg[1]);
1782 tprintf(", %lu", tcp->u_arg[2]);
1783 }
1784 return 0;
1785}
1786
1787int
1788osf_fstatfs(tcp)
1789struct tcb *tcp;
1790{
1791 if (entering(tcp)) {
1792 tprintf("%lu, ", tcp->u_arg[0]);
1793 } else {
1794 printstatfs(tcp, tcp->u_arg[1]);
1795 tprintf(", %lu", tcp->u_arg[2]);
1796 }
1797 return 0;
1798}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001799#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001800
1801#endif /* !SVR4 */
1802
1803#ifdef SUNOS4
1804
1805int
1806sys_ustat(tcp)
1807struct tcb *tcp;
1808{
1809 struct ustat statbuf;
1810
1811 if (entering(tcp)) {
1812 tprintf("makedev(%lu, %lu), ",
1813 (long) major(tcp->u_arg[0]),
1814 (long) minor(tcp->u_arg[0]));
1815 }
1816 else {
1817 if (syserror(tcp) || !verbose(tcp))
1818 tprintf("%#lx", tcp->u_arg[1]);
1819 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1820 tprintf("{...}");
1821 else {
1822 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1823 statbuf.f_tfree, statbuf.f_tinode);
1824 tprintf("f_fname=\"%.*s\", ",
1825 (int) sizeof(statbuf.f_fname),
1826 statbuf.f_fname);
1827 tprintf("f_fpack=\"%.*s\"}",
1828 (int) sizeof(statbuf.f_fpack),
1829 statbuf.f_fpack);
1830 }
1831 }
1832 return 0;
1833}
1834
1835#endif /* SUNOS4 */
1836
Wichert Akkermanc7926982000-04-10 22:22:31 +00001837int
1838sys_pivotroot(tcp)
1839struct tcb *tcp;
1840{
1841 if (entering(tcp)) {
1842 printpath(tcp, tcp->u_arg[0]);
1843 tprintf(", ");
1844 printpath(tcp, tcp->u_arg[1]);
1845 }
1846 return 0;
1847}
1848
1849
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001850/* directory */
1851int
1852sys_chdir(tcp)
1853struct tcb *tcp;
1854{
1855 if (entering(tcp)) {
1856 printpath(tcp, tcp->u_arg[0]);
1857 }
1858 return 0;
1859}
1860
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001861static int
1862decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001863{
1864 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001865 printpath(tcp, tcp->u_arg[offset]);
1866 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001867 }
1868 return 0;
1869}
1870
1871int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001872sys_mkdir(struct tcb *tcp)
1873{
1874 return decode_mkdir(tcp, 0);
1875}
1876
1877#ifdef LINUX
1878int
1879sys_mkdirat(struct tcb *tcp)
1880{
1881 if (entering(tcp))
1882 print_dirfd(tcp->u_arg[0]);
1883 return decode_mkdir(tcp, 1);
1884}
1885#endif
1886
1887int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001888sys_rmdir(tcp)
1889struct tcb *tcp;
1890{
1891 if (entering(tcp)) {
1892 printpath(tcp, tcp->u_arg[0]);
1893 }
1894 return 0;
1895}
1896
1897int
1898sys_fchdir(tcp)
1899struct tcb *tcp;
1900{
1901 if (entering(tcp)) {
1902 tprintf("%ld", tcp->u_arg[0]);
1903 }
1904 return 0;
1905}
1906
1907int
1908sys_chroot(tcp)
1909struct tcb *tcp;
1910{
1911 if (entering(tcp)) {
1912 printpath(tcp, tcp->u_arg[0]);
1913 }
1914 return 0;
1915}
1916
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001917#if defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001918int
1919sys_fchroot(tcp)
1920struct tcb *tcp;
1921{
1922 if (entering(tcp)) {
1923 tprintf("%ld", tcp->u_arg[0]);
1924 }
1925 return 0;
1926}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001927#endif /* SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001928
1929int
1930sys_link(tcp)
1931struct tcb *tcp;
1932{
1933 if (entering(tcp)) {
1934 printpath(tcp, tcp->u_arg[0]);
1935 tprintf(", ");
1936 printpath(tcp, tcp->u_arg[1]);
1937 }
1938 return 0;
1939}
1940
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001941#ifdef LINUX
1942int
1943sys_linkat(struct tcb *tcp)
1944{
1945 if (entering(tcp)) {
1946 print_dirfd(tcp->u_arg[0]);
1947 printpath(tcp, tcp->u_arg[1]);
1948 tprintf(", ");
1949 print_dirfd(tcp->u_arg[2]);
1950 printpath(tcp, tcp->u_arg[3]);
1951 tprintf(", %ld", tcp->u_arg[4]);
1952 }
1953 return 0;
1954}
1955#endif
1956
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001957int
1958sys_unlink(tcp)
1959struct tcb *tcp;
1960{
1961 if (entering(tcp)) {
1962 printpath(tcp, tcp->u_arg[0]);
1963 }
1964 return 0;
1965}
1966
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001967#ifdef LINUX
1968static const struct xlat unlinkatflags[] = {
1969#ifndef AT_REMOVEDIR
1970# define AT_REMOVEDIR 0x200
1971#endif
1972 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1973 { 0, NULL },
1974};
1975
1976int
1977sys_unlinkat(struct tcb *tcp)
1978{
1979 if (entering(tcp)) {
1980 print_dirfd(tcp->u_arg[0]);
1981 printpath(tcp, tcp->u_arg[1]);
1982 tprintf(", ");
1983 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1984 }
1985 return 0;
1986}
1987#endif
1988
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001989int
1990sys_symlink(tcp)
1991struct tcb *tcp;
1992{
1993 if (entering(tcp)) {
1994 printpath(tcp, tcp->u_arg[0]);
1995 tprintf(", ");
1996 printpath(tcp, tcp->u_arg[1]);
1997 }
1998 return 0;
1999}
2000
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002001#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002002int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002003sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002004{
2005 if (entering(tcp)) {
2006 printpath(tcp, tcp->u_arg[0]);
2007 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002008 print_dirfd(tcp->u_arg[1]);
2009 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002010 }
2011 return 0;
2012}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002013#endif
2014
2015static int
2016decode_readlink(struct tcb *tcp, int offset)
2017{
2018 if (entering(tcp)) {
2019 printpath(tcp, tcp->u_arg[offset]);
2020 tprintf(", ");
2021 } else {
2022 if (syserror(tcp))
2023 tprintf("%#lx", tcp->u_arg[offset + 1]);
2024 else
2025 printpathn(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
2026 tprintf(", %lu", tcp->u_arg[offset + 2]);
2027 }
2028 return 0;
2029}
2030
2031int
2032sys_readlink(struct tcb *tcp)
2033{
2034 return decode_readlink(tcp, 0);
2035}
2036
2037#ifdef LINUX
2038int
2039sys_readlinkat(struct tcb *tcp)
2040{
2041 if (entering(tcp))
2042 print_dirfd(tcp->u_arg[0]);
2043 return decode_readlink(tcp, 1);
2044}
2045#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002046
2047int
2048sys_rename(tcp)
2049struct tcb *tcp;
2050{
2051 if (entering(tcp)) {
2052 printpath(tcp, tcp->u_arg[0]);
2053 tprintf(", ");
2054 printpath(tcp, tcp->u_arg[1]);
2055 }
2056 return 0;
2057}
2058
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002059#ifdef LINUX
2060int
2061sys_renameat(struct tcb *tcp)
2062{
2063 if (entering(tcp)) {
2064 print_dirfd(tcp->u_arg[0]);
2065 printpath(tcp, tcp->u_arg[1]);
2066 tprintf(", ");
2067 print_dirfd(tcp->u_arg[2]);
2068 printpath(tcp, tcp->u_arg[3]);
2069 }
2070 return 0;
2071}
2072#endif
2073
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002074int
2075sys_chown(tcp)
2076struct tcb *tcp;
2077{
2078 if (entering(tcp)) {
2079 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002080 printuid(", ", tcp->u_arg[1]);
2081 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002082 }
2083 return 0;
2084}
2085
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002086#ifdef LINUX
2087int
2088sys_fchownat(struct tcb *tcp)
2089{
2090 if (entering(tcp)) {
2091 print_dirfd(tcp->u_arg[0]);
2092 printpath(tcp, tcp->u_arg[1]);
2093 printuid(", ", tcp->u_arg[2]);
2094 printuid(", ", tcp->u_arg[3]);
2095 tprintf(", ");
2096 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
2097 }
2098 return 0;
2099}
2100#endif
2101
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002102int
2103sys_fchown(tcp)
2104struct tcb *tcp;
2105{
2106 if (entering(tcp)) {
Roland McGrath6bc12202003-11-13 22:32:27 +00002107 tprintf("%ld", tcp->u_arg[0]);
2108 printuid(", ", tcp->u_arg[1]);
2109 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002110 }
2111 return 0;
2112}
2113
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002114static int
2115decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002116{
2117 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002118 printpath(tcp, tcp->u_arg[offset]);
2119 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002120 }
2121 return 0;
2122}
2123
2124int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002125sys_chmod(struct tcb *tcp)
2126{
2127 return decode_chmod(tcp, 0);
2128}
2129
2130#ifdef LINUX
2131int
2132sys_fchmodat(struct tcb *tcp)
2133{
2134 if (entering(tcp))
2135 print_dirfd(tcp->u_arg[0]);
2136 return decode_chmod(tcp, 1);
2137}
2138#endif
2139
2140int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002141sys_fchmod(tcp)
2142struct tcb *tcp;
2143{
2144 if (entering(tcp)) {
2145 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
2146 }
2147 return 0;
2148}
2149
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002150#ifdef ALPHA
2151int
2152sys_osf_utimes(tcp)
2153struct tcb *tcp;
2154{
2155 if (entering(tcp)) {
2156 printpath(tcp, tcp->u_arg[0]);
2157 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002158 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002159 }
2160 return 0;
2161}
2162#endif
2163
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002164static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002165decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002166{
2167 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002168 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002169 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002170 if (tcp->u_arg[offset + 1] == 0)
2171 tprintf("NULL");
2172 else {
2173 tprintf("{");
2174 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2175 BITNESS_CURRENT, special);
2176 tprintf(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002177 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Roland McGrath6afc5652007-07-24 01:57:11 +00002178 + sizeof (struct timeval),
2179 BITNESS_CURRENT, special);
2180 tprintf("}");
2181 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002182 }
2183 return 0;
2184}
2185
2186int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002187sys_utimes(struct tcb *tcp)
2188{
Roland McGrath6afc5652007-07-24 01:57:11 +00002189 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002190}
2191
2192#ifdef LINUX
2193int
2194sys_futimesat(struct tcb *tcp)
2195{
2196 if (entering(tcp))
2197 print_dirfd(tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002198 return decode_utimes(tcp, 1, 0);
2199}
2200
2201int
2202sys_utimensat(struct tcb *tcp)
2203{
2204 if (entering(tcp)) {
2205 print_dirfd(tcp->u_arg[0]);
2206 decode_utimes(tcp, 1, 1);
2207 tprintf(", ");
2208 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2209 }
2210 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002211}
2212#endif
2213
2214int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002215sys_utime(tcp)
2216struct tcb *tcp;
2217{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002218 union {
2219 long utl[2];
2220 int uti[2];
2221 } u;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002222
2223 if (entering(tcp)) {
2224 printpath(tcp, tcp->u_arg[0]);
2225 tprintf(", ");
2226 if (!tcp->u_arg[1])
2227 tprintf("NULL");
2228 else if (!verbose(tcp))
2229 tprintf("%#lx", tcp->u_arg[1]);
Roland McGrath7e9817c2007-07-05 20:31:58 +00002230 else if (umoven(tcp, tcp->u_arg[1],
2231 2 * personality_wordsize[current_personality],
2232 (char *) &u) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002233 tprintf("[?, ?]");
Roland McGrath7e9817c2007-07-05 20:31:58 +00002234 else if (personality_wordsize[current_personality]
2235 == sizeof u.utl[0]) {
2236 tprintf("[%s,", sprinttime(u.utl[0]));
2237 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002238 }
Roland McGrath7e9817c2007-07-05 20:31:58 +00002239 else if (personality_wordsize[current_personality]
2240 == sizeof u.uti[0]) {
2241 tprintf("[%s,", sprinttime(u.uti[0]));
2242 tprintf(" %s]", sprinttime(u.uti[1]));
2243 }
2244 else
2245 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002246 }
2247 return 0;
2248}
2249
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002250static int
2251decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002252{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002253 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002254
2255 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002256 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002257 tprintf(", %s", sprintmode(mode));
2258 switch (mode & S_IFMT) {
2259 case S_IFCHR: case S_IFBLK:
2260#ifdef LINUXSPARC
2261 if (current_personality == 1)
2262 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002263 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2264 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002265 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002266#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002267 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002268 (unsigned long) major(tcp->u_arg[offset + 2]),
2269 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002270 break;
2271 default:
2272 break;
2273 }
2274 }
2275 return 0;
2276}
2277
2278int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002279sys_mknod(struct tcb *tcp)
2280{
2281 return decode_mknod(tcp, 0);
2282}
2283
2284#ifdef LINUX
2285int
2286sys_mknodat(struct tcb *tcp)
2287{
2288 if (entering(tcp))
2289 print_dirfd(tcp->u_arg[0]);
2290 return decode_mknod(tcp, 1);
2291}
2292#endif
2293
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002294#ifdef FREEBSD
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002295int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002296sys_mkfifo(tcp)
2297struct tcb *tcp;
2298{
2299 if (entering(tcp)) {
2300 printpath(tcp, tcp->u_arg[0]);
2301 tprintf(", %#lo", tcp->u_arg[1]);
2302 }
2303 return 0;
2304}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002305#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002306
2307int
2308sys_fsync(tcp)
2309struct tcb *tcp;
2310{
2311 if (entering(tcp)) {
2312 tprintf("%ld", tcp->u_arg[0]);
2313 }
2314 return 0;
2315}
2316
Michal Ludvig53b320f2002-09-23 13:30:09 +00002317#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002318
2319static void
2320printdir(tcp, addr)
2321struct tcb *tcp;
2322long addr;
2323{
2324 struct dirent d;
2325
2326 if (!verbose(tcp)) {
2327 tprintf("%#lx", addr);
2328 return;
2329 }
2330 if (umove(tcp, addr, &d) < 0) {
2331 tprintf("{...}");
2332 return;
2333 }
2334 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002335 tprintf("d_name=");
2336 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2337 tprintf("}");
2338}
2339
2340int
2341sys_readdir(tcp)
2342struct tcb *tcp;
2343{
2344 if (entering(tcp)) {
2345 tprintf("%lu, ", tcp->u_arg[0]);
2346 } else {
2347 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2348 tprintf("%#lx", tcp->u_arg[1]);
2349 else
2350 printdir(tcp, tcp->u_arg[1]);
2351 /* Not much point in printing this out, it is always 1. */
2352 if (tcp->u_arg[2] != 1)
2353 tprintf(", %lu", tcp->u_arg[2]);
2354 }
2355 return 0;
2356}
2357
Michal Ludvig53b320f2002-09-23 13:30:09 +00002358#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002359
Roland McGrath40542842004-01-13 09:47:49 +00002360#if defined FREEBSD || defined LINUX
Roland McGratha4d48532005-06-08 20:45:28 +00002361static const struct xlat direnttypes[] = {
Roland McGrath40542842004-01-13 09:47:49 +00002362 { DT_UNKNOWN, "DT_UNKNOWN" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002363 { DT_FIFO, "DT_FIFO" },
2364 { DT_CHR, "DT_CHR" },
2365 { DT_DIR, "DT_DIR" },
2366 { DT_BLK, "DT_BLK" },
2367 { DT_REG, "DT_REG" },
2368 { DT_LNK, "DT_LNK" },
2369 { DT_SOCK, "DT_SOCK" },
2370 { DT_WHT, "DT_WHT" },
2371 { 0, NULL },
2372};
2373
2374#endif
2375
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002376int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002377sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002378{
2379 int i, len, dents = 0;
2380 char *buf;
2381
2382 if (entering(tcp)) {
2383 tprintf("%lu, ", tcp->u_arg[0]);
2384 return 0;
2385 }
2386 if (syserror(tcp) || !verbose(tcp)) {
2387 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2388 return 0;
2389 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002390 len = tcp->u_rval;
2391 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002392 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2393 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002394 return 0;
2395 }
2396 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002397 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002398 free(buf);
2399 return 0;
2400 }
2401 if (!abbrev(tcp))
2402 tprintf("{");
2403 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002404 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002405#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002406 if (!abbrev(tcp)) {
2407 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2408 i ? " " : "", d->d_ino, d->d_off);
2409 tprintf("d_reclen=%u, d_name=\"%s\"}",
2410 d->d_reclen, d->d_name);
2411 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002412#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002413#ifdef SVR4
2414 if (!abbrev(tcp)) {
2415 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002416 i ? " " : "",
2417 (unsigned long) d->d_ino,
2418 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002419 tprintf("d_reclen=%u, d_name=\"%s\"}",
2420 d->d_reclen, d->d_name);
2421 }
2422#endif /* SVR4 */
2423#ifdef SUNOS4
2424 if (!abbrev(tcp)) {
2425 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2426 i ? " " : "", d->d_off, d->d_fileno,
2427 d->d_reclen);
2428 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2429 d->d_namlen, d->d_namlen, d->d_name);
2430 }
2431#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002432#ifdef FREEBSD
2433 if (!abbrev(tcp)) {
2434 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2435 i ? " " : "", d->d_fileno, d->d_reclen);
2436 printxval(direnttypes, d->d_type, "DT_???");
2437 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2438 d->d_namlen, d->d_namlen, d->d_name);
2439 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002440#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002441 if (!d->d_reclen) {
2442 tprintf("/* d_reclen == 0, problem here */");
2443 break;
2444 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002445 i += d->d_reclen;
2446 dents++;
2447 }
2448 if (!abbrev(tcp))
2449 tprintf("}");
2450 else
2451 tprintf("/* %u entries */", dents);
2452 tprintf(", %lu", tcp->u_arg[2]);
2453 free(buf);
2454 return 0;
2455}
2456
John Hughesbdf48f52001-03-06 15:08:09 +00002457
2458#if _LFS64_LARGEFILE
2459int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002460sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002461{
2462 int i, len, dents = 0;
2463 char *buf;
2464
2465 if (entering(tcp)) {
2466 tprintf("%lu, ", tcp->u_arg[0]);
2467 return 0;
2468 }
2469 if (syserror(tcp) || !verbose(tcp)) {
2470 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2471 return 0;
2472 }
2473 len = tcp->u_rval;
2474 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002475 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2476 fprintf(stderr, "out of memory\n");
John Hughesbdf48f52001-03-06 15:08:09 +00002477 return 0;
2478 }
2479 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002480 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002481 free(buf);
2482 return 0;
2483 }
2484 if (!abbrev(tcp))
2485 tprintf("{");
2486 for (i = 0; i < len;) {
2487 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002488#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002489 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002490 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002491 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002492 d->d_ino,
2493 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002494#ifdef LINUX
2495 tprintf("d_type=");
2496 printxval(direnttypes, d->d_type, "DT_???");
2497 tprintf(", ");
2498#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002499 tprintf("d_reclen=%u, d_name=\"%s\"}",
2500 d->d_reclen, d->d_name);
2501 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002502#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002503#ifdef SUNOS4
2504 if (!abbrev(tcp)) {
2505 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2506 i ? " " : "", d->d_off, d->d_fileno,
2507 d->d_reclen);
2508 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2509 d->d_namlen, d->d_namlen, d->d_name);
2510 }
2511#endif /* SUNOS4 */
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002512 if (!d->d_reclen) {
2513 tprintf("/* d_reclen == 0, problem here */");
2514 break;
2515 }
John Hughesbdf48f52001-03-06 15:08:09 +00002516 i += d->d_reclen;
2517 dents++;
2518 }
2519 if (!abbrev(tcp))
2520 tprintf("}");
2521 else
2522 tprintf("/* %u entries */", dents);
2523 tprintf(", %lu", tcp->u_arg[2]);
2524 free(buf);
2525 return 0;
2526}
2527#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002528
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002529#ifdef FREEBSD
2530int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002531sys_getdirentries(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002532{
2533 int i, len, dents = 0;
2534 long basep;
2535 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002536
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002537 if (entering(tcp)) {
2538 tprintf("%lu, ", tcp->u_arg[0]);
2539 return 0;
2540 }
2541 if (syserror(tcp) || !verbose(tcp)) {
2542 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2543 return 0;
2544 }
2545 len = tcp->u_rval;
2546 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002547 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2548 fprintf(stderr, "out of memory\n");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002549 return 0;
2550 }
2551 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002552 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002553 free(buf);
2554 return 0;
2555 }
2556 if (!abbrev(tcp))
2557 tprintf("{");
2558 for (i = 0; i < len;) {
2559 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2560 if (!abbrev(tcp)) {
2561 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2562 i ? " " : "", d->d_fileno, d->d_reclen);
2563 printxval(direnttypes, d->d_type, "DT_???");
2564 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2565 d->d_namlen, d->d_namlen, d->d_name);
2566 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002567 if (!d->d_reclen) {
2568 tprintf("/* d_reclen == 0, problem here */");
2569 break;
2570 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002571 i += d->d_reclen;
2572 dents++;
2573 }
2574 if (!abbrev(tcp))
2575 tprintf("}");
2576 else
2577 tprintf("/* %u entries */", dents);
2578 free(buf);
2579 tprintf(", %lu", tcp->u_arg[2]);
2580 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2581 tprintf(", %#lx", tcp->u_arg[3]);
2582 else
2583 tprintf(", [%lu]", basep);
2584 return 0;
2585}
2586#endif
2587
Michal Ludvig53b320f2002-09-23 13:30:09 +00002588#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002589int
2590sys_getcwd(tcp)
2591struct tcb *tcp;
2592{
2593 if (exiting(tcp)) {
2594 if (syserror(tcp))
2595 tprintf("%#lx", tcp->u_arg[0]);
2596 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002597 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002598 tprintf(", %lu", tcp->u_arg[1]);
2599 }
2600 return 0;
2601}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002602#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002603
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002604#ifdef FREEBSD
2605int
2606sys___getcwd(tcp)
2607struct tcb *tcp;
2608{
2609 if (exiting(tcp)) {
2610 if (syserror(tcp))
2611 tprintf("%#lx", tcp->u_arg[0]);
2612 else
2613 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2614 tprintf(", %lu", tcp->u_arg[1]);
2615 }
2616 return 0;
2617}
2618#endif
2619
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002620#ifdef HAVE_SYS_ASYNCH_H
2621
2622int
2623sys_aioread(tcp)
2624struct tcb *tcp;
2625{
2626 struct aio_result_t res;
2627
2628 if (entering(tcp)) {
2629 tprintf("%lu, ", tcp->u_arg[0]);
2630 } else {
2631 if (syserror(tcp))
2632 tprintf("%#lx", tcp->u_arg[1]);
2633 else
2634 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2635 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2636 printxval(whence, tcp->u_arg[4], "L_???");
2637 if (syserror(tcp) || tcp->u_arg[5] == 0
2638 || umove(tcp, tcp->u_arg[5], &res) < 0)
2639 tprintf(", %#lx", tcp->u_arg[5]);
2640 else
2641 tprintf(", {aio_return %d aio_errno %d}",
2642 res.aio_return, res.aio_errno);
2643 }
2644 return 0;
2645}
2646
2647int
2648sys_aiowrite(tcp)
2649struct tcb *tcp;
2650{
2651 struct aio_result_t res;
2652
2653 if (entering(tcp)) {
2654 tprintf("%lu, ", tcp->u_arg[0]);
2655 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2656 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2657 printxval(whence, tcp->u_arg[4], "L_???");
2658 }
2659 else {
2660 if (tcp->u_arg[5] == 0)
2661 tprintf(", NULL");
2662 else if (syserror(tcp)
2663 || umove(tcp, tcp->u_arg[5], &res) < 0)
2664 tprintf(", %#lx", tcp->u_arg[5]);
2665 else
2666 tprintf(", {aio_return %d aio_errno %d}",
2667 res.aio_return, res.aio_errno);
2668 }
2669 return 0;
2670}
2671
2672int
2673sys_aiowait(tcp)
2674struct tcb *tcp;
2675{
2676 if (entering(tcp))
2677 printtv(tcp, tcp->u_arg[0]);
2678 return 0;
2679}
2680
2681int
2682sys_aiocancel(tcp)
2683struct tcb *tcp;
2684{
2685 struct aio_result_t res;
2686
2687 if (exiting(tcp)) {
2688 if (tcp->u_arg[0] == 0)
2689 tprintf("NULL");
2690 else if (syserror(tcp)
2691 || umove(tcp, tcp->u_arg[0], &res) < 0)
2692 tprintf("%#lx", tcp->u_arg[0]);
2693 else
2694 tprintf("{aio_return %d aio_errno %d}",
2695 res.aio_return, res.aio_errno);
2696 }
2697 return 0;
2698}
2699
2700#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002701
Roland McGratha4d48532005-06-08 20:45:28 +00002702static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002703#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002704 { XATTR_CREATE, "XATTR_CREATE" },
2705 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002706#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002707 { 0, NULL }
2708};
2709
Roland McGrath3292e222004-08-31 06:30:48 +00002710static void
2711print_xattr_val(tcp, failed, arg, insize, size)
2712struct tcb *tcp;
2713int failed;
2714unsigned long arg;
Roland McGrathaa524c82005-06-01 19:22:06 +00002715unsigned long insize, size;
Roland McGrath3292e222004-08-31 06:30:48 +00002716{
Roland McGrath883567c2005-02-02 03:38:32 +00002717 if (!failed) {
Roland McGrathaa524c82005-06-01 19:22:06 +00002718 unsigned long capacity = 4 * size + 1;
2719 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
Roland McGrath883567c2005-02-02 03:38:32 +00002720 if (buf == NULL || /* probably a bogus size argument */
Roland McGrathf7746422005-03-01 23:02:32 +00002721 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
Roland McGrath883567c2005-02-02 03:38:32 +00002722 failed = 1;
2723 }
2724 else {
2725 unsigned char *out = buf;
2726 unsigned char *in = &buf[3 * size];
2727 size_t i;
2728 for (i = 0; i < size; ++i)
2729 if (isprint(in[i]))
2730 *out++ = in[i];
2731 else {
Roland McGrath3292e222004-08-31 06:30:48 +00002732#define tohex(n) "0123456789abcdef"[n]
Roland McGrath883567c2005-02-02 03:38:32 +00002733 *out++ = '\\';
2734 *out++ = 'x';
2735 *out++ = tohex(in[i] / 16);
2736 *out++ = tohex(in[i] % 16);
2737 }
2738 /* Don't print terminating NUL if there is one. */
Dmitry V. Levin504eb0b2006-10-11 22:58:31 +00002739 if (i > 0 && in[i - 1] == '\0')
Roland McGrath883567c2005-02-02 03:38:32 +00002740 out -= 4;
2741 *out = '\0';
2742 tprintf(", \"%s\", %ld", buf, insize);
2743 }
2744 free(buf);
2745 }
2746 if (failed)
2747 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002748}
2749
Roland McGrath186c5ac2002-12-15 23:58:23 +00002750int
2751sys_setxattr(tcp)
2752struct tcb *tcp;
2753{
2754 if (entering(tcp)) {
2755 printpath(tcp, tcp->u_arg[0]);
2756 tprintf(", ");
2757 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002758 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2759 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002760 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002761 }
2762 return 0;
2763}
2764
2765int
2766sys_fsetxattr(tcp)
2767struct tcb *tcp;
2768{
2769 if (entering(tcp)) {
2770 tprintf("%ld, ", tcp->u_arg[0]);
2771 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002772 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2773 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002774 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002775 }
2776 return 0;
2777}
2778
2779int
2780sys_getxattr(tcp)
2781struct tcb *tcp;
2782{
2783 if (entering(tcp)) {
2784 printpath(tcp, tcp->u_arg[0]);
2785 tprintf(", ");
2786 printstr(tcp, tcp->u_arg[1], -1);
2787 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002788 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2789 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002790 }
2791 return 0;
2792}
2793
2794int
2795sys_fgetxattr(tcp)
2796struct tcb *tcp;
2797{
2798 if (entering(tcp)) {
2799 tprintf("%ld, ", tcp->u_arg[0]);
2800 printstr(tcp, tcp->u_arg[1], -1);
2801 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002802 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2803 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002804 }
2805 return 0;
2806}
2807
2808int
2809sys_listxattr(tcp)
2810struct tcb *tcp;
2811{
2812 if (entering(tcp)) {
2813 printpath(tcp, tcp->u_arg[0]);
2814 } else {
2815 /* XXX Print value in format */
2816 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2817 }
2818 return 0;
2819}
2820
2821int
2822sys_flistxattr(tcp)
2823struct tcb *tcp;
2824{
2825 if (entering(tcp)) {
2826 tprintf("%ld", tcp->u_arg[0]);
2827 } else {
2828 /* XXX Print value in format */
2829 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2830 }
2831 return 0;
2832}
2833
2834int
2835sys_removexattr(tcp)
2836struct tcb *tcp;
2837{
2838 if (entering(tcp)) {
2839 printpath(tcp, tcp->u_arg[0]);
2840 tprintf(", ");
2841 printstr(tcp, tcp->u_arg[1], -1);
2842 }
2843 return 0;
2844}
2845
2846int
2847sys_fremovexattr(tcp)
2848struct tcb *tcp;
2849{
2850 if (entering(tcp)) {
2851 tprintf("%ld, ", tcp->u_arg[0]);
2852 printstr(tcp, tcp->u_arg[1], -1);
2853 }
2854 return 0;
2855}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002856
2857
2858static const struct xlat advise[] = {
2859 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2860 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2861 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2862 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2863 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2864 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2865 { 0, NULL }
2866};
2867
2868
Roland McGrathe27ed342004-10-20 02:24:19 +00002869#ifdef LINUX
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002870int
2871sys_fadvise64(tcp)
2872struct tcb *tcp;
2873{
2874 if (entering(tcp)) {
2875 tprintf("%ld, %lld, %ld, ",
2876 tcp->u_arg[0],
2877# if defined IA64 || defined X86_64 || defined ALPHA
2878 (long long int) tcp->u_arg[1], tcp->u_arg[2]);
2879 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2880#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002881 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
2882 printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002883#endif
2884 }
2885 return 0;
2886}
2887#endif
2888
2889
2890int
2891sys_fadvise64_64(tcp)
2892struct tcb *tcp;
2893{
2894 if (entering(tcp)) {
2895 tprintf("%ld, %lld, %lld, ",
2896 tcp->u_arg[0],
Roland McGrath542c2c62008-05-20 01:11:56 +00002897#if defined LINUX_MIPSN32
2898 tcp->ext_arg[1], tcp->ext_arg[2]);
2899 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2900#elif defined IA64 || defined X86_64 || defined ALPHA || defined LINUX_MIPSN64
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002901 (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
2902 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2903#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002904 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
2905 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002906 printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
2907#endif
2908 }
2909 return 0;
2910}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002911
2912#ifdef LINUX
2913static const struct xlat inotify_modes[] = {
2914 { 0x00000001, "IN_ACCESS" },
2915 { 0x00000002, "IN_MODIFY" },
2916 { 0x00000004, "IN_ATTRIB" },
2917 { 0x00000008, "IN_CLOSE_WRITE" },
2918 { 0x00000010, "IN_CLOSE_NOWRITE" },
2919 { 0x00000020, "IN_OPEN" },
2920 { 0x00000040, "IN_MOVED_FROM" },
2921 { 0x00000080, "IN_MOVED_TO" },
2922 { 0x00000100, "IN_CREATE" },
2923 { 0x00000200, "IN_DELETE" },
2924 { 0x00000400, "IN_DELETE_SELF" },
2925 { 0x00000800, "IN_MOVE_SELF" },
2926 { 0x00002000, "IN_UNMOUNT" },
2927 { 0x00004000, "IN_Q_OVERFLOW" },
2928 { 0x00008000, "IN_IGNORED" },
2929 { 0x01000000, "IN_ONLYDIR" },
2930 { 0x02000000, "IN_DONT_FOLLOW" },
2931 { 0x20000000, "IN_MASK_ADD" },
2932 { 0x40000000, "IN_ISDIR" },
2933 { 0x80000000, "IN_ONESHOT" }
2934};
2935
2936int
2937sys_inotify_add_watch(struct tcb *tcp)
2938{
2939 if (entering(tcp)) {
2940 tprintf("%ld, ", tcp->u_arg[0]);
2941 printpath(tcp, tcp->u_arg[1]);
2942 tprintf(", ");
2943 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2944 }
2945 return 0;
2946}
2947
2948int
2949sys_inotify_rm_watch(struct tcb *tcp)
2950{
2951 if (entering(tcp)) {
2952 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
2953 }
2954 return 0;
2955}
2956#endif