blob: 22a8260ce70e9cfd4f5b3733cc0a18441cf8e79e [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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000500int
501sys_lseek(tcp)
502struct tcb *tcp;
503{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000504 off_t offset;
505 int _whence;
506
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000507 if (entering(tcp)) {
508 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000509 offset = tcp->u_arg[1];
510 _whence = tcp->u_arg[2];
511 if (_whence == SEEK_SET)
512 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000513 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000514 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000515 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000516 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517 return RVAL_UDECIMAL;
518}
John Hughes5a826b82001-03-07 13:21:24 +0000519#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520
Michal Ludvig53b320f2002-09-23 13:30:09 +0000521#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522int
523sys_llseek (tcp)
524struct tcb *tcp;
525{
526 if (entering(tcp)) {
Roland McGrath8c304bc2004-10-19 22:59:55 +0000527 /*
528 * This one call takes explicitly two 32-bit arguments hi, lo,
529 * rather than one 64-bit argument for which LONG_LONG works
530 * appropriate for the native byte order.
531 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000532 if (tcp->u_arg[4] == SEEK_SET)
533 tprintf("%ld, %llu, ", tcp->u_arg[0],
Roland McGrath8c304bc2004-10-19 22:59:55 +0000534 (((long long int) tcp->u_arg[1]) << 32
535 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000536 else
537 tprintf("%ld, %lld, ", tcp->u_arg[0],
Roland McGrath8c304bc2004-10-19 22:59:55 +0000538 (((long long int) tcp->u_arg[1]) << 32
539 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000540 }
541 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000542 long long int off;
543 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000544 tprintf("%#lx, ", tcp->u_arg[3]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000545 else
546 tprintf("[%llu], ", off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547 printxval(whence, tcp->u_arg[4], "SEEK_???");
548 }
549 return 0;
550}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000551
552int
553sys_readahead (tcp)
554struct tcb *tcp;
555{
556 if (entering(tcp)) {
557 tprintf("%ld, %lld, %ld", tcp->u_arg[0],
558# if defined IA64 || defined X86_64 || defined ALPHA
559 (long long int) tcp->u_arg[1], tcp->u_arg[2]
560# else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +0000561 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]
Roland McGrath186c5ac2002-12-15 23:58:23 +0000562# endif
563 );
564 }
565 return 0;
566}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000567#endif
568
John Hughes70623be2001-03-08 13:59:00 +0000569#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000570int
571sys_lseek64 (tcp)
572struct tcb *tcp;
573{
574 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000575 long long offset;
576 ALIGN64 (tcp, 1); /* FreeBSD aligns off_t args */
John Hughes0c79e012001-03-08 14:40:06 +0000577 offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +0000578 if (tcp->u_arg[3] == SEEK_SET)
579 tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
580 else
581 tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
582 printxval(whence, tcp->u_arg[3], "SEEK_???");
583 }
584 return RVAL_LUDECIMAL;
585}
586#endif
587
John Hughes70623be2001-03-08 13:59:00 +0000588#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000589int
590sys_truncate(tcp)
591struct tcb *tcp;
592{
593 if (entering(tcp)) {
594 printpath(tcp, tcp->u_arg[0]);
595 tprintf(", %lu", tcp->u_arg[1]);
596 }
597 return 0;
598}
John Hughes5a826b82001-03-07 13:21:24 +0000599#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000600
John Hughes70623be2001-03-08 13:59:00 +0000601#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000602int
603sys_truncate64(tcp)
604struct tcb *tcp;
605{
606 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000607 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000608 printpath(tcp, tcp->u_arg[0]);
John Hughes0c79e012001-03-08 14:40:06 +0000609 tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000610 }
611 return 0;
612}
613#endif
614
John Hughes70623be2001-03-08 13:59:00 +0000615#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000616int
617sys_ftruncate(tcp)
618struct tcb *tcp;
619{
620 if (entering(tcp)) {
621 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
622 }
623 return 0;
624}
John Hughes5a826b82001-03-07 13:21:24 +0000625#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000626
John Hughes70623be2001-03-08 13:59:00 +0000627#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000628int
629sys_ftruncate64(tcp)
630struct tcb *tcp;
631{
632 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000633 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000634 tprintf("%ld, %llu", tcp->u_arg[0],
John Hughes0c79e012001-03-08 14:40:06 +0000635 LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000636 }
637 return 0;
638}
639#endif
640
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000641/* several stats */
642
Roland McGrathd9f816f2004-09-04 03:39:20 +0000643static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000644 { S_IFREG, "S_IFREG" },
645 { S_IFSOCK, "S_IFSOCK" },
646 { S_IFIFO, "S_IFIFO" },
647 { S_IFLNK, "S_IFLNK" },
648 { S_IFDIR, "S_IFDIR" },
649 { S_IFBLK, "S_IFBLK" },
650 { S_IFCHR, "S_IFCHR" },
651 { 0, NULL },
652};
653
Roland McGrathf9c49b22004-10-06 22:11:54 +0000654static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000655sprintmode(mode)
656int mode;
657{
658 static char buf[64];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000659 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000660
661 if ((mode & S_IFMT) == 0)
662 s = "";
663 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
664 sprintf(buf, "%#o", mode);
665 return buf;
666 }
667 sprintf(buf, "%s%s%s%s", s,
668 (mode & S_ISUID) ? "|S_ISUID" : "",
669 (mode & S_ISGID) ? "|S_ISGID" : "",
670 (mode & S_ISVTX) ? "|S_ISVTX" : "");
671 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
672 if (mode)
673 sprintf(buf + strlen(buf), "|%#o", mode);
674 s = (*buf == '|') ? buf + 1 : buf;
675 return *s ? s : "0";
676}
677
678static char *
679sprinttime(t)
680time_t t;
681{
682 struct tm *tmp;
683 static char buf[32];
684
685 if (t == 0) {
686 sprintf(buf, "0");
687 return buf;
688 }
689 tmp = localtime(&t);
690 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
Wichert Akkerman3ed6dc22000-01-11 14:41:09 +0000691 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000692 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
693 return buf;
694}
695
696#ifdef LINUXSPARC
697typedef struct {
698 int tv_sec;
699 int tv_nsec;
700} timestruct_t;
701
702struct solstat {
703 unsigned st_dev;
704 int st_pad1[3]; /* network id */
705 unsigned st_ino;
706 unsigned st_mode;
707 unsigned st_nlink;
708 unsigned st_uid;
709 unsigned st_gid;
710 unsigned st_rdev;
711 int st_pad2[2];
712 int st_size;
713 int st_pad3; /* st_size, off_t expansion */
714 timestruct_t st_atime;
715 timestruct_t st_mtime;
716 timestruct_t st_ctime;
717 int st_blksize;
718 int st_blocks;
719 char st_fstype[16];
720 int st_pad4[8]; /* expansion area */
721};
722
723static void
724printstatsol(tcp, addr)
725struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000726long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000727{
728 struct solstat statbuf;
729
730 if (!addr) {
731 tprintf("NULL");
732 return;
733 }
734 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000735 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000736 return;
737 }
738 if (umove(tcp, addr, &statbuf) < 0) {
739 tprintf("{...}");
740 return;
741 }
742 if (!abbrev(tcp)) {
743 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
744 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
745 (unsigned long) (statbuf.st_dev & 0x3ffff),
746 (unsigned long) statbuf.st_ino,
747 sprintmode(statbuf.st_mode));
748 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
749 (unsigned long) statbuf.st_nlink,
750 (unsigned long) statbuf.st_uid,
751 (unsigned long) statbuf.st_gid);
752 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
753 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
754 }
755 else
756 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
757 switch (statbuf.st_mode & S_IFMT) {
758 case S_IFCHR: case S_IFBLK:
759 tprintf("st_rdev=makedev(%lu, %lu), ",
760 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
761 (unsigned long) (statbuf.st_rdev & 0x3ffff));
762 break;
763 default:
764 tprintf("st_size=%u, ", statbuf.st_size);
765 break;
766 }
767 if (!abbrev(tcp)) {
768 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
769 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
770 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
771 }
772 else
773 tprintf("...}");
774}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000775
776#if defined (SPARC64)
777static void
778printstat_sparc64(tcp, addr)
779struct tcb *tcp;
780long addr;
781{
782 struct stat_sparc64 statbuf;
783
784 if (!addr) {
785 tprintf("NULL");
786 return;
787 }
788 if (syserror(tcp) || !verbose(tcp)) {
789 tprintf("%#lx", addr);
790 return;
791 }
792 if (umove(tcp, addr, &statbuf) < 0) {
793 tprintf("{...}");
794 return;
795 }
796
797 if (!abbrev(tcp)) {
798 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
799 (unsigned long) major(statbuf.st_dev),
800 (unsigned long) minor(statbuf.st_dev),
801 (unsigned long) statbuf.st_ino,
802 sprintmode(statbuf.st_mode));
803 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
804 (unsigned long) statbuf.st_nlink,
805 (unsigned long) statbuf.st_uid,
806 (unsigned long) statbuf.st_gid);
807 tprintf("st_blksize=%lu, ",
808 (unsigned long) statbuf.st_blksize);
809 tprintf("st_blocks=%lu, ",
810 (unsigned long) statbuf.st_blocks);
811 }
812 else
813 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
814 switch (statbuf.st_mode & S_IFMT) {
815 case S_IFCHR: case S_IFBLK:
816 tprintf("st_rdev=makedev(%lu, %lu), ",
817 (unsigned long) major(statbuf.st_rdev),
818 (unsigned long) minor(statbuf.st_rdev));
819 break;
820 default:
821 tprintf("st_size=%lu, ", statbuf.st_size);
822 break;
823 }
824 if (!abbrev(tcp)) {
825 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
826 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
827 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
828 tprintf("}");
829 }
830 else
831 tprintf("...}");
832}
833#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000834#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000835
Roland McGratha4d48532005-06-08 20:45:28 +0000836static const struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000837#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000838 { UF_NODUMP, "UF_NODUMP" },
839 { UF_IMMUTABLE, "UF_IMMUTABLE" },
840 { UF_APPEND, "UF_APPEND" },
841 { UF_OPAQUE, "UF_OPAQUE" },
842 { UF_NOUNLINK, "UF_NOUNLINK" },
843 { SF_ARCHIVED, "SF_ARCHIVED" },
844 { SF_IMMUTABLE, "SF_IMMUTABLE" },
845 { SF_APPEND, "SF_APPEND" },
846 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000847#elif UNIXWARE >= 2
848#ifdef _S_ISMLD
849 { _S_ISMLD, "_S_ISMLD" },
850#endif
851#ifdef _S_ISMOUNTED
852 { _S_ISMOUNTED, "_S_ISMOUNTED" },
853#endif
854#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000855 { 0, NULL },
856};
857
John Hughesc0fc3fd2001-03-08 16:10:40 +0000858#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000859int
860sys_chflags(tcp)
861struct tcb *tcp;
862{
863 if (entering(tcp)) {
864 printpath(tcp, tcp->u_arg[0]);
865 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000866 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000867 }
868 return 0;
869}
870
871int
872sys_fchflags(tcp)
873struct tcb *tcp;
874{
875 if (entering(tcp)) {
876 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000877 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000878 }
879 return 0;
880}
881#endif
882
John Hughes70623be2001-03-08 13:59:00 +0000883#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000884static void
885realprintstat(tcp, statbuf)
886struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000887struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000888{
889 if (!abbrev(tcp)) {
890 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
891 (unsigned long) major(statbuf->st_dev),
892 (unsigned long) minor(statbuf->st_dev),
893 (unsigned long) statbuf->st_ino,
894 sprintmode(statbuf->st_mode));
895 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
896 (unsigned long) statbuf->st_nlink,
897 (unsigned long) statbuf->st_uid,
898 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000899#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000900 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000901#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
902#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000903 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000904#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000905 }
906 else
907 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
908 switch (statbuf->st_mode & S_IFMT) {
909 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000910#ifdef HAVE_STRUCT_STAT_ST_RDEV
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000911 tprintf("st_rdev=makedev(%lu, %lu), ",
912 (unsigned long) major(statbuf->st_rdev),
913 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000914#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000915 tprintf("st_size=makedev(%lu, %lu), ",
916 (unsigned long) major(statbuf->st_size),
917 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000918#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000919 break;
920 default:
921 tprintf("st_size=%lu, ", statbuf->st_size);
922 break;
923 }
924 if (!abbrev(tcp)) {
925 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
926 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000927 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000928#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000929 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000930 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000931#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000932#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000933 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
934#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000935#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000936 tprintf(", st_level=%ld", statbuf->st_level);
937#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000938#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000939 tprintf(", st_fstype=%.*s",
940 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
941#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000942#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000943 tprintf(", st_gen=%u", statbuf->st_gen);
944#endif
945 tprintf("}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000946 }
947 else
948 tprintf("...}");
949}
950
Nate Sammons771a6ff1999-04-05 22:39:31 +0000951
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000952static void
953printstat(tcp, addr)
954struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000955long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000956{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000957 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000958
959#ifdef LINUXSPARC
960 if (current_personality == 1) {
961 printstatsol(tcp, addr);
962 return;
963 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000964#ifdef SPARC64
965 else if (current_personality == 2) {
966 printstat_sparc64(tcp, addr);
967 return;
968 }
969#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000970#endif /* LINUXSPARC */
971
972 if (!addr) {
973 tprintf("NULL");
974 return;
975 }
976 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000977 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000978 return;
979 }
980 if (umove(tcp, addr, &statbuf) < 0) {
981 tprintf("{...}");
982 return;
983 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000984
985 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000986}
John Hughes70623be2001-03-08 13:59:00 +0000987#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000988
Wichert Akkermanc7926982000-04-10 22:22:31 +0000989#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000990static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000991printstat64(tcp, addr)
992struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000993long addr;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000994{
995 struct stat64 statbuf;
996
997#ifdef LINUXSPARC
998 if (current_personality == 1) {
999 printstatsol(tcp, addr);
1000 return;
1001 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001002#ifdef SPARC64
1003 else if (current_personality == 2) {
1004 printstat_sparc64(tcp, addr);
1005 return;
1006 }
1007#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001008#endif /* LINUXSPARC */
1009
1010 if (!addr) {
1011 tprintf("NULL");
1012 return;
1013 }
1014 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001015 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001016 return;
1017 }
1018 if (umove(tcp, addr, &statbuf) < 0) {
1019 tprintf("{...}");
1020 return;
1021 }
1022
1023 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001024#ifdef HAVE_LONG_LONG
1025 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1026#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001027 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001028#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001029 (unsigned long) major(statbuf.st_dev),
1030 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001031#ifdef HAVE_LONG_LONG
1032 (unsigned long long) statbuf.st_ino,
1033#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001034 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001035#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001036 sprintmode(statbuf.st_mode));
1037 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1038 (unsigned long) statbuf.st_nlink,
1039 (unsigned long) statbuf.st_uid,
1040 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001041#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001042 tprintf("st_blksize=%lu, ",
1043 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001044#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1045#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001046 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001047#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001048 }
1049 else
1050 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1051 switch (statbuf.st_mode & S_IFMT) {
1052 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001053#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001054 tprintf("st_rdev=makedev(%lu, %lu), ",
1055 (unsigned long) major(statbuf.st_rdev),
1056 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001057#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001058 tprintf("st_size=makedev(%lu, %lu), ",
1059 (unsigned long) major(statbuf.st_size),
1060 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001061#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001062 break;
1063 default:
1064 tprintf("st_size=%llu, ", statbuf.st_size);
1065 break;
1066 }
1067 if (!abbrev(tcp)) {
1068 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1069 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001070 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001071#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +00001072 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001073 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001074#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001075#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001076 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1077#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001078#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001079 tprintf(", st_level=%ld", statbuf.st_level);
1080#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001081#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001082 tprintf(", st_fstype=%.*s",
1083 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1084#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001085#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001086 tprintf(", st_gen=%u", statbuf.st_gen);
1087#endif
1088 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001089 }
1090 else
1091 tprintf("...}");
1092}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001093#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001094
Roland McGrath79db8af2003-06-27 21:20:09 +00001095#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001096static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001097convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001098const struct __old_kernel_stat *oldbuf;
1099struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001100{
1101 newbuf->st_dev=oldbuf->st_dev;
1102 newbuf->st_ino=oldbuf->st_ino;
1103 newbuf->st_mode=oldbuf->st_mode;
1104 newbuf->st_nlink=oldbuf->st_nlink;
1105 newbuf->st_uid=oldbuf->st_uid;
1106 newbuf->st_gid=oldbuf->st_gid;
1107 newbuf->st_rdev=oldbuf->st_rdev;
1108 newbuf->st_size=oldbuf->st_size;
1109 newbuf->st_atime=oldbuf->st_atime;
1110 newbuf->st_mtime=oldbuf->st_mtime;
1111 newbuf->st_ctime=oldbuf->st_ctime;
1112 newbuf->st_blksize=0; /* not supported in old_stat */
1113 newbuf->st_blocks=0; /* not supported in old_stat */
1114}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001115
1116
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001117static void
1118printoldstat(tcp, addr)
1119struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001120long addr;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001121{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001122 struct __old_kernel_stat statbuf;
1123 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001124
1125#ifdef LINUXSPARC
1126 if (current_personality == 1) {
1127 printstatsol(tcp, addr);
1128 return;
1129 }
1130#endif /* LINUXSPARC */
1131
1132 if (!addr) {
1133 tprintf("NULL");
1134 return;
1135 }
1136 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001137 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001138 return;
1139 }
1140 if (umove(tcp, addr, &statbuf) < 0) {
1141 tprintf("{...}");
1142 return;
1143 }
1144
1145 convertoldstat(&statbuf, &newstatbuf);
1146 realprintstat(tcp, &newstatbuf);
1147}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001148#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001149
John Hughes70623be2001-03-08 13:59:00 +00001150#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001151int
1152sys_stat(tcp)
1153struct tcb *tcp;
1154{
1155 if (entering(tcp)) {
1156 printpath(tcp, tcp->u_arg[0]);
1157 tprintf(", ");
1158 } else {
1159 printstat(tcp, tcp->u_arg[1]);
1160 }
1161 return 0;
1162}
John Hughesb8c9f772001-03-07 16:53:07 +00001163#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001164
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001165int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001166sys_stat64(tcp)
1167struct tcb *tcp;
1168{
1169#ifdef HAVE_STAT64
1170 if (entering(tcp)) {
1171 printpath(tcp, tcp->u_arg[0]);
1172 tprintf(", ");
1173 } else {
1174 printstat64(tcp, tcp->u_arg[1]);
1175 }
1176 return 0;
1177#else
1178 return printargs(tcp);
1179#endif
1180}
1181
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001182#ifdef LINUX
1183static const struct xlat fstatatflags[] = {
1184#ifndef AT_SYMLINK_NOFOLLOW
1185# define AT_SYMLINK_NOFOLLOW 0x100
1186#endif
1187 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1188 { 0, NULL },
1189};
Roland McGrath6afc5652007-07-24 01:57:11 +00001190#define utimensatflags fstatatflags
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001191
1192int
1193sys_newfstatat(struct tcb *tcp)
1194{
1195 if (entering(tcp)) {
1196 print_dirfd(tcp->u_arg[0]);
1197 printpath(tcp, tcp->u_arg[1]);
1198 tprintf(", ");
1199 } else {
Roland McGrath359c8ed2007-07-05 19:01:17 +00001200#if defined HAVE_STAT64 && !(defined POWERPC && defined __powerpc64__)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001201 printstat64(tcp, tcp->u_arg[2]);
1202#else
1203 printstat(tcp, tcp->u_arg[2]);
1204#endif
1205 tprintf(", ");
1206 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1207 }
1208 return 0;
1209}
1210#endif
1211
Roland McGrath79db8af2003-06-27 21:20:09 +00001212#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001213int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001214sys_oldstat(tcp)
1215struct tcb *tcp;
1216{
1217 if (entering(tcp)) {
1218 printpath(tcp, tcp->u_arg[0]);
1219 tprintf(", ");
1220 } else {
1221 printoldstat(tcp, tcp->u_arg[1]);
1222 }
1223 return 0;
1224}
Roland McGrath79db8af2003-06-27 21:20:09 +00001225#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001226
John Hughes70623be2001-03-08 13:59:00 +00001227#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001228int
1229sys_fstat(tcp)
1230struct tcb *tcp;
1231{
1232 if (entering(tcp))
1233 tprintf("%ld, ", tcp->u_arg[0]);
1234 else {
1235 printstat(tcp, tcp->u_arg[1]);
1236 }
1237 return 0;
1238}
John Hughesb8c9f772001-03-07 16:53:07 +00001239#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001240
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001241int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001242sys_fstat64(tcp)
1243struct tcb *tcp;
1244{
1245#ifdef HAVE_STAT64
1246 if (entering(tcp))
1247 tprintf("%ld, ", tcp->u_arg[0]);
1248 else {
1249 printstat64(tcp, tcp->u_arg[1]);
1250 }
1251 return 0;
1252#else
1253 return printargs(tcp);
1254#endif
1255}
1256
Roland McGrath79db8af2003-06-27 21:20:09 +00001257#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001258int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001259sys_oldfstat(tcp)
1260struct tcb *tcp;
1261{
1262 if (entering(tcp))
1263 tprintf("%ld, ", tcp->u_arg[0]);
1264 else {
1265 printoldstat(tcp, tcp->u_arg[1]);
1266 }
1267 return 0;
1268}
Roland McGrath79db8af2003-06-27 21:20:09 +00001269#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001270
John Hughes70623be2001-03-08 13:59:00 +00001271#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001272int
1273sys_lstat(tcp)
1274struct tcb *tcp;
1275{
1276 if (entering(tcp)) {
1277 printpath(tcp, tcp->u_arg[0]);
1278 tprintf(", ");
1279 } else {
1280 printstat(tcp, tcp->u_arg[1]);
1281 }
1282 return 0;
1283}
John Hughesb8c9f772001-03-07 16:53:07 +00001284#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001285
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001286int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001287sys_lstat64(tcp)
1288struct tcb *tcp;
1289{
1290#ifdef HAVE_STAT64
1291 if (entering(tcp)) {
1292 printpath(tcp, tcp->u_arg[0]);
1293 tprintf(", ");
1294 } else {
1295 printstat64(tcp, tcp->u_arg[1]);
1296 }
1297 return 0;
1298#else
1299 return printargs(tcp);
1300#endif
1301}
1302
Roland McGrath79db8af2003-06-27 21:20:09 +00001303#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001304int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001305sys_oldlstat(tcp)
1306struct tcb *tcp;
1307{
1308 if (entering(tcp)) {
1309 printpath(tcp, tcp->u_arg[0]);
1310 tprintf(", ");
1311 } else {
1312 printoldstat(tcp, tcp->u_arg[1]);
1313 }
1314 return 0;
1315}
Roland McGrath79db8af2003-06-27 21:20:09 +00001316#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001317
1318
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001319#if defined(SVR4) || defined(LINUXSPARC)
1320
1321int
1322sys_xstat(tcp)
1323struct tcb *tcp;
1324{
1325 if (entering(tcp)) {
1326 tprintf("%ld, ", tcp->u_arg[0]);
1327 printpath(tcp, tcp->u_arg[1]);
1328 tprintf(", ");
1329 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001330#ifdef _STAT64_VER
1331 if (tcp->u_arg[0] == _STAT64_VER)
1332 printstat64 (tcp, tcp->u_arg[2]);
1333 else
1334#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001335 printstat(tcp, tcp->u_arg[2]);
1336 }
1337 return 0;
1338}
1339
1340int
1341sys_fxstat(tcp)
1342struct tcb *tcp;
1343{
1344 if (entering(tcp))
1345 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1346 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001347#ifdef _STAT64_VER
1348 if (tcp->u_arg[0] == _STAT64_VER)
1349 printstat64 (tcp, tcp->u_arg[2]);
1350 else
1351#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001352 printstat(tcp, tcp->u_arg[2]);
1353 }
1354 return 0;
1355}
1356
1357int
1358sys_lxstat(tcp)
1359struct tcb *tcp;
1360{
1361 if (entering(tcp)) {
1362 tprintf("%ld, ", tcp->u_arg[0]);
1363 printpath(tcp, tcp->u_arg[1]);
1364 tprintf(", ");
1365 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001366#ifdef _STAT64_VER
1367 if (tcp->u_arg[0] == _STAT64_VER)
1368 printstat64 (tcp, tcp->u_arg[2]);
1369 else
1370#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001371 printstat(tcp, tcp->u_arg[2]);
1372 }
1373 return 0;
1374}
1375
1376int
1377sys_xmknod(tcp)
1378struct tcb *tcp;
1379{
1380 int mode = tcp->u_arg[2];
1381
1382 if (entering(tcp)) {
1383 tprintf("%ld, ", tcp->u_arg[0]);
1384 printpath(tcp, tcp->u_arg[1]);
1385 tprintf(", %s", sprintmode(mode));
1386 switch (mode & S_IFMT) {
1387 case S_IFCHR: case S_IFBLK:
1388#ifdef LINUXSPARC
1389 tprintf(", makedev(%lu, %lu)",
1390 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1391 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001392#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001393 tprintf(", makedev(%lu, %lu)",
1394 (unsigned long) major(tcp->u_arg[3]),
1395 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001396#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001397 break;
1398 default:
1399 break;
1400 }
1401 }
1402 return 0;
1403}
1404
Wichert Akkerman8829a551999-06-11 13:18:40 +00001405#ifdef HAVE_SYS_ACL_H
1406
1407#include <sys/acl.h>
1408
Roland McGratha4d48532005-06-08 20:45:28 +00001409static const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001410#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001411 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001412#endif
1413#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001414 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001415#endif
1416#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001417 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001418#endif
1419#ifdef ACL_GET
1420 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001421#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001422#ifdef ACL_SET
1423 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001424#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001425#ifdef ACL_CNT
1426 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001427#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001428 { 0, NULL },
1429};
1430
1431int
1432sys_acl(tcp)
1433struct tcb *tcp;
1434{
1435 if (entering(tcp)) {
1436 printpath(tcp, tcp->u_arg[0]);
1437 tprintf(", ");
1438 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1439 tprintf(", %ld", tcp->u_arg[2]);
1440 /*
1441 * FIXME - dump out the list of aclent_t's pointed to
1442 * by "tcp->u_arg[3]" if it's not NULL.
1443 */
1444 if (tcp->u_arg[3])
1445 tprintf(", %#lx", tcp->u_arg[3]);
1446 else
1447 tprintf(", NULL");
1448 }
1449 return 0;
1450}
1451
1452
1453int
1454sys_facl(tcp)
1455struct tcb *tcp;
1456{
1457 if (entering(tcp)) {
1458 tprintf("%ld, ", tcp->u_arg[0]);
1459 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1460 tprintf(", %ld", tcp->u_arg[2]);
1461 /*
1462 * FIXME - dump out the list of aclent_t's pointed to
1463 * by "tcp->u_arg[3]" if it's not NULL.
1464 */
1465 if (tcp->u_arg[3])
1466 tprintf(", %#lx", tcp->u_arg[3]);
1467 else
1468 tprintf(", NULL");
1469 }
1470 return 0;
1471}
1472
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001473
Roland McGratha4d48532005-06-08 20:45:28 +00001474static const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001475#ifdef IPC_SHM
1476 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001477#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001478#ifdef IPC_SEM
1479 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001480#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001481#ifdef IPC_MSG
1482 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001483#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001484 { 0, NULL },
1485};
1486
1487
1488int
1489sys_aclipc(tcp)
1490struct tcb *tcp;
1491{
1492 if (entering(tcp)) {
1493 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1494 tprintf(", %#lx, ", tcp->u_arg[1]);
1495 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1496 tprintf(", %ld", tcp->u_arg[3]);
1497 /*
1498 * FIXME - dump out the list of aclent_t's pointed to
1499 * by "tcp->u_arg[4]" if it's not NULL.
1500 */
1501 if (tcp->u_arg[4])
1502 tprintf(", %#lx", tcp->u_arg[4]);
1503 else
1504 tprintf(", NULL");
1505 }
1506 return 0;
1507}
1508
1509
1510
Wichert Akkerman8829a551999-06-11 13:18:40 +00001511#endif /* HAVE_SYS_ACL_H */
1512
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001513#endif /* SVR4 || LINUXSPARC */
1514
Michal Ludvig53b320f2002-09-23 13:30:09 +00001515#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001516
Roland McGrathd9f816f2004-09-04 03:39:20 +00001517static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001518 { 0x73757245, "CODA_SUPER_MAGIC" },
1519 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1520 { 0x1373, "DEVFS_SUPER_MAGIC" },
1521 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1522 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001523 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1524 { 0xef53, "EXT2_SUPER_MAGIC" },
1525 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001526 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001527 { 0x9660, "ISOFS_SUPER_MAGIC" },
1528 { 0x137f, "MINIX_SUPER_MAGIC" },
1529 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001530 { 0x2468, "MINIX2_SUPER_MAGIC" },
1531 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001532 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001533 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001534 { 0x6969, "NFS_SUPER_MAGIC" },
1535 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001536 { 0x002f, "QNX4_SUPER_MAGIC" },
1537 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1538 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1539 { 0x517b, "SMB_SUPER_MAGIC" },
1540 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1541 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1542 { 0x00011954, "UFS_MAGIC" },
1543 { 0x54190100, "UFS_CIGAM" },
1544 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001545 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001546 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001547 { 0, NULL },
1548};
1549
Michal Ludvig53b320f2002-09-23 13:30:09 +00001550#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001551
1552#ifndef SVR4
1553
Roland McGrathf9c49b22004-10-06 22:11:54 +00001554static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001555sprintfstype(magic)
1556int magic;
1557{
1558 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001559#ifdef LINUX
Roland McGrathf9c49b22004-10-06 22:11:54 +00001560 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001561
1562 s = xlookup(fsmagic, magic);
1563 if (s) {
1564 sprintf(buf, "\"%s\"", s);
1565 return buf;
1566 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001567#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001568 sprintf(buf, "%#x", magic);
1569 return buf;
1570}
1571
1572static void
1573printstatfs(tcp, addr)
1574struct tcb *tcp;
1575long addr;
1576{
1577 struct statfs statbuf;
1578
1579 if (syserror(tcp) || !verbose(tcp)) {
1580 tprintf("%#lx", addr);
1581 return;
1582 }
1583 if (umove(tcp, addr, &statbuf) < 0) {
1584 tprintf("{...}");
1585 return;
1586 }
1587#ifdef ALPHA
1588
1589 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1590 sprintfstype(statbuf.f_type),
1591 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001592 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1593 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1594 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1595 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001596#else /* !ALPHA */
1597 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1598 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001599 (unsigned long)statbuf.f_bsize,
1600 (unsigned long)statbuf.f_blocks,
1601 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001602 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1603 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001604 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001605 (unsigned long)statbuf.f_ffree,
1606 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001607#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001608 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001609#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001610#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001611#ifdef _STATFS_F_FRSIZE
1612 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1613#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001614 tprintf("}");
1615}
1616
1617int
1618sys_statfs(tcp)
1619struct tcb *tcp;
1620{
1621 if (entering(tcp)) {
1622 printpath(tcp, tcp->u_arg[0]);
1623 tprintf(", ");
1624 } else {
1625 printstatfs(tcp, tcp->u_arg[1]);
1626 }
1627 return 0;
1628}
1629
1630int
1631sys_fstatfs(tcp)
1632struct tcb *tcp;
1633{
1634 if (entering(tcp)) {
1635 tprintf("%lu, ", tcp->u_arg[0]);
1636 } else {
1637 printstatfs(tcp, tcp->u_arg[1]);
1638 }
1639 return 0;
1640}
1641
Roland McGrathab147c52003-07-17 09:03:02 +00001642#ifdef LINUX
1643static void
1644printstatfs64(tcp, addr)
1645struct tcb *tcp;
1646long addr;
1647{
1648 struct statfs64 statbuf;
1649
1650 if (syserror(tcp) || !verbose(tcp)) {
1651 tprintf("%#lx", addr);
1652 return;
1653 }
1654 if (umove(tcp, addr, &statbuf) < 0) {
1655 tprintf("{...}");
1656 return;
1657 }
Roland McGrath08738432005-06-03 02:40:39 +00001658 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001659 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001660 (unsigned long long)statbuf.f_bsize,
1661 (unsigned long long)statbuf.f_blocks,
1662 (unsigned long long)statbuf.f_bfree);
1663 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1664 (unsigned long long)statbuf.f_bavail,
1665 (unsigned long long)statbuf.f_files,
1666 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001667 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1668 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001669#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001670 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001671#endif
1672 tprintf("}");
1673}
1674
1675int
1676sys_statfs64(tcp)
1677struct tcb *tcp;
1678{
1679 if (entering(tcp)) {
1680 printpath(tcp, tcp->u_arg[0]);
1681 tprintf(", %lu, ", tcp->u_arg[1]);
1682 } else {
1683 if (tcp->u_arg[1] == sizeof (struct statfs64))
1684 printstatfs64(tcp, tcp->u_arg[2]);
1685 else
1686 tprintf("{???}");
1687 }
1688 return 0;
1689}
1690
1691int
1692sys_fstatfs64(tcp)
1693struct tcb *tcp;
1694{
1695 if (entering(tcp)) {
1696 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1697 } else {
1698 if (tcp->u_arg[1] == sizeof (struct statfs64))
1699 printstatfs64(tcp, tcp->u_arg[2]);
1700 else
1701 tprintf("{???}");
1702 }
1703 return 0;
1704}
1705#endif
1706
Michal Ludvig53b320f2002-09-23 13:30:09 +00001707#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001708
1709int
1710osf_statfs(tcp)
1711struct tcb *tcp;
1712{
1713 if (entering(tcp)) {
1714 printpath(tcp, tcp->u_arg[0]);
1715 tprintf(", ");
1716 } else {
1717 printstatfs(tcp, tcp->u_arg[1]);
1718 tprintf(", %lu", tcp->u_arg[2]);
1719 }
1720 return 0;
1721}
1722
1723int
1724osf_fstatfs(tcp)
1725struct tcb *tcp;
1726{
1727 if (entering(tcp)) {
1728 tprintf("%lu, ", tcp->u_arg[0]);
1729 } else {
1730 printstatfs(tcp, tcp->u_arg[1]);
1731 tprintf(", %lu", tcp->u_arg[2]);
1732 }
1733 return 0;
1734}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001735#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001736
1737#endif /* !SVR4 */
1738
1739#ifdef SUNOS4
1740
1741int
1742sys_ustat(tcp)
1743struct tcb *tcp;
1744{
1745 struct ustat statbuf;
1746
1747 if (entering(tcp)) {
1748 tprintf("makedev(%lu, %lu), ",
1749 (long) major(tcp->u_arg[0]),
1750 (long) minor(tcp->u_arg[0]));
1751 }
1752 else {
1753 if (syserror(tcp) || !verbose(tcp))
1754 tprintf("%#lx", tcp->u_arg[1]);
1755 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1756 tprintf("{...}");
1757 else {
1758 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1759 statbuf.f_tfree, statbuf.f_tinode);
1760 tprintf("f_fname=\"%.*s\", ",
1761 (int) sizeof(statbuf.f_fname),
1762 statbuf.f_fname);
1763 tprintf("f_fpack=\"%.*s\"}",
1764 (int) sizeof(statbuf.f_fpack),
1765 statbuf.f_fpack);
1766 }
1767 }
1768 return 0;
1769}
1770
1771#endif /* SUNOS4 */
1772
Wichert Akkermanc7926982000-04-10 22:22:31 +00001773int
1774sys_pivotroot(tcp)
1775struct tcb *tcp;
1776{
1777 if (entering(tcp)) {
1778 printpath(tcp, tcp->u_arg[0]);
1779 tprintf(", ");
1780 printpath(tcp, tcp->u_arg[1]);
1781 }
1782 return 0;
1783}
1784
1785
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001786/* directory */
1787int
1788sys_chdir(tcp)
1789struct tcb *tcp;
1790{
1791 if (entering(tcp)) {
1792 printpath(tcp, tcp->u_arg[0]);
1793 }
1794 return 0;
1795}
1796
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001797static int
1798decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001799{
1800 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001801 printpath(tcp, tcp->u_arg[offset]);
1802 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001803 }
1804 return 0;
1805}
1806
1807int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001808sys_mkdir(struct tcb *tcp)
1809{
1810 return decode_mkdir(tcp, 0);
1811}
1812
1813#ifdef LINUX
1814int
1815sys_mkdirat(struct tcb *tcp)
1816{
1817 if (entering(tcp))
1818 print_dirfd(tcp->u_arg[0]);
1819 return decode_mkdir(tcp, 1);
1820}
1821#endif
1822
1823int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001824sys_rmdir(tcp)
1825struct tcb *tcp;
1826{
1827 if (entering(tcp)) {
1828 printpath(tcp, tcp->u_arg[0]);
1829 }
1830 return 0;
1831}
1832
1833int
1834sys_fchdir(tcp)
1835struct tcb *tcp;
1836{
1837 if (entering(tcp)) {
1838 tprintf("%ld", tcp->u_arg[0]);
1839 }
1840 return 0;
1841}
1842
1843int
1844sys_chroot(tcp)
1845struct tcb *tcp;
1846{
1847 if (entering(tcp)) {
1848 printpath(tcp, tcp->u_arg[0]);
1849 }
1850 return 0;
1851}
1852
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001853#if defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001854int
1855sys_fchroot(tcp)
1856struct tcb *tcp;
1857{
1858 if (entering(tcp)) {
1859 tprintf("%ld", tcp->u_arg[0]);
1860 }
1861 return 0;
1862}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001863#endif /* SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001864
1865int
1866sys_link(tcp)
1867struct tcb *tcp;
1868{
1869 if (entering(tcp)) {
1870 printpath(tcp, tcp->u_arg[0]);
1871 tprintf(", ");
1872 printpath(tcp, tcp->u_arg[1]);
1873 }
1874 return 0;
1875}
1876
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001877#ifdef LINUX
1878int
1879sys_linkat(struct tcb *tcp)
1880{
1881 if (entering(tcp)) {
1882 print_dirfd(tcp->u_arg[0]);
1883 printpath(tcp, tcp->u_arg[1]);
1884 tprintf(", ");
1885 print_dirfd(tcp->u_arg[2]);
1886 printpath(tcp, tcp->u_arg[3]);
1887 tprintf(", %ld", tcp->u_arg[4]);
1888 }
1889 return 0;
1890}
1891#endif
1892
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001893int
1894sys_unlink(tcp)
1895struct tcb *tcp;
1896{
1897 if (entering(tcp)) {
1898 printpath(tcp, tcp->u_arg[0]);
1899 }
1900 return 0;
1901}
1902
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001903#ifdef LINUX
1904static const struct xlat unlinkatflags[] = {
1905#ifndef AT_REMOVEDIR
1906# define AT_REMOVEDIR 0x200
1907#endif
1908 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1909 { 0, NULL },
1910};
1911
1912int
1913sys_unlinkat(struct tcb *tcp)
1914{
1915 if (entering(tcp)) {
1916 print_dirfd(tcp->u_arg[0]);
1917 printpath(tcp, tcp->u_arg[1]);
1918 tprintf(", ");
1919 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1920 }
1921 return 0;
1922}
1923#endif
1924
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001925int
1926sys_symlink(tcp)
1927struct tcb *tcp;
1928{
1929 if (entering(tcp)) {
1930 printpath(tcp, tcp->u_arg[0]);
1931 tprintf(", ");
1932 printpath(tcp, tcp->u_arg[1]);
1933 }
1934 return 0;
1935}
1936
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001937#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001938int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001939sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001940{
1941 if (entering(tcp)) {
1942 printpath(tcp, tcp->u_arg[0]);
1943 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001944 print_dirfd(tcp->u_arg[1]);
1945 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001946 }
1947 return 0;
1948}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001949#endif
1950
1951static int
1952decode_readlink(struct tcb *tcp, int offset)
1953{
1954 if (entering(tcp)) {
1955 printpath(tcp, tcp->u_arg[offset]);
1956 tprintf(", ");
1957 } else {
1958 if (syserror(tcp))
1959 tprintf("%#lx", tcp->u_arg[offset + 1]);
1960 else
1961 printpathn(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1962 tprintf(", %lu", tcp->u_arg[offset + 2]);
1963 }
1964 return 0;
1965}
1966
1967int
1968sys_readlink(struct tcb *tcp)
1969{
1970 return decode_readlink(tcp, 0);
1971}
1972
1973#ifdef LINUX
1974int
1975sys_readlinkat(struct tcb *tcp)
1976{
1977 if (entering(tcp))
1978 print_dirfd(tcp->u_arg[0]);
1979 return decode_readlink(tcp, 1);
1980}
1981#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001982
1983int
1984sys_rename(tcp)
1985struct tcb *tcp;
1986{
1987 if (entering(tcp)) {
1988 printpath(tcp, tcp->u_arg[0]);
1989 tprintf(", ");
1990 printpath(tcp, tcp->u_arg[1]);
1991 }
1992 return 0;
1993}
1994
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001995#ifdef LINUX
1996int
1997sys_renameat(struct tcb *tcp)
1998{
1999 if (entering(tcp)) {
2000 print_dirfd(tcp->u_arg[0]);
2001 printpath(tcp, tcp->u_arg[1]);
2002 tprintf(", ");
2003 print_dirfd(tcp->u_arg[2]);
2004 printpath(tcp, tcp->u_arg[3]);
2005 }
2006 return 0;
2007}
2008#endif
2009
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002010int
2011sys_chown(tcp)
2012struct tcb *tcp;
2013{
2014 if (entering(tcp)) {
2015 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002016 printuid(", ", tcp->u_arg[1]);
2017 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002018 }
2019 return 0;
2020}
2021
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002022#ifdef LINUX
2023int
2024sys_fchownat(struct tcb *tcp)
2025{
2026 if (entering(tcp)) {
2027 print_dirfd(tcp->u_arg[0]);
2028 printpath(tcp, tcp->u_arg[1]);
2029 printuid(", ", tcp->u_arg[2]);
2030 printuid(", ", tcp->u_arg[3]);
2031 tprintf(", ");
2032 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
2033 }
2034 return 0;
2035}
2036#endif
2037
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002038int
2039sys_fchown(tcp)
2040struct tcb *tcp;
2041{
2042 if (entering(tcp)) {
Roland McGrath6bc12202003-11-13 22:32:27 +00002043 tprintf("%ld", tcp->u_arg[0]);
2044 printuid(", ", tcp->u_arg[1]);
2045 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002046 }
2047 return 0;
2048}
2049
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002050static int
2051decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002052{
2053 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002054 printpath(tcp, tcp->u_arg[offset]);
2055 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002056 }
2057 return 0;
2058}
2059
2060int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002061sys_chmod(struct tcb *tcp)
2062{
2063 return decode_chmod(tcp, 0);
2064}
2065
2066#ifdef LINUX
2067int
2068sys_fchmodat(struct tcb *tcp)
2069{
2070 if (entering(tcp))
2071 print_dirfd(tcp->u_arg[0]);
2072 return decode_chmod(tcp, 1);
2073}
2074#endif
2075
2076int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002077sys_fchmod(tcp)
2078struct tcb *tcp;
2079{
2080 if (entering(tcp)) {
2081 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
2082 }
2083 return 0;
2084}
2085
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002086#ifdef ALPHA
2087int
2088sys_osf_utimes(tcp)
2089struct tcb *tcp;
2090{
2091 if (entering(tcp)) {
2092 printpath(tcp, tcp->u_arg[0]);
2093 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002094 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002095 }
2096 return 0;
2097}
2098#endif
2099
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002100static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002101decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002102{
2103 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002104 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002105 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002106 if (tcp->u_arg[offset + 1] == 0)
2107 tprintf("NULL");
2108 else {
2109 tprintf("{");
2110 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2111 BITNESS_CURRENT, special);
2112 tprintf(", ");
2113 printtv_bitness(tcp, tcp->u_arg[offset + 1]
2114 + sizeof (struct timeval),
2115 BITNESS_CURRENT, special);
2116 tprintf("}");
2117 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002118 }
2119 return 0;
2120}
2121
2122int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002123sys_utimes(struct tcb *tcp)
2124{
Roland McGrath6afc5652007-07-24 01:57:11 +00002125 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002126}
2127
2128#ifdef LINUX
2129int
2130sys_futimesat(struct tcb *tcp)
2131{
2132 if (entering(tcp))
2133 print_dirfd(tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002134 return decode_utimes(tcp, 1, 0);
2135}
2136
2137int
2138sys_utimensat(struct tcb *tcp)
2139{
2140 if (entering(tcp)) {
2141 print_dirfd(tcp->u_arg[0]);
2142 decode_utimes(tcp, 1, 1);
2143 tprintf(", ");
2144 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2145 }
2146 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002147}
2148#endif
2149
2150int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002151sys_utime(tcp)
2152struct tcb *tcp;
2153{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002154 union {
2155 long utl[2];
2156 int uti[2];
2157 } u;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002158
2159 if (entering(tcp)) {
2160 printpath(tcp, tcp->u_arg[0]);
2161 tprintf(", ");
2162 if (!tcp->u_arg[1])
2163 tprintf("NULL");
2164 else if (!verbose(tcp))
2165 tprintf("%#lx", tcp->u_arg[1]);
Roland McGrath7e9817c2007-07-05 20:31:58 +00002166 else if (umoven(tcp, tcp->u_arg[1],
2167 2 * personality_wordsize[current_personality],
2168 (char *) &u) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002169 tprintf("[?, ?]");
Roland McGrath7e9817c2007-07-05 20:31:58 +00002170 else if (personality_wordsize[current_personality]
2171 == sizeof u.utl[0]) {
2172 tprintf("[%s,", sprinttime(u.utl[0]));
2173 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002174 }
Roland McGrath7e9817c2007-07-05 20:31:58 +00002175 else if (personality_wordsize[current_personality]
2176 == sizeof u.uti[0]) {
2177 tprintf("[%s,", sprinttime(u.uti[0]));
2178 tprintf(" %s]", sprinttime(u.uti[1]));
2179 }
2180 else
2181 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002182 }
2183 return 0;
2184}
2185
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002186static int
2187decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002188{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002189 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002190
2191 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002192 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002193 tprintf(", %s", sprintmode(mode));
2194 switch (mode & S_IFMT) {
2195 case S_IFCHR: case S_IFBLK:
2196#ifdef LINUXSPARC
2197 if (current_personality == 1)
2198 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002199 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2200 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002201 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002202#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002203 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002204 (unsigned long) major(tcp->u_arg[offset + 2]),
2205 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002206 break;
2207 default:
2208 break;
2209 }
2210 }
2211 return 0;
2212}
2213
2214int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002215sys_mknod(struct tcb *tcp)
2216{
2217 return decode_mknod(tcp, 0);
2218}
2219
2220#ifdef LINUX
2221int
2222sys_mknodat(struct tcb *tcp)
2223{
2224 if (entering(tcp))
2225 print_dirfd(tcp->u_arg[0]);
2226 return decode_mknod(tcp, 1);
2227}
2228#endif
2229
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002230#ifdef FREEBSD
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002231int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002232sys_mkfifo(tcp)
2233struct tcb *tcp;
2234{
2235 if (entering(tcp)) {
2236 printpath(tcp, tcp->u_arg[0]);
2237 tprintf(", %#lo", tcp->u_arg[1]);
2238 }
2239 return 0;
2240}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002241#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002242
2243int
2244sys_fsync(tcp)
2245struct tcb *tcp;
2246{
2247 if (entering(tcp)) {
2248 tprintf("%ld", tcp->u_arg[0]);
2249 }
2250 return 0;
2251}
2252
Michal Ludvig53b320f2002-09-23 13:30:09 +00002253#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002254
2255static void
2256printdir(tcp, addr)
2257struct tcb *tcp;
2258long addr;
2259{
2260 struct dirent d;
2261
2262 if (!verbose(tcp)) {
2263 tprintf("%#lx", addr);
2264 return;
2265 }
2266 if (umove(tcp, addr, &d) < 0) {
2267 tprintf("{...}");
2268 return;
2269 }
2270 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002271 tprintf("d_name=");
2272 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2273 tprintf("}");
2274}
2275
2276int
2277sys_readdir(tcp)
2278struct tcb *tcp;
2279{
2280 if (entering(tcp)) {
2281 tprintf("%lu, ", tcp->u_arg[0]);
2282 } else {
2283 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2284 tprintf("%#lx", tcp->u_arg[1]);
2285 else
2286 printdir(tcp, tcp->u_arg[1]);
2287 /* Not much point in printing this out, it is always 1. */
2288 if (tcp->u_arg[2] != 1)
2289 tprintf(", %lu", tcp->u_arg[2]);
2290 }
2291 return 0;
2292}
2293
Michal Ludvig53b320f2002-09-23 13:30:09 +00002294#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002295
Roland McGrath40542842004-01-13 09:47:49 +00002296#if defined FREEBSD || defined LINUX
Roland McGratha4d48532005-06-08 20:45:28 +00002297static const struct xlat direnttypes[] = {
Roland McGrath40542842004-01-13 09:47:49 +00002298 { DT_UNKNOWN, "DT_UNKNOWN" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002299 { DT_FIFO, "DT_FIFO" },
2300 { DT_CHR, "DT_CHR" },
2301 { DT_DIR, "DT_DIR" },
2302 { DT_BLK, "DT_BLK" },
2303 { DT_REG, "DT_REG" },
2304 { DT_LNK, "DT_LNK" },
2305 { DT_SOCK, "DT_SOCK" },
2306 { DT_WHT, "DT_WHT" },
2307 { 0, NULL },
2308};
2309
2310#endif
2311
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002312int
2313sys_getdents(tcp)
2314struct tcb *tcp;
2315{
2316 int i, len, dents = 0;
2317 char *buf;
2318
2319 if (entering(tcp)) {
2320 tprintf("%lu, ", tcp->u_arg[0]);
2321 return 0;
2322 }
2323 if (syserror(tcp) || !verbose(tcp)) {
2324 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2325 return 0;
2326 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002327 len = tcp->u_rval;
2328 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002329 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2330 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002331 return 0;
2332 }
2333 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002334 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002335 free(buf);
2336 return 0;
2337 }
2338 if (!abbrev(tcp))
2339 tprintf("{");
2340 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002341 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002342#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002343 if (!abbrev(tcp)) {
2344 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2345 i ? " " : "", d->d_ino, d->d_off);
2346 tprintf("d_reclen=%u, d_name=\"%s\"}",
2347 d->d_reclen, d->d_name);
2348 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002349#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002350#ifdef SVR4
2351 if (!abbrev(tcp)) {
2352 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002353 i ? " " : "",
2354 (unsigned long) d->d_ino,
2355 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002356 tprintf("d_reclen=%u, d_name=\"%s\"}",
2357 d->d_reclen, d->d_name);
2358 }
2359#endif /* SVR4 */
2360#ifdef SUNOS4
2361 if (!abbrev(tcp)) {
2362 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2363 i ? " " : "", d->d_off, d->d_fileno,
2364 d->d_reclen);
2365 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2366 d->d_namlen, d->d_namlen, d->d_name);
2367 }
2368#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002369#ifdef FREEBSD
2370 if (!abbrev(tcp)) {
2371 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2372 i ? " " : "", d->d_fileno, d->d_reclen);
2373 printxval(direnttypes, d->d_type, "DT_???");
2374 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2375 d->d_namlen, d->d_namlen, d->d_name);
2376 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002377#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002378 if (!d->d_reclen) {
2379 tprintf("/* d_reclen == 0, problem here */");
2380 break;
2381 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002382 i += d->d_reclen;
2383 dents++;
2384 }
2385 if (!abbrev(tcp))
2386 tprintf("}");
2387 else
2388 tprintf("/* %u entries */", dents);
2389 tprintf(", %lu", tcp->u_arg[2]);
2390 free(buf);
2391 return 0;
2392}
2393
John Hughesbdf48f52001-03-06 15:08:09 +00002394
2395#if _LFS64_LARGEFILE
2396int
2397sys_getdents64(tcp)
2398struct tcb *tcp;
2399{
2400 int i, len, dents = 0;
2401 char *buf;
2402
2403 if (entering(tcp)) {
2404 tprintf("%lu, ", tcp->u_arg[0]);
2405 return 0;
2406 }
2407 if (syserror(tcp) || !verbose(tcp)) {
2408 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2409 return 0;
2410 }
2411 len = tcp->u_rval;
2412 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002413 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2414 fprintf(stderr, "out of memory\n");
John Hughesbdf48f52001-03-06 15:08:09 +00002415 return 0;
2416 }
2417 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002418 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002419 free(buf);
2420 return 0;
2421 }
2422 if (!abbrev(tcp))
2423 tprintf("{");
2424 for (i = 0; i < len;) {
2425 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002426#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002427 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002428 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002429 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002430 d->d_ino,
2431 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002432#ifdef LINUX
2433 tprintf("d_type=");
2434 printxval(direnttypes, d->d_type, "DT_???");
2435 tprintf(", ");
2436#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002437 tprintf("d_reclen=%u, d_name=\"%s\"}",
2438 d->d_reclen, d->d_name);
2439 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002440#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002441#ifdef SUNOS4
2442 if (!abbrev(tcp)) {
2443 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2444 i ? " " : "", d->d_off, d->d_fileno,
2445 d->d_reclen);
2446 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2447 d->d_namlen, d->d_namlen, d->d_name);
2448 }
2449#endif /* SUNOS4 */
2450 i += d->d_reclen;
2451 dents++;
2452 }
2453 if (!abbrev(tcp))
2454 tprintf("}");
2455 else
2456 tprintf("/* %u entries */", dents);
2457 tprintf(", %lu", tcp->u_arg[2]);
2458 free(buf);
2459 return 0;
2460}
2461#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002462
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002463#ifdef FREEBSD
2464int
2465sys_getdirentries(tcp)
2466struct tcb * tcp;
2467{
2468 int i, len, dents = 0;
2469 long basep;
2470 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002471
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002472 if (entering(tcp)) {
2473 tprintf("%lu, ", tcp->u_arg[0]);
2474 return 0;
2475 }
2476 if (syserror(tcp) || !verbose(tcp)) {
2477 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2478 return 0;
2479 }
2480 len = tcp->u_rval;
2481 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002482 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2483 fprintf(stderr, "out of memory\n");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002484 return 0;
2485 }
2486 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002487 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002488 free(buf);
2489 return 0;
2490 }
2491 if (!abbrev(tcp))
2492 tprintf("{");
2493 for (i = 0; i < len;) {
2494 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2495 if (!abbrev(tcp)) {
2496 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2497 i ? " " : "", d->d_fileno, d->d_reclen);
2498 printxval(direnttypes, d->d_type, "DT_???");
2499 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2500 d->d_namlen, d->d_namlen, d->d_name);
2501 }
2502 i += d->d_reclen;
2503 dents++;
2504 }
2505 if (!abbrev(tcp))
2506 tprintf("}");
2507 else
2508 tprintf("/* %u entries */", dents);
2509 free(buf);
2510 tprintf(", %lu", tcp->u_arg[2]);
2511 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2512 tprintf(", %#lx", tcp->u_arg[3]);
2513 else
2514 tprintf(", [%lu]", basep);
2515 return 0;
2516}
2517#endif
2518
Michal Ludvig53b320f2002-09-23 13:30:09 +00002519#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002520int
2521sys_getcwd(tcp)
2522struct tcb *tcp;
2523{
2524 if (exiting(tcp)) {
2525 if (syserror(tcp))
2526 tprintf("%#lx", tcp->u_arg[0]);
2527 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002528 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002529 tprintf(", %lu", tcp->u_arg[1]);
2530 }
2531 return 0;
2532}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002533#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002534
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002535#ifdef FREEBSD
2536int
2537sys___getcwd(tcp)
2538struct tcb *tcp;
2539{
2540 if (exiting(tcp)) {
2541 if (syserror(tcp))
2542 tprintf("%#lx", tcp->u_arg[0]);
2543 else
2544 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2545 tprintf(", %lu", tcp->u_arg[1]);
2546 }
2547 return 0;
2548}
2549#endif
2550
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002551#ifdef HAVE_SYS_ASYNCH_H
2552
2553int
2554sys_aioread(tcp)
2555struct tcb *tcp;
2556{
2557 struct aio_result_t res;
2558
2559 if (entering(tcp)) {
2560 tprintf("%lu, ", tcp->u_arg[0]);
2561 } else {
2562 if (syserror(tcp))
2563 tprintf("%#lx", tcp->u_arg[1]);
2564 else
2565 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2566 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2567 printxval(whence, tcp->u_arg[4], "L_???");
2568 if (syserror(tcp) || tcp->u_arg[5] == 0
2569 || umove(tcp, tcp->u_arg[5], &res) < 0)
2570 tprintf(", %#lx", tcp->u_arg[5]);
2571 else
2572 tprintf(", {aio_return %d aio_errno %d}",
2573 res.aio_return, res.aio_errno);
2574 }
2575 return 0;
2576}
2577
2578int
2579sys_aiowrite(tcp)
2580struct tcb *tcp;
2581{
2582 struct aio_result_t res;
2583
2584 if (entering(tcp)) {
2585 tprintf("%lu, ", tcp->u_arg[0]);
2586 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2587 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2588 printxval(whence, tcp->u_arg[4], "L_???");
2589 }
2590 else {
2591 if (tcp->u_arg[5] == 0)
2592 tprintf(", NULL");
2593 else if (syserror(tcp)
2594 || umove(tcp, tcp->u_arg[5], &res) < 0)
2595 tprintf(", %#lx", tcp->u_arg[5]);
2596 else
2597 tprintf(", {aio_return %d aio_errno %d}",
2598 res.aio_return, res.aio_errno);
2599 }
2600 return 0;
2601}
2602
2603int
2604sys_aiowait(tcp)
2605struct tcb *tcp;
2606{
2607 if (entering(tcp))
2608 printtv(tcp, tcp->u_arg[0]);
2609 return 0;
2610}
2611
2612int
2613sys_aiocancel(tcp)
2614struct tcb *tcp;
2615{
2616 struct aio_result_t res;
2617
2618 if (exiting(tcp)) {
2619 if (tcp->u_arg[0] == 0)
2620 tprintf("NULL");
2621 else if (syserror(tcp)
2622 || umove(tcp, tcp->u_arg[0], &res) < 0)
2623 tprintf("%#lx", tcp->u_arg[0]);
2624 else
2625 tprintf("{aio_return %d aio_errno %d}",
2626 res.aio_return, res.aio_errno);
2627 }
2628 return 0;
2629}
2630
2631#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002632
Roland McGratha4d48532005-06-08 20:45:28 +00002633static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002634#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002635 { XATTR_CREATE, "XATTR_CREATE" },
2636 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002637#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002638 { 0, NULL }
2639};
2640
Roland McGrath3292e222004-08-31 06:30:48 +00002641static void
2642print_xattr_val(tcp, failed, arg, insize, size)
2643struct tcb *tcp;
2644int failed;
2645unsigned long arg;
Roland McGrathaa524c82005-06-01 19:22:06 +00002646unsigned long insize, size;
Roland McGrath3292e222004-08-31 06:30:48 +00002647{
Roland McGrath883567c2005-02-02 03:38:32 +00002648 if (!failed) {
Roland McGrathaa524c82005-06-01 19:22:06 +00002649 unsigned long capacity = 4 * size + 1;
2650 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
Roland McGrath883567c2005-02-02 03:38:32 +00002651 if (buf == NULL || /* probably a bogus size argument */
Roland McGrathf7746422005-03-01 23:02:32 +00002652 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
Roland McGrath883567c2005-02-02 03:38:32 +00002653 failed = 1;
2654 }
2655 else {
2656 unsigned char *out = buf;
2657 unsigned char *in = &buf[3 * size];
2658 size_t i;
2659 for (i = 0; i < size; ++i)
2660 if (isprint(in[i]))
2661 *out++ = in[i];
2662 else {
Roland McGrath3292e222004-08-31 06:30:48 +00002663#define tohex(n) "0123456789abcdef"[n]
Roland McGrath883567c2005-02-02 03:38:32 +00002664 *out++ = '\\';
2665 *out++ = 'x';
2666 *out++ = tohex(in[i] / 16);
2667 *out++ = tohex(in[i] % 16);
2668 }
2669 /* Don't print terminating NUL if there is one. */
Dmitry V. Levin504eb0b2006-10-11 22:58:31 +00002670 if (i > 0 && in[i - 1] == '\0')
Roland McGrath883567c2005-02-02 03:38:32 +00002671 out -= 4;
2672 *out = '\0';
2673 tprintf(", \"%s\", %ld", buf, insize);
2674 }
2675 free(buf);
2676 }
2677 if (failed)
2678 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002679}
2680
Roland McGrath186c5ac2002-12-15 23:58:23 +00002681int
2682sys_setxattr(tcp)
2683struct tcb *tcp;
2684{
2685 if (entering(tcp)) {
2686 printpath(tcp, tcp->u_arg[0]);
2687 tprintf(", ");
2688 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002689 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2690 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002691 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002692 }
2693 return 0;
2694}
2695
2696int
2697sys_fsetxattr(tcp)
2698struct tcb *tcp;
2699{
2700 if (entering(tcp)) {
2701 tprintf("%ld, ", tcp->u_arg[0]);
2702 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002703 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2704 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002705 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002706 }
2707 return 0;
2708}
2709
2710int
2711sys_getxattr(tcp)
2712struct tcb *tcp;
2713{
2714 if (entering(tcp)) {
2715 printpath(tcp, tcp->u_arg[0]);
2716 tprintf(", ");
2717 printstr(tcp, tcp->u_arg[1], -1);
2718 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002719 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2720 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002721 }
2722 return 0;
2723}
2724
2725int
2726sys_fgetxattr(tcp)
2727struct tcb *tcp;
2728{
2729 if (entering(tcp)) {
2730 tprintf("%ld, ", tcp->u_arg[0]);
2731 printstr(tcp, tcp->u_arg[1], -1);
2732 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002733 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2734 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002735 }
2736 return 0;
2737}
2738
2739int
2740sys_listxattr(tcp)
2741struct tcb *tcp;
2742{
2743 if (entering(tcp)) {
2744 printpath(tcp, tcp->u_arg[0]);
2745 } else {
2746 /* XXX Print value in format */
2747 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2748 }
2749 return 0;
2750}
2751
2752int
2753sys_flistxattr(tcp)
2754struct tcb *tcp;
2755{
2756 if (entering(tcp)) {
2757 tprintf("%ld", tcp->u_arg[0]);
2758 } else {
2759 /* XXX Print value in format */
2760 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2761 }
2762 return 0;
2763}
2764
2765int
2766sys_removexattr(tcp)
2767struct tcb *tcp;
2768{
2769 if (entering(tcp)) {
2770 printpath(tcp, tcp->u_arg[0]);
2771 tprintf(", ");
2772 printstr(tcp, tcp->u_arg[1], -1);
2773 }
2774 return 0;
2775}
2776
2777int
2778sys_fremovexattr(tcp)
2779struct tcb *tcp;
2780{
2781 if (entering(tcp)) {
2782 tprintf("%ld, ", tcp->u_arg[0]);
2783 printstr(tcp, tcp->u_arg[1], -1);
2784 }
2785 return 0;
2786}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002787
2788
2789static const struct xlat advise[] = {
2790 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2791 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2792 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2793 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2794 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2795 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2796 { 0, NULL }
2797};
2798
2799
Roland McGrathe27ed342004-10-20 02:24:19 +00002800#ifdef LINUX
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002801int
2802sys_fadvise64(tcp)
2803struct tcb *tcp;
2804{
2805 if (entering(tcp)) {
2806 tprintf("%ld, %lld, %ld, ",
2807 tcp->u_arg[0],
2808# if defined IA64 || defined X86_64 || defined ALPHA
2809 (long long int) tcp->u_arg[1], tcp->u_arg[2]);
2810 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2811#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002812 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
2813 printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002814#endif
2815 }
2816 return 0;
2817}
2818#endif
2819
2820
2821int
2822sys_fadvise64_64(tcp)
2823struct tcb *tcp;
2824{
2825 if (entering(tcp)) {
2826 tprintf("%ld, %lld, %lld, ",
2827 tcp->u_arg[0],
2828# if defined IA64 || defined X86_64 || defined ALPHA
2829 (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
2830 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2831#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002832 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
2833 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002834 printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
2835#endif
2836 }
2837 return 0;
2838}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002839
2840#ifdef LINUX
2841static const struct xlat inotify_modes[] = {
2842 { 0x00000001, "IN_ACCESS" },
2843 { 0x00000002, "IN_MODIFY" },
2844 { 0x00000004, "IN_ATTRIB" },
2845 { 0x00000008, "IN_CLOSE_WRITE" },
2846 { 0x00000010, "IN_CLOSE_NOWRITE" },
2847 { 0x00000020, "IN_OPEN" },
2848 { 0x00000040, "IN_MOVED_FROM" },
2849 { 0x00000080, "IN_MOVED_TO" },
2850 { 0x00000100, "IN_CREATE" },
2851 { 0x00000200, "IN_DELETE" },
2852 { 0x00000400, "IN_DELETE_SELF" },
2853 { 0x00000800, "IN_MOVE_SELF" },
2854 { 0x00002000, "IN_UNMOUNT" },
2855 { 0x00004000, "IN_Q_OVERFLOW" },
2856 { 0x00008000, "IN_IGNORED" },
2857 { 0x01000000, "IN_ONLYDIR" },
2858 { 0x02000000, "IN_DONT_FOLLOW" },
2859 { 0x20000000, "IN_MASK_ADD" },
2860 { 0x40000000, "IN_ISDIR" },
2861 { 0x80000000, "IN_ONESHOT" }
2862};
2863
2864int
2865sys_inotify_add_watch(struct tcb *tcp)
2866{
2867 if (entering(tcp)) {
2868 tprintf("%ld, ", tcp->u_arg[0]);
2869 printpath(tcp, tcp->u_arg[1]);
2870 tprintf(", ");
2871 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2872 }
2873 return 0;
2874}
2875
2876int
2877sys_inotify_rm_watch(struct tcb *tcp)
2878{
2879 if (entering(tcp)) {
2880 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
2881 }
2882 return 0;
2883}
2884#endif