blob: 7128523a13b160cf4a4a46537953e4c8d12e411d [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 *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000679sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000680{
681 struct tm *tmp;
682 static char buf[32];
683
684 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000685 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000686 return buf;
687 }
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000688 if ((tmp = localtime(&t)))
689 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
690 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
691 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
692 else
693 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
694
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000695 return buf;
696}
697
698#ifdef LINUXSPARC
699typedef struct {
700 int tv_sec;
701 int tv_nsec;
702} timestruct_t;
703
704struct solstat {
705 unsigned st_dev;
706 int st_pad1[3]; /* network id */
707 unsigned st_ino;
708 unsigned st_mode;
709 unsigned st_nlink;
710 unsigned st_uid;
711 unsigned st_gid;
712 unsigned st_rdev;
713 int st_pad2[2];
714 int st_size;
715 int st_pad3; /* st_size, off_t expansion */
716 timestruct_t st_atime;
717 timestruct_t st_mtime;
718 timestruct_t st_ctime;
719 int st_blksize;
720 int st_blocks;
721 char st_fstype[16];
722 int st_pad4[8]; /* expansion area */
723};
724
725static void
726printstatsol(tcp, addr)
727struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000728long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000729{
730 struct solstat statbuf;
731
732 if (!addr) {
733 tprintf("NULL");
734 return;
735 }
736 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000737 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000738 return;
739 }
740 if (umove(tcp, addr, &statbuf) < 0) {
741 tprintf("{...}");
742 return;
743 }
744 if (!abbrev(tcp)) {
745 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
746 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
747 (unsigned long) (statbuf.st_dev & 0x3ffff),
748 (unsigned long) statbuf.st_ino,
749 sprintmode(statbuf.st_mode));
750 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
751 (unsigned long) statbuf.st_nlink,
752 (unsigned long) statbuf.st_uid,
753 (unsigned long) statbuf.st_gid);
754 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
755 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
756 }
757 else
758 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
759 switch (statbuf.st_mode & S_IFMT) {
760 case S_IFCHR: case S_IFBLK:
761 tprintf("st_rdev=makedev(%lu, %lu), ",
762 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
763 (unsigned long) (statbuf.st_rdev & 0x3ffff));
764 break;
765 default:
766 tprintf("st_size=%u, ", statbuf.st_size);
767 break;
768 }
769 if (!abbrev(tcp)) {
770 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
771 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
772 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
773 }
774 else
775 tprintf("...}");
776}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000777
778#if defined (SPARC64)
779static void
780printstat_sparc64(tcp, addr)
781struct tcb *tcp;
782long addr;
783{
784 struct stat_sparc64 statbuf;
785
786 if (!addr) {
787 tprintf("NULL");
788 return;
789 }
790 if (syserror(tcp) || !verbose(tcp)) {
791 tprintf("%#lx", addr);
792 return;
793 }
794 if (umove(tcp, addr, &statbuf) < 0) {
795 tprintf("{...}");
796 return;
797 }
798
799 if (!abbrev(tcp)) {
800 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
801 (unsigned long) major(statbuf.st_dev),
802 (unsigned long) minor(statbuf.st_dev),
803 (unsigned long) statbuf.st_ino,
804 sprintmode(statbuf.st_mode));
805 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
806 (unsigned long) statbuf.st_nlink,
807 (unsigned long) statbuf.st_uid,
808 (unsigned long) statbuf.st_gid);
809 tprintf("st_blksize=%lu, ",
810 (unsigned long) statbuf.st_blksize);
811 tprintf("st_blocks=%lu, ",
812 (unsigned long) statbuf.st_blocks);
813 }
814 else
815 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
816 switch (statbuf.st_mode & S_IFMT) {
817 case S_IFCHR: case S_IFBLK:
818 tprintf("st_rdev=makedev(%lu, %lu), ",
819 (unsigned long) major(statbuf.st_rdev),
820 (unsigned long) minor(statbuf.st_rdev));
821 break;
822 default:
823 tprintf("st_size=%lu, ", statbuf.st_size);
824 break;
825 }
826 if (!abbrev(tcp)) {
827 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
828 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
829 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
830 tprintf("}");
831 }
832 else
833 tprintf("...}");
834}
835#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000836#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000837
Roland McGratha4d48532005-06-08 20:45:28 +0000838static const struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000839#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000840 { UF_NODUMP, "UF_NODUMP" },
841 { UF_IMMUTABLE, "UF_IMMUTABLE" },
842 { UF_APPEND, "UF_APPEND" },
843 { UF_OPAQUE, "UF_OPAQUE" },
844 { UF_NOUNLINK, "UF_NOUNLINK" },
845 { SF_ARCHIVED, "SF_ARCHIVED" },
846 { SF_IMMUTABLE, "SF_IMMUTABLE" },
847 { SF_APPEND, "SF_APPEND" },
848 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000849#elif UNIXWARE >= 2
850#ifdef _S_ISMLD
851 { _S_ISMLD, "_S_ISMLD" },
852#endif
853#ifdef _S_ISMOUNTED
854 { _S_ISMOUNTED, "_S_ISMOUNTED" },
855#endif
856#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000857 { 0, NULL },
858};
859
John Hughesc0fc3fd2001-03-08 16:10:40 +0000860#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000861int
862sys_chflags(tcp)
863struct tcb *tcp;
864{
865 if (entering(tcp)) {
866 printpath(tcp, tcp->u_arg[0]);
867 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000868 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000869 }
870 return 0;
871}
872
873int
874sys_fchflags(tcp)
875struct tcb *tcp;
876{
877 if (entering(tcp)) {
878 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000879 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000880 }
881 return 0;
882}
883#endif
884
John Hughes70623be2001-03-08 13:59:00 +0000885#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000886static void
887realprintstat(tcp, statbuf)
888struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000889struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000890{
891 if (!abbrev(tcp)) {
892 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
893 (unsigned long) major(statbuf->st_dev),
894 (unsigned long) minor(statbuf->st_dev),
895 (unsigned long) statbuf->st_ino,
896 sprintmode(statbuf->st_mode));
897 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
898 (unsigned long) statbuf->st_nlink,
899 (unsigned long) statbuf->st_uid,
900 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000901#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000902 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000903#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
904#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000905 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000906#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000907 }
908 else
909 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
910 switch (statbuf->st_mode & S_IFMT) {
911 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000912#ifdef HAVE_STRUCT_STAT_ST_RDEV
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000913 tprintf("st_rdev=makedev(%lu, %lu), ",
914 (unsigned long) major(statbuf->st_rdev),
915 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000916#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000917 tprintf("st_size=makedev(%lu, %lu), ",
918 (unsigned long) major(statbuf->st_size),
919 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000920#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000921 break;
922 default:
923 tprintf("st_size=%lu, ", statbuf->st_size);
924 break;
925 }
926 if (!abbrev(tcp)) {
927 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
928 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000929 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000930#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000931 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000932 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000933#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000934#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000935 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
936#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000937#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000938 tprintf(", st_level=%ld", statbuf->st_level);
939#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000940#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000941 tprintf(", st_fstype=%.*s",
942 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
943#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000944#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000945 tprintf(", st_gen=%u", statbuf->st_gen);
946#endif
947 tprintf("}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000948 }
949 else
950 tprintf("...}");
951}
952
Nate Sammons771a6ff1999-04-05 22:39:31 +0000953
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000954static void
955printstat(tcp, addr)
956struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000957long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000958{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000959 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000960
961#ifdef LINUXSPARC
962 if (current_personality == 1) {
963 printstatsol(tcp, addr);
964 return;
965 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000966#ifdef SPARC64
967 else if (current_personality == 2) {
968 printstat_sparc64(tcp, addr);
969 return;
970 }
971#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000972#endif /* LINUXSPARC */
973
974 if (!addr) {
975 tprintf("NULL");
976 return;
977 }
978 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000979 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000980 return;
981 }
982 if (umove(tcp, addr, &statbuf) < 0) {
983 tprintf("{...}");
984 return;
985 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000986
987 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000988}
John Hughes70623be2001-03-08 13:59:00 +0000989#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000990
Roland McGrathe6d0f712007-08-07 01:22:49 +0000991#if !defined HAVE_STAT64 && defined LINUX && defined X86_64
992/*
993 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
994 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
995 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
996 * __GNUC__ is needed for the required __attribute__ below.
997 */
998struct stat64 {
999 unsigned long long st_dev;
1000 unsigned char __pad0[4];
1001 unsigned int __st_ino;
1002 unsigned int st_mode;
1003 unsigned int st_nlink;
1004 unsigned int st_uid;
1005 unsigned int st_gid;
1006 unsigned long long st_rdev;
1007 unsigned char __pad3[4];
1008 long long st_size;
1009 unsigned int st_blksize;
1010 unsigned long long st_blocks;
1011 unsigned int st_atime;
1012 unsigned int st_atime_nsec;
1013 unsigned int st_mtime;
1014 unsigned int st_mtime_nsec;
1015 unsigned int st_ctime;
1016 unsigned int st_ctime_nsec;
1017 unsigned long long st_ino;
1018} __attribute__((packed));
1019# define HAVE_STAT64 1
1020# define STAT64_SIZE 96
1021#endif
1022
Wichert Akkermanc7926982000-04-10 22:22:31 +00001023#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001024static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001025printstat64(tcp, addr)
1026struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001027long addr;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001028{
1029 struct stat64 statbuf;
1030
Roland McGrathe6d0f712007-08-07 01:22:49 +00001031#ifdef STAT64_SIZE
1032 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1033#endif
1034
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001035#ifdef LINUXSPARC
1036 if (current_personality == 1) {
1037 printstatsol(tcp, addr);
1038 return;
1039 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001040#ifdef SPARC64
1041 else if (current_personality == 2) {
1042 printstat_sparc64(tcp, addr);
1043 return;
1044 }
1045#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001046#endif /* LINUXSPARC */
1047
1048 if (!addr) {
1049 tprintf("NULL");
1050 return;
1051 }
1052 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001053 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001054 return;
1055 }
1056 if (umove(tcp, addr, &statbuf) < 0) {
1057 tprintf("{...}");
1058 return;
1059 }
1060
1061 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001062#ifdef HAVE_LONG_LONG
1063 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1064#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001065 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001066#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001067 (unsigned long) major(statbuf.st_dev),
1068 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001069#ifdef HAVE_LONG_LONG
1070 (unsigned long long) statbuf.st_ino,
1071#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001072 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001073#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001074 sprintmode(statbuf.st_mode));
1075 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1076 (unsigned long) statbuf.st_nlink,
1077 (unsigned long) statbuf.st_uid,
1078 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001079#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001080 tprintf("st_blksize=%lu, ",
1081 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001082#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1083#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001084 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001085#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001086 }
1087 else
1088 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1089 switch (statbuf.st_mode & S_IFMT) {
1090 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001091#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001092 tprintf("st_rdev=makedev(%lu, %lu), ",
1093 (unsigned long) major(statbuf.st_rdev),
1094 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001095#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001096 tprintf("st_size=makedev(%lu, %lu), ",
1097 (unsigned long) major(statbuf.st_size),
1098 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001099#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001100 break;
1101 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001102#ifdef HAVE_LONG_LONG
1103 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1104#else
1105 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1106#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001107 break;
1108 }
1109 if (!abbrev(tcp)) {
1110 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1111 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001112 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001113#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +00001114 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001115 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001116#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001117#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001118 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1119#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001120#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001121 tprintf(", st_level=%ld", statbuf.st_level);
1122#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001123#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001124 tprintf(", st_fstype=%.*s",
1125 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1126#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001127#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001128 tprintf(", st_gen=%u", statbuf.st_gen);
1129#endif
1130 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001131 }
1132 else
1133 tprintf("...}");
1134}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001135#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001136
Roland McGrath79db8af2003-06-27 21:20:09 +00001137#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001138static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001139convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001140const struct __old_kernel_stat *oldbuf;
1141struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001142{
1143 newbuf->st_dev=oldbuf->st_dev;
1144 newbuf->st_ino=oldbuf->st_ino;
1145 newbuf->st_mode=oldbuf->st_mode;
1146 newbuf->st_nlink=oldbuf->st_nlink;
1147 newbuf->st_uid=oldbuf->st_uid;
1148 newbuf->st_gid=oldbuf->st_gid;
1149 newbuf->st_rdev=oldbuf->st_rdev;
1150 newbuf->st_size=oldbuf->st_size;
1151 newbuf->st_atime=oldbuf->st_atime;
1152 newbuf->st_mtime=oldbuf->st_mtime;
1153 newbuf->st_ctime=oldbuf->st_ctime;
1154 newbuf->st_blksize=0; /* not supported in old_stat */
1155 newbuf->st_blocks=0; /* not supported in old_stat */
1156}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001157
1158
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001159static void
1160printoldstat(tcp, addr)
1161struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001162long addr;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001163{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001164 struct __old_kernel_stat statbuf;
1165 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001166
1167#ifdef LINUXSPARC
1168 if (current_personality == 1) {
1169 printstatsol(tcp, addr);
1170 return;
1171 }
1172#endif /* LINUXSPARC */
1173
1174 if (!addr) {
1175 tprintf("NULL");
1176 return;
1177 }
1178 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001179 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001180 return;
1181 }
1182 if (umove(tcp, addr, &statbuf) < 0) {
1183 tprintf("{...}");
1184 return;
1185 }
1186
1187 convertoldstat(&statbuf, &newstatbuf);
1188 realprintstat(tcp, &newstatbuf);
1189}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001190#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001191
John Hughes70623be2001-03-08 13:59:00 +00001192#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001193int
1194sys_stat(tcp)
1195struct tcb *tcp;
1196{
1197 if (entering(tcp)) {
1198 printpath(tcp, tcp->u_arg[0]);
1199 tprintf(", ");
1200 } else {
1201 printstat(tcp, tcp->u_arg[1]);
1202 }
1203 return 0;
1204}
John Hughesb8c9f772001-03-07 16:53:07 +00001205#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001206
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001207int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001208sys_stat64(tcp)
1209struct tcb *tcp;
1210{
1211#ifdef HAVE_STAT64
1212 if (entering(tcp)) {
1213 printpath(tcp, tcp->u_arg[0]);
1214 tprintf(", ");
1215 } else {
1216 printstat64(tcp, tcp->u_arg[1]);
1217 }
1218 return 0;
1219#else
1220 return printargs(tcp);
1221#endif
1222}
1223
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001224#ifdef LINUX
1225static const struct xlat fstatatflags[] = {
1226#ifndef AT_SYMLINK_NOFOLLOW
1227# define AT_SYMLINK_NOFOLLOW 0x100
1228#endif
1229 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1230 { 0, NULL },
1231};
Roland McGrath6afc5652007-07-24 01:57:11 +00001232#define utimensatflags fstatatflags
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001233
1234int
1235sys_newfstatat(struct tcb *tcp)
1236{
1237 if (entering(tcp)) {
1238 print_dirfd(tcp->u_arg[0]);
1239 printpath(tcp, tcp->u_arg[1]);
1240 tprintf(", ");
1241 } else {
Roland McGrath359c8ed2007-07-05 19:01:17 +00001242#if defined HAVE_STAT64 && !(defined POWERPC && defined __powerpc64__)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001243 printstat64(tcp, tcp->u_arg[2]);
1244#else
1245 printstat(tcp, tcp->u_arg[2]);
1246#endif
1247 tprintf(", ");
1248 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1249 }
1250 return 0;
1251}
1252#endif
1253
Roland McGrath79db8af2003-06-27 21:20:09 +00001254#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001255int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001256sys_oldstat(tcp)
1257struct tcb *tcp;
1258{
1259 if (entering(tcp)) {
1260 printpath(tcp, tcp->u_arg[0]);
1261 tprintf(", ");
1262 } else {
1263 printoldstat(tcp, tcp->u_arg[1]);
1264 }
1265 return 0;
1266}
Roland McGrath79db8af2003-06-27 21:20:09 +00001267#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001268
John Hughes70623be2001-03-08 13:59:00 +00001269#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001270int
1271sys_fstat(tcp)
1272struct tcb *tcp;
1273{
1274 if (entering(tcp))
1275 tprintf("%ld, ", tcp->u_arg[0]);
1276 else {
1277 printstat(tcp, tcp->u_arg[1]);
1278 }
1279 return 0;
1280}
John Hughesb8c9f772001-03-07 16:53:07 +00001281#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001282
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001283int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001284sys_fstat64(tcp)
1285struct tcb *tcp;
1286{
1287#ifdef HAVE_STAT64
1288 if (entering(tcp))
1289 tprintf("%ld, ", tcp->u_arg[0]);
1290 else {
1291 printstat64(tcp, tcp->u_arg[1]);
1292 }
1293 return 0;
1294#else
1295 return printargs(tcp);
1296#endif
1297}
1298
Roland McGrath79db8af2003-06-27 21:20:09 +00001299#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001300int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001301sys_oldfstat(tcp)
1302struct tcb *tcp;
1303{
1304 if (entering(tcp))
1305 tprintf("%ld, ", tcp->u_arg[0]);
1306 else {
1307 printoldstat(tcp, tcp->u_arg[1]);
1308 }
1309 return 0;
1310}
Roland McGrath79db8af2003-06-27 21:20:09 +00001311#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001312
John Hughes70623be2001-03-08 13:59:00 +00001313#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001314int
1315sys_lstat(tcp)
1316struct tcb *tcp;
1317{
1318 if (entering(tcp)) {
1319 printpath(tcp, tcp->u_arg[0]);
1320 tprintf(", ");
1321 } else {
1322 printstat(tcp, tcp->u_arg[1]);
1323 }
1324 return 0;
1325}
John Hughesb8c9f772001-03-07 16:53:07 +00001326#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001327
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001328int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001329sys_lstat64(tcp)
1330struct tcb *tcp;
1331{
1332#ifdef HAVE_STAT64
1333 if (entering(tcp)) {
1334 printpath(tcp, tcp->u_arg[0]);
1335 tprintf(", ");
1336 } else {
1337 printstat64(tcp, tcp->u_arg[1]);
1338 }
1339 return 0;
1340#else
1341 return printargs(tcp);
1342#endif
1343}
1344
Roland McGrath79db8af2003-06-27 21:20:09 +00001345#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001346int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001347sys_oldlstat(tcp)
1348struct tcb *tcp;
1349{
1350 if (entering(tcp)) {
1351 printpath(tcp, tcp->u_arg[0]);
1352 tprintf(", ");
1353 } else {
1354 printoldstat(tcp, tcp->u_arg[1]);
1355 }
1356 return 0;
1357}
Roland McGrath79db8af2003-06-27 21:20:09 +00001358#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001359
1360
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001361#if defined(SVR4) || defined(LINUXSPARC)
1362
1363int
1364sys_xstat(tcp)
1365struct tcb *tcp;
1366{
1367 if (entering(tcp)) {
1368 tprintf("%ld, ", tcp->u_arg[0]);
1369 printpath(tcp, tcp->u_arg[1]);
1370 tprintf(", ");
1371 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001372#ifdef _STAT64_VER
1373 if (tcp->u_arg[0] == _STAT64_VER)
1374 printstat64 (tcp, tcp->u_arg[2]);
1375 else
1376#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001377 printstat(tcp, tcp->u_arg[2]);
1378 }
1379 return 0;
1380}
1381
1382int
1383sys_fxstat(tcp)
1384struct tcb *tcp;
1385{
1386 if (entering(tcp))
1387 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1388 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001389#ifdef _STAT64_VER
1390 if (tcp->u_arg[0] == _STAT64_VER)
1391 printstat64 (tcp, tcp->u_arg[2]);
1392 else
1393#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001394 printstat(tcp, tcp->u_arg[2]);
1395 }
1396 return 0;
1397}
1398
1399int
1400sys_lxstat(tcp)
1401struct tcb *tcp;
1402{
1403 if (entering(tcp)) {
1404 tprintf("%ld, ", tcp->u_arg[0]);
1405 printpath(tcp, tcp->u_arg[1]);
1406 tprintf(", ");
1407 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001408#ifdef _STAT64_VER
1409 if (tcp->u_arg[0] == _STAT64_VER)
1410 printstat64 (tcp, tcp->u_arg[2]);
1411 else
1412#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413 printstat(tcp, tcp->u_arg[2]);
1414 }
1415 return 0;
1416}
1417
1418int
1419sys_xmknod(tcp)
1420struct tcb *tcp;
1421{
1422 int mode = tcp->u_arg[2];
1423
1424 if (entering(tcp)) {
1425 tprintf("%ld, ", tcp->u_arg[0]);
1426 printpath(tcp, tcp->u_arg[1]);
1427 tprintf(", %s", sprintmode(mode));
1428 switch (mode & S_IFMT) {
1429 case S_IFCHR: case S_IFBLK:
1430#ifdef LINUXSPARC
1431 tprintf(", makedev(%lu, %lu)",
1432 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1433 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001434#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001435 tprintf(", makedev(%lu, %lu)",
1436 (unsigned long) major(tcp->u_arg[3]),
1437 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001438#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001439 break;
1440 default:
1441 break;
1442 }
1443 }
1444 return 0;
1445}
1446
Wichert Akkerman8829a551999-06-11 13:18:40 +00001447#ifdef HAVE_SYS_ACL_H
1448
1449#include <sys/acl.h>
1450
Roland McGratha4d48532005-06-08 20:45:28 +00001451static const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001452#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001453 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001454#endif
1455#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001456 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001457#endif
1458#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001459 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001460#endif
1461#ifdef ACL_GET
1462 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001463#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001464#ifdef ACL_SET
1465 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001466#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001467#ifdef ACL_CNT
1468 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001469#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001470 { 0, NULL },
1471};
1472
1473int
1474sys_acl(tcp)
1475struct tcb *tcp;
1476{
1477 if (entering(tcp)) {
1478 printpath(tcp, tcp->u_arg[0]);
1479 tprintf(", ");
1480 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1481 tprintf(", %ld", tcp->u_arg[2]);
1482 /*
1483 * FIXME - dump out the list of aclent_t's pointed to
1484 * by "tcp->u_arg[3]" if it's not NULL.
1485 */
1486 if (tcp->u_arg[3])
1487 tprintf(", %#lx", tcp->u_arg[3]);
1488 else
1489 tprintf(", NULL");
1490 }
1491 return 0;
1492}
1493
1494
1495int
1496sys_facl(tcp)
1497struct tcb *tcp;
1498{
1499 if (entering(tcp)) {
1500 tprintf("%ld, ", tcp->u_arg[0]);
1501 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1502 tprintf(", %ld", tcp->u_arg[2]);
1503 /*
1504 * FIXME - dump out the list of aclent_t's pointed to
1505 * by "tcp->u_arg[3]" if it's not NULL.
1506 */
1507 if (tcp->u_arg[3])
1508 tprintf(", %#lx", tcp->u_arg[3]);
1509 else
1510 tprintf(", NULL");
1511 }
1512 return 0;
1513}
1514
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001515
Roland McGratha4d48532005-06-08 20:45:28 +00001516static const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001517#ifdef IPC_SHM
1518 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001519#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001520#ifdef IPC_SEM
1521 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001522#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001523#ifdef IPC_MSG
1524 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001525#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001526 { 0, NULL },
1527};
1528
1529
1530int
1531sys_aclipc(tcp)
1532struct tcb *tcp;
1533{
1534 if (entering(tcp)) {
1535 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1536 tprintf(", %#lx, ", tcp->u_arg[1]);
1537 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1538 tprintf(", %ld", tcp->u_arg[3]);
1539 /*
1540 * FIXME - dump out the list of aclent_t's pointed to
1541 * by "tcp->u_arg[4]" if it's not NULL.
1542 */
1543 if (tcp->u_arg[4])
1544 tprintf(", %#lx", tcp->u_arg[4]);
1545 else
1546 tprintf(", NULL");
1547 }
1548 return 0;
1549}
1550
1551
1552
Wichert Akkerman8829a551999-06-11 13:18:40 +00001553#endif /* HAVE_SYS_ACL_H */
1554
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001555#endif /* SVR4 || LINUXSPARC */
1556
Michal Ludvig53b320f2002-09-23 13:30:09 +00001557#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001558
Roland McGrathd9f816f2004-09-04 03:39:20 +00001559static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001560 { 0x73757245, "CODA_SUPER_MAGIC" },
1561 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1562 { 0x1373, "DEVFS_SUPER_MAGIC" },
1563 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1564 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001565 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1566 { 0xef53, "EXT2_SUPER_MAGIC" },
1567 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001568 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001569 { 0x9660, "ISOFS_SUPER_MAGIC" },
1570 { 0x137f, "MINIX_SUPER_MAGIC" },
1571 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001572 { 0x2468, "MINIX2_SUPER_MAGIC" },
1573 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001574 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001575 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001576 { 0x6969, "NFS_SUPER_MAGIC" },
1577 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001578 { 0x002f, "QNX4_SUPER_MAGIC" },
1579 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1580 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1581 { 0x517b, "SMB_SUPER_MAGIC" },
1582 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1583 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1584 { 0x00011954, "UFS_MAGIC" },
1585 { 0x54190100, "UFS_CIGAM" },
1586 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001587 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001588 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001589 { 0, NULL },
1590};
1591
Michal Ludvig53b320f2002-09-23 13:30:09 +00001592#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001593
1594#ifndef SVR4
1595
Roland McGrathf9c49b22004-10-06 22:11:54 +00001596static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001597sprintfstype(magic)
1598int magic;
1599{
1600 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001601#ifdef LINUX
Roland McGrathf9c49b22004-10-06 22:11:54 +00001602 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001603
1604 s = xlookup(fsmagic, magic);
1605 if (s) {
1606 sprintf(buf, "\"%s\"", s);
1607 return buf;
1608 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001609#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001610 sprintf(buf, "%#x", magic);
1611 return buf;
1612}
1613
1614static void
1615printstatfs(tcp, addr)
1616struct tcb *tcp;
1617long addr;
1618{
1619 struct statfs statbuf;
1620
1621 if (syserror(tcp) || !verbose(tcp)) {
1622 tprintf("%#lx", addr);
1623 return;
1624 }
1625 if (umove(tcp, addr, &statbuf) < 0) {
1626 tprintf("{...}");
1627 return;
1628 }
1629#ifdef ALPHA
1630
1631 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1632 sprintfstype(statbuf.f_type),
1633 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001634 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1635 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1636 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1637 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001638#else /* !ALPHA */
1639 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1640 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001641 (unsigned long)statbuf.f_bsize,
1642 (unsigned long)statbuf.f_blocks,
1643 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001644 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1645 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001646 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001647 (unsigned long)statbuf.f_ffree,
1648 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001649#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001650 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001651#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001652#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001653#ifdef _STATFS_F_FRSIZE
1654 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1655#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001656 tprintf("}");
1657}
1658
1659int
1660sys_statfs(tcp)
1661struct tcb *tcp;
1662{
1663 if (entering(tcp)) {
1664 printpath(tcp, tcp->u_arg[0]);
1665 tprintf(", ");
1666 } else {
1667 printstatfs(tcp, tcp->u_arg[1]);
1668 }
1669 return 0;
1670}
1671
1672int
1673sys_fstatfs(tcp)
1674struct tcb *tcp;
1675{
1676 if (entering(tcp)) {
1677 tprintf("%lu, ", tcp->u_arg[0]);
1678 } else {
1679 printstatfs(tcp, tcp->u_arg[1]);
1680 }
1681 return 0;
1682}
1683
Roland McGrathab147c52003-07-17 09:03:02 +00001684#ifdef LINUX
1685static void
1686printstatfs64(tcp, addr)
1687struct tcb *tcp;
1688long addr;
1689{
1690 struct statfs64 statbuf;
1691
1692 if (syserror(tcp) || !verbose(tcp)) {
1693 tprintf("%#lx", addr);
1694 return;
1695 }
1696 if (umove(tcp, addr, &statbuf) < 0) {
1697 tprintf("{...}");
1698 return;
1699 }
Roland McGrath08738432005-06-03 02:40:39 +00001700 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001701 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001702 (unsigned long long)statbuf.f_bsize,
1703 (unsigned long long)statbuf.f_blocks,
1704 (unsigned long long)statbuf.f_bfree);
1705 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1706 (unsigned long long)statbuf.f_bavail,
1707 (unsigned long long)statbuf.f_files,
1708 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001709 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1710 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001711#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001712 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001713#endif
1714 tprintf("}");
1715}
1716
1717int
1718sys_statfs64(tcp)
1719struct tcb *tcp;
1720{
1721 if (entering(tcp)) {
1722 printpath(tcp, tcp->u_arg[0]);
1723 tprintf(", %lu, ", tcp->u_arg[1]);
1724 } else {
1725 if (tcp->u_arg[1] == sizeof (struct statfs64))
1726 printstatfs64(tcp, tcp->u_arg[2]);
1727 else
1728 tprintf("{???}");
1729 }
1730 return 0;
1731}
1732
1733int
1734sys_fstatfs64(tcp)
1735struct tcb *tcp;
1736{
1737 if (entering(tcp)) {
1738 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1739 } else {
1740 if (tcp->u_arg[1] == sizeof (struct statfs64))
1741 printstatfs64(tcp, tcp->u_arg[2]);
1742 else
1743 tprintf("{???}");
1744 }
1745 return 0;
1746}
1747#endif
1748
Michal Ludvig53b320f2002-09-23 13:30:09 +00001749#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001750
1751int
1752osf_statfs(tcp)
1753struct tcb *tcp;
1754{
1755 if (entering(tcp)) {
1756 printpath(tcp, tcp->u_arg[0]);
1757 tprintf(", ");
1758 } else {
1759 printstatfs(tcp, tcp->u_arg[1]);
1760 tprintf(", %lu", tcp->u_arg[2]);
1761 }
1762 return 0;
1763}
1764
1765int
1766osf_fstatfs(tcp)
1767struct tcb *tcp;
1768{
1769 if (entering(tcp)) {
1770 tprintf("%lu, ", tcp->u_arg[0]);
1771 } else {
1772 printstatfs(tcp, tcp->u_arg[1]);
1773 tprintf(", %lu", tcp->u_arg[2]);
1774 }
1775 return 0;
1776}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001777#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001778
1779#endif /* !SVR4 */
1780
1781#ifdef SUNOS4
1782
1783int
1784sys_ustat(tcp)
1785struct tcb *tcp;
1786{
1787 struct ustat statbuf;
1788
1789 if (entering(tcp)) {
1790 tprintf("makedev(%lu, %lu), ",
1791 (long) major(tcp->u_arg[0]),
1792 (long) minor(tcp->u_arg[0]));
1793 }
1794 else {
1795 if (syserror(tcp) || !verbose(tcp))
1796 tprintf("%#lx", tcp->u_arg[1]);
1797 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1798 tprintf("{...}");
1799 else {
1800 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1801 statbuf.f_tfree, statbuf.f_tinode);
1802 tprintf("f_fname=\"%.*s\", ",
1803 (int) sizeof(statbuf.f_fname),
1804 statbuf.f_fname);
1805 tprintf("f_fpack=\"%.*s\"}",
1806 (int) sizeof(statbuf.f_fpack),
1807 statbuf.f_fpack);
1808 }
1809 }
1810 return 0;
1811}
1812
1813#endif /* SUNOS4 */
1814
Wichert Akkermanc7926982000-04-10 22:22:31 +00001815int
1816sys_pivotroot(tcp)
1817struct tcb *tcp;
1818{
1819 if (entering(tcp)) {
1820 printpath(tcp, tcp->u_arg[0]);
1821 tprintf(", ");
1822 printpath(tcp, tcp->u_arg[1]);
1823 }
1824 return 0;
1825}
1826
1827
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001828/* directory */
1829int
1830sys_chdir(tcp)
1831struct tcb *tcp;
1832{
1833 if (entering(tcp)) {
1834 printpath(tcp, tcp->u_arg[0]);
1835 }
1836 return 0;
1837}
1838
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001839static int
1840decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001841{
1842 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001843 printpath(tcp, tcp->u_arg[offset]);
1844 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001845 }
1846 return 0;
1847}
1848
1849int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001850sys_mkdir(struct tcb *tcp)
1851{
1852 return decode_mkdir(tcp, 0);
1853}
1854
1855#ifdef LINUX
1856int
1857sys_mkdirat(struct tcb *tcp)
1858{
1859 if (entering(tcp))
1860 print_dirfd(tcp->u_arg[0]);
1861 return decode_mkdir(tcp, 1);
1862}
1863#endif
1864
1865int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001866sys_rmdir(tcp)
1867struct tcb *tcp;
1868{
1869 if (entering(tcp)) {
1870 printpath(tcp, tcp->u_arg[0]);
1871 }
1872 return 0;
1873}
1874
1875int
1876sys_fchdir(tcp)
1877struct tcb *tcp;
1878{
1879 if (entering(tcp)) {
1880 tprintf("%ld", tcp->u_arg[0]);
1881 }
1882 return 0;
1883}
1884
1885int
1886sys_chroot(tcp)
1887struct tcb *tcp;
1888{
1889 if (entering(tcp)) {
1890 printpath(tcp, tcp->u_arg[0]);
1891 }
1892 return 0;
1893}
1894
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001895#if defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001896int
1897sys_fchroot(tcp)
1898struct tcb *tcp;
1899{
1900 if (entering(tcp)) {
1901 tprintf("%ld", tcp->u_arg[0]);
1902 }
1903 return 0;
1904}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001905#endif /* SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001906
1907int
1908sys_link(tcp)
1909struct tcb *tcp;
1910{
1911 if (entering(tcp)) {
1912 printpath(tcp, tcp->u_arg[0]);
1913 tprintf(", ");
1914 printpath(tcp, tcp->u_arg[1]);
1915 }
1916 return 0;
1917}
1918
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001919#ifdef LINUX
1920int
1921sys_linkat(struct tcb *tcp)
1922{
1923 if (entering(tcp)) {
1924 print_dirfd(tcp->u_arg[0]);
1925 printpath(tcp, tcp->u_arg[1]);
1926 tprintf(", ");
1927 print_dirfd(tcp->u_arg[2]);
1928 printpath(tcp, tcp->u_arg[3]);
1929 tprintf(", %ld", tcp->u_arg[4]);
1930 }
1931 return 0;
1932}
1933#endif
1934
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001935int
1936sys_unlink(tcp)
1937struct tcb *tcp;
1938{
1939 if (entering(tcp)) {
1940 printpath(tcp, tcp->u_arg[0]);
1941 }
1942 return 0;
1943}
1944
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001945#ifdef LINUX
1946static const struct xlat unlinkatflags[] = {
1947#ifndef AT_REMOVEDIR
1948# define AT_REMOVEDIR 0x200
1949#endif
1950 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1951 { 0, NULL },
1952};
1953
1954int
1955sys_unlinkat(struct tcb *tcp)
1956{
1957 if (entering(tcp)) {
1958 print_dirfd(tcp->u_arg[0]);
1959 printpath(tcp, tcp->u_arg[1]);
1960 tprintf(", ");
1961 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1962 }
1963 return 0;
1964}
1965#endif
1966
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001967int
1968sys_symlink(tcp)
1969struct tcb *tcp;
1970{
1971 if (entering(tcp)) {
1972 printpath(tcp, tcp->u_arg[0]);
1973 tprintf(", ");
1974 printpath(tcp, tcp->u_arg[1]);
1975 }
1976 return 0;
1977}
1978
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001979#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001980int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001981sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001982{
1983 if (entering(tcp)) {
1984 printpath(tcp, tcp->u_arg[0]);
1985 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001986 print_dirfd(tcp->u_arg[1]);
1987 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001988 }
1989 return 0;
1990}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001991#endif
1992
1993static int
1994decode_readlink(struct tcb *tcp, int offset)
1995{
1996 if (entering(tcp)) {
1997 printpath(tcp, tcp->u_arg[offset]);
1998 tprintf(", ");
1999 } else {
2000 if (syserror(tcp))
2001 tprintf("%#lx", tcp->u_arg[offset + 1]);
2002 else
2003 printpathn(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
2004 tprintf(", %lu", tcp->u_arg[offset + 2]);
2005 }
2006 return 0;
2007}
2008
2009int
2010sys_readlink(struct tcb *tcp)
2011{
2012 return decode_readlink(tcp, 0);
2013}
2014
2015#ifdef LINUX
2016int
2017sys_readlinkat(struct tcb *tcp)
2018{
2019 if (entering(tcp))
2020 print_dirfd(tcp->u_arg[0]);
2021 return decode_readlink(tcp, 1);
2022}
2023#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002024
2025int
2026sys_rename(tcp)
2027struct tcb *tcp;
2028{
2029 if (entering(tcp)) {
2030 printpath(tcp, tcp->u_arg[0]);
2031 tprintf(", ");
2032 printpath(tcp, tcp->u_arg[1]);
2033 }
2034 return 0;
2035}
2036
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002037#ifdef LINUX
2038int
2039sys_renameat(struct tcb *tcp)
2040{
2041 if (entering(tcp)) {
2042 print_dirfd(tcp->u_arg[0]);
2043 printpath(tcp, tcp->u_arg[1]);
2044 tprintf(", ");
2045 print_dirfd(tcp->u_arg[2]);
2046 printpath(tcp, tcp->u_arg[3]);
2047 }
2048 return 0;
2049}
2050#endif
2051
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002052int
2053sys_chown(tcp)
2054struct tcb *tcp;
2055{
2056 if (entering(tcp)) {
2057 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002058 printuid(", ", tcp->u_arg[1]);
2059 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002060 }
2061 return 0;
2062}
2063
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002064#ifdef LINUX
2065int
2066sys_fchownat(struct tcb *tcp)
2067{
2068 if (entering(tcp)) {
2069 print_dirfd(tcp->u_arg[0]);
2070 printpath(tcp, tcp->u_arg[1]);
2071 printuid(", ", tcp->u_arg[2]);
2072 printuid(", ", tcp->u_arg[3]);
2073 tprintf(", ");
2074 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
2075 }
2076 return 0;
2077}
2078#endif
2079
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002080int
2081sys_fchown(tcp)
2082struct tcb *tcp;
2083{
2084 if (entering(tcp)) {
Roland McGrath6bc12202003-11-13 22:32:27 +00002085 tprintf("%ld", tcp->u_arg[0]);
2086 printuid(", ", tcp->u_arg[1]);
2087 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002088 }
2089 return 0;
2090}
2091
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002092static int
2093decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002094{
2095 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002096 printpath(tcp, tcp->u_arg[offset]);
2097 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002098 }
2099 return 0;
2100}
2101
2102int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002103sys_chmod(struct tcb *tcp)
2104{
2105 return decode_chmod(tcp, 0);
2106}
2107
2108#ifdef LINUX
2109int
2110sys_fchmodat(struct tcb *tcp)
2111{
2112 if (entering(tcp))
2113 print_dirfd(tcp->u_arg[0]);
2114 return decode_chmod(tcp, 1);
2115}
2116#endif
2117
2118int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002119sys_fchmod(tcp)
2120struct tcb *tcp;
2121{
2122 if (entering(tcp)) {
2123 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
2124 }
2125 return 0;
2126}
2127
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002128#ifdef ALPHA
2129int
2130sys_osf_utimes(tcp)
2131struct tcb *tcp;
2132{
2133 if (entering(tcp)) {
2134 printpath(tcp, tcp->u_arg[0]);
2135 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002136 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002137 }
2138 return 0;
2139}
2140#endif
2141
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002142static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002143decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002144{
2145 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002146 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002147 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002148 if (tcp->u_arg[offset + 1] == 0)
2149 tprintf("NULL");
2150 else {
2151 tprintf("{");
2152 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2153 BITNESS_CURRENT, special);
2154 tprintf(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002155 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Roland McGrath6afc5652007-07-24 01:57:11 +00002156 + sizeof (struct timeval),
2157 BITNESS_CURRENT, special);
2158 tprintf("}");
2159 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002160 }
2161 return 0;
2162}
2163
2164int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002165sys_utimes(struct tcb *tcp)
2166{
Roland McGrath6afc5652007-07-24 01:57:11 +00002167 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002168}
2169
2170#ifdef LINUX
2171int
2172sys_futimesat(struct tcb *tcp)
2173{
2174 if (entering(tcp))
2175 print_dirfd(tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002176 return decode_utimes(tcp, 1, 0);
2177}
2178
2179int
2180sys_utimensat(struct tcb *tcp)
2181{
2182 if (entering(tcp)) {
2183 print_dirfd(tcp->u_arg[0]);
2184 decode_utimes(tcp, 1, 1);
2185 tprintf(", ");
2186 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2187 }
2188 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002189}
2190#endif
2191
2192int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002193sys_utime(tcp)
2194struct tcb *tcp;
2195{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002196 union {
2197 long utl[2];
2198 int uti[2];
2199 } u;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002200
2201 if (entering(tcp)) {
2202 printpath(tcp, tcp->u_arg[0]);
2203 tprintf(", ");
2204 if (!tcp->u_arg[1])
2205 tprintf("NULL");
2206 else if (!verbose(tcp))
2207 tprintf("%#lx", tcp->u_arg[1]);
Roland McGrath7e9817c2007-07-05 20:31:58 +00002208 else if (umoven(tcp, tcp->u_arg[1],
2209 2 * personality_wordsize[current_personality],
2210 (char *) &u) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002211 tprintf("[?, ?]");
Roland McGrath7e9817c2007-07-05 20:31:58 +00002212 else if (personality_wordsize[current_personality]
2213 == sizeof u.utl[0]) {
2214 tprintf("[%s,", sprinttime(u.utl[0]));
2215 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002216 }
Roland McGrath7e9817c2007-07-05 20:31:58 +00002217 else if (personality_wordsize[current_personality]
2218 == sizeof u.uti[0]) {
2219 tprintf("[%s,", sprinttime(u.uti[0]));
2220 tprintf(" %s]", sprinttime(u.uti[1]));
2221 }
2222 else
2223 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002224 }
2225 return 0;
2226}
2227
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002228static int
2229decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002230{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002231 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002232
2233 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002234 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002235 tprintf(", %s", sprintmode(mode));
2236 switch (mode & S_IFMT) {
2237 case S_IFCHR: case S_IFBLK:
2238#ifdef LINUXSPARC
2239 if (current_personality == 1)
2240 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002241 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2242 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002243 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002244#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002245 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002246 (unsigned long) major(tcp->u_arg[offset + 2]),
2247 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002248 break;
2249 default:
2250 break;
2251 }
2252 }
2253 return 0;
2254}
2255
2256int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002257sys_mknod(struct tcb *tcp)
2258{
2259 return decode_mknod(tcp, 0);
2260}
2261
2262#ifdef LINUX
2263int
2264sys_mknodat(struct tcb *tcp)
2265{
2266 if (entering(tcp))
2267 print_dirfd(tcp->u_arg[0]);
2268 return decode_mknod(tcp, 1);
2269}
2270#endif
2271
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002272#ifdef FREEBSD
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002273int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002274sys_mkfifo(tcp)
2275struct tcb *tcp;
2276{
2277 if (entering(tcp)) {
2278 printpath(tcp, tcp->u_arg[0]);
2279 tprintf(", %#lo", tcp->u_arg[1]);
2280 }
2281 return 0;
2282}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002283#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002284
2285int
2286sys_fsync(tcp)
2287struct tcb *tcp;
2288{
2289 if (entering(tcp)) {
2290 tprintf("%ld", tcp->u_arg[0]);
2291 }
2292 return 0;
2293}
2294
Michal Ludvig53b320f2002-09-23 13:30:09 +00002295#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002296
2297static void
2298printdir(tcp, addr)
2299struct tcb *tcp;
2300long addr;
2301{
2302 struct dirent d;
2303
2304 if (!verbose(tcp)) {
2305 tprintf("%#lx", addr);
2306 return;
2307 }
2308 if (umove(tcp, addr, &d) < 0) {
2309 tprintf("{...}");
2310 return;
2311 }
2312 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002313 tprintf("d_name=");
2314 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2315 tprintf("}");
2316}
2317
2318int
2319sys_readdir(tcp)
2320struct tcb *tcp;
2321{
2322 if (entering(tcp)) {
2323 tprintf("%lu, ", tcp->u_arg[0]);
2324 } else {
2325 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2326 tprintf("%#lx", tcp->u_arg[1]);
2327 else
2328 printdir(tcp, tcp->u_arg[1]);
2329 /* Not much point in printing this out, it is always 1. */
2330 if (tcp->u_arg[2] != 1)
2331 tprintf(", %lu", tcp->u_arg[2]);
2332 }
2333 return 0;
2334}
2335
Michal Ludvig53b320f2002-09-23 13:30:09 +00002336#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002337
Roland McGrath40542842004-01-13 09:47:49 +00002338#if defined FREEBSD || defined LINUX
Roland McGratha4d48532005-06-08 20:45:28 +00002339static const struct xlat direnttypes[] = {
Roland McGrath40542842004-01-13 09:47:49 +00002340 { DT_UNKNOWN, "DT_UNKNOWN" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002341 { DT_FIFO, "DT_FIFO" },
2342 { DT_CHR, "DT_CHR" },
2343 { DT_DIR, "DT_DIR" },
2344 { DT_BLK, "DT_BLK" },
2345 { DT_REG, "DT_REG" },
2346 { DT_LNK, "DT_LNK" },
2347 { DT_SOCK, "DT_SOCK" },
2348 { DT_WHT, "DT_WHT" },
2349 { 0, NULL },
2350};
2351
2352#endif
2353
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002354int
2355sys_getdents(tcp)
2356struct tcb *tcp;
2357{
2358 int i, len, dents = 0;
2359 char *buf;
2360
2361 if (entering(tcp)) {
2362 tprintf("%lu, ", tcp->u_arg[0]);
2363 return 0;
2364 }
2365 if (syserror(tcp) || !verbose(tcp)) {
2366 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2367 return 0;
2368 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002369 len = tcp->u_rval;
2370 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002371 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2372 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002373 return 0;
2374 }
2375 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002376 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002377 free(buf);
2378 return 0;
2379 }
2380 if (!abbrev(tcp))
2381 tprintf("{");
2382 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002383 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002384#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002385 if (!abbrev(tcp)) {
2386 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2387 i ? " " : "", d->d_ino, d->d_off);
2388 tprintf("d_reclen=%u, d_name=\"%s\"}",
2389 d->d_reclen, d->d_name);
2390 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002391#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002392#ifdef SVR4
2393 if (!abbrev(tcp)) {
2394 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002395 i ? " " : "",
2396 (unsigned long) d->d_ino,
2397 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002398 tprintf("d_reclen=%u, d_name=\"%s\"}",
2399 d->d_reclen, d->d_name);
2400 }
2401#endif /* SVR4 */
2402#ifdef SUNOS4
2403 if (!abbrev(tcp)) {
2404 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2405 i ? " " : "", d->d_off, d->d_fileno,
2406 d->d_reclen);
2407 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2408 d->d_namlen, d->d_namlen, d->d_name);
2409 }
2410#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002411#ifdef FREEBSD
2412 if (!abbrev(tcp)) {
2413 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2414 i ? " " : "", d->d_fileno, d->d_reclen);
2415 printxval(direnttypes, d->d_type, "DT_???");
2416 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2417 d->d_namlen, d->d_namlen, d->d_name);
2418 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002419#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002420 if (!d->d_reclen) {
2421 tprintf("/* d_reclen == 0, problem here */");
2422 break;
2423 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002424 i += d->d_reclen;
2425 dents++;
2426 }
2427 if (!abbrev(tcp))
2428 tprintf("}");
2429 else
2430 tprintf("/* %u entries */", dents);
2431 tprintf(", %lu", tcp->u_arg[2]);
2432 free(buf);
2433 return 0;
2434}
2435
John Hughesbdf48f52001-03-06 15:08:09 +00002436
2437#if _LFS64_LARGEFILE
2438int
2439sys_getdents64(tcp)
2440struct tcb *tcp;
2441{
2442 int i, len, dents = 0;
2443 char *buf;
2444
2445 if (entering(tcp)) {
2446 tprintf("%lu, ", tcp->u_arg[0]);
2447 return 0;
2448 }
2449 if (syserror(tcp) || !verbose(tcp)) {
2450 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2451 return 0;
2452 }
2453 len = tcp->u_rval;
2454 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002455 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2456 fprintf(stderr, "out of memory\n");
John Hughesbdf48f52001-03-06 15:08:09 +00002457 return 0;
2458 }
2459 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002460 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002461 free(buf);
2462 return 0;
2463 }
2464 if (!abbrev(tcp))
2465 tprintf("{");
2466 for (i = 0; i < len;) {
2467 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002468#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002469 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002470 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002471 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002472 d->d_ino,
2473 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002474#ifdef LINUX
2475 tprintf("d_type=");
2476 printxval(direnttypes, d->d_type, "DT_???");
2477 tprintf(", ");
2478#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002479 tprintf("d_reclen=%u, d_name=\"%s\"}",
2480 d->d_reclen, d->d_name);
2481 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002482#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002483#ifdef SUNOS4
2484 if (!abbrev(tcp)) {
2485 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2486 i ? " " : "", d->d_off, d->d_fileno,
2487 d->d_reclen);
2488 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2489 d->d_namlen, d->d_namlen, d->d_name);
2490 }
2491#endif /* SUNOS4 */
2492 i += d->d_reclen;
2493 dents++;
2494 }
2495 if (!abbrev(tcp))
2496 tprintf("}");
2497 else
2498 tprintf("/* %u entries */", dents);
2499 tprintf(", %lu", tcp->u_arg[2]);
2500 free(buf);
2501 return 0;
2502}
2503#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002504
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002505#ifdef FREEBSD
2506int
2507sys_getdirentries(tcp)
2508struct tcb * tcp;
2509{
2510 int i, len, dents = 0;
2511 long basep;
2512 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002513
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002514 if (entering(tcp)) {
2515 tprintf("%lu, ", tcp->u_arg[0]);
2516 return 0;
2517 }
2518 if (syserror(tcp) || !verbose(tcp)) {
2519 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2520 return 0;
2521 }
2522 len = tcp->u_rval;
2523 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002524 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2525 fprintf(stderr, "out of memory\n");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002526 return 0;
2527 }
2528 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002529 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002530 free(buf);
2531 return 0;
2532 }
2533 if (!abbrev(tcp))
2534 tprintf("{");
2535 for (i = 0; i < len;) {
2536 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2537 if (!abbrev(tcp)) {
2538 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2539 i ? " " : "", d->d_fileno, d->d_reclen);
2540 printxval(direnttypes, d->d_type, "DT_???");
2541 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2542 d->d_namlen, d->d_namlen, d->d_name);
2543 }
2544 i += d->d_reclen;
2545 dents++;
2546 }
2547 if (!abbrev(tcp))
2548 tprintf("}");
2549 else
2550 tprintf("/* %u entries */", dents);
2551 free(buf);
2552 tprintf(", %lu", tcp->u_arg[2]);
2553 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2554 tprintf(", %#lx", tcp->u_arg[3]);
2555 else
2556 tprintf(", [%lu]", basep);
2557 return 0;
2558}
2559#endif
2560
Michal Ludvig53b320f2002-09-23 13:30:09 +00002561#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002562int
2563sys_getcwd(tcp)
2564struct tcb *tcp;
2565{
2566 if (exiting(tcp)) {
2567 if (syserror(tcp))
2568 tprintf("%#lx", tcp->u_arg[0]);
2569 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002570 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002571 tprintf(", %lu", tcp->u_arg[1]);
2572 }
2573 return 0;
2574}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002575#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002576
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002577#ifdef FREEBSD
2578int
2579sys___getcwd(tcp)
2580struct tcb *tcp;
2581{
2582 if (exiting(tcp)) {
2583 if (syserror(tcp))
2584 tprintf("%#lx", tcp->u_arg[0]);
2585 else
2586 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2587 tprintf(", %lu", tcp->u_arg[1]);
2588 }
2589 return 0;
2590}
2591#endif
2592
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002593#ifdef HAVE_SYS_ASYNCH_H
2594
2595int
2596sys_aioread(tcp)
2597struct tcb *tcp;
2598{
2599 struct aio_result_t res;
2600
2601 if (entering(tcp)) {
2602 tprintf("%lu, ", tcp->u_arg[0]);
2603 } else {
2604 if (syserror(tcp))
2605 tprintf("%#lx", tcp->u_arg[1]);
2606 else
2607 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2608 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2609 printxval(whence, tcp->u_arg[4], "L_???");
2610 if (syserror(tcp) || tcp->u_arg[5] == 0
2611 || umove(tcp, tcp->u_arg[5], &res) < 0)
2612 tprintf(", %#lx", tcp->u_arg[5]);
2613 else
2614 tprintf(", {aio_return %d aio_errno %d}",
2615 res.aio_return, res.aio_errno);
2616 }
2617 return 0;
2618}
2619
2620int
2621sys_aiowrite(tcp)
2622struct tcb *tcp;
2623{
2624 struct aio_result_t res;
2625
2626 if (entering(tcp)) {
2627 tprintf("%lu, ", tcp->u_arg[0]);
2628 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2629 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2630 printxval(whence, tcp->u_arg[4], "L_???");
2631 }
2632 else {
2633 if (tcp->u_arg[5] == 0)
2634 tprintf(", NULL");
2635 else if (syserror(tcp)
2636 || umove(tcp, tcp->u_arg[5], &res) < 0)
2637 tprintf(", %#lx", tcp->u_arg[5]);
2638 else
2639 tprintf(", {aio_return %d aio_errno %d}",
2640 res.aio_return, res.aio_errno);
2641 }
2642 return 0;
2643}
2644
2645int
2646sys_aiowait(tcp)
2647struct tcb *tcp;
2648{
2649 if (entering(tcp))
2650 printtv(tcp, tcp->u_arg[0]);
2651 return 0;
2652}
2653
2654int
2655sys_aiocancel(tcp)
2656struct tcb *tcp;
2657{
2658 struct aio_result_t res;
2659
2660 if (exiting(tcp)) {
2661 if (tcp->u_arg[0] == 0)
2662 tprintf("NULL");
2663 else if (syserror(tcp)
2664 || umove(tcp, tcp->u_arg[0], &res) < 0)
2665 tprintf("%#lx", tcp->u_arg[0]);
2666 else
2667 tprintf("{aio_return %d aio_errno %d}",
2668 res.aio_return, res.aio_errno);
2669 }
2670 return 0;
2671}
2672
2673#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002674
Roland McGratha4d48532005-06-08 20:45:28 +00002675static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002676#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002677 { XATTR_CREATE, "XATTR_CREATE" },
2678 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002679#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002680 { 0, NULL }
2681};
2682
Roland McGrath3292e222004-08-31 06:30:48 +00002683static void
2684print_xattr_val(tcp, failed, arg, insize, size)
2685struct tcb *tcp;
2686int failed;
2687unsigned long arg;
Roland McGrathaa524c82005-06-01 19:22:06 +00002688unsigned long insize, size;
Roland McGrath3292e222004-08-31 06:30:48 +00002689{
Roland McGrath883567c2005-02-02 03:38:32 +00002690 if (!failed) {
Roland McGrathaa524c82005-06-01 19:22:06 +00002691 unsigned long capacity = 4 * size + 1;
2692 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
Roland McGrath883567c2005-02-02 03:38:32 +00002693 if (buf == NULL || /* probably a bogus size argument */
Roland McGrathf7746422005-03-01 23:02:32 +00002694 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
Roland McGrath883567c2005-02-02 03:38:32 +00002695 failed = 1;
2696 }
2697 else {
2698 unsigned char *out = buf;
2699 unsigned char *in = &buf[3 * size];
2700 size_t i;
2701 for (i = 0; i < size; ++i)
2702 if (isprint(in[i]))
2703 *out++ = in[i];
2704 else {
Roland McGrath3292e222004-08-31 06:30:48 +00002705#define tohex(n) "0123456789abcdef"[n]
Roland McGrath883567c2005-02-02 03:38:32 +00002706 *out++ = '\\';
2707 *out++ = 'x';
2708 *out++ = tohex(in[i] / 16);
2709 *out++ = tohex(in[i] % 16);
2710 }
2711 /* Don't print terminating NUL if there is one. */
Dmitry V. Levin504eb0b2006-10-11 22:58:31 +00002712 if (i > 0 && in[i - 1] == '\0')
Roland McGrath883567c2005-02-02 03:38:32 +00002713 out -= 4;
2714 *out = '\0';
2715 tprintf(", \"%s\", %ld", buf, insize);
2716 }
2717 free(buf);
2718 }
2719 if (failed)
2720 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002721}
2722
Roland McGrath186c5ac2002-12-15 23:58:23 +00002723int
2724sys_setxattr(tcp)
2725struct tcb *tcp;
2726{
2727 if (entering(tcp)) {
2728 printpath(tcp, tcp->u_arg[0]);
2729 tprintf(", ");
2730 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002731 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2732 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002733 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002734 }
2735 return 0;
2736}
2737
2738int
2739sys_fsetxattr(tcp)
2740struct tcb *tcp;
2741{
2742 if (entering(tcp)) {
2743 tprintf("%ld, ", tcp->u_arg[0]);
2744 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002745 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2746 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002747 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002748 }
2749 return 0;
2750}
2751
2752int
2753sys_getxattr(tcp)
2754struct tcb *tcp;
2755{
2756 if (entering(tcp)) {
2757 printpath(tcp, tcp->u_arg[0]);
2758 tprintf(", ");
2759 printstr(tcp, tcp->u_arg[1], -1);
2760 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002761 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2762 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002763 }
2764 return 0;
2765}
2766
2767int
2768sys_fgetxattr(tcp)
2769struct tcb *tcp;
2770{
2771 if (entering(tcp)) {
2772 tprintf("%ld, ", tcp->u_arg[0]);
2773 printstr(tcp, tcp->u_arg[1], -1);
2774 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002775 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2776 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002777 }
2778 return 0;
2779}
2780
2781int
2782sys_listxattr(tcp)
2783struct tcb *tcp;
2784{
2785 if (entering(tcp)) {
2786 printpath(tcp, tcp->u_arg[0]);
2787 } else {
2788 /* XXX Print value in format */
2789 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2790 }
2791 return 0;
2792}
2793
2794int
2795sys_flistxattr(tcp)
2796struct tcb *tcp;
2797{
2798 if (entering(tcp)) {
2799 tprintf("%ld", tcp->u_arg[0]);
2800 } else {
2801 /* XXX Print value in format */
2802 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2803 }
2804 return 0;
2805}
2806
2807int
2808sys_removexattr(tcp)
2809struct tcb *tcp;
2810{
2811 if (entering(tcp)) {
2812 printpath(tcp, tcp->u_arg[0]);
2813 tprintf(", ");
2814 printstr(tcp, tcp->u_arg[1], -1);
2815 }
2816 return 0;
2817}
2818
2819int
2820sys_fremovexattr(tcp)
2821struct tcb *tcp;
2822{
2823 if (entering(tcp)) {
2824 tprintf("%ld, ", tcp->u_arg[0]);
2825 printstr(tcp, tcp->u_arg[1], -1);
2826 }
2827 return 0;
2828}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002829
2830
2831static const struct xlat advise[] = {
2832 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2833 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2834 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2835 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2836 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2837 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2838 { 0, NULL }
2839};
2840
2841
Roland McGrathe27ed342004-10-20 02:24:19 +00002842#ifdef LINUX
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002843int
2844sys_fadvise64(tcp)
2845struct tcb *tcp;
2846{
2847 if (entering(tcp)) {
2848 tprintf("%ld, %lld, %ld, ",
2849 tcp->u_arg[0],
2850# if defined IA64 || defined X86_64 || defined ALPHA
2851 (long long int) tcp->u_arg[1], tcp->u_arg[2]);
2852 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2853#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002854 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
2855 printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002856#endif
2857 }
2858 return 0;
2859}
2860#endif
2861
2862
2863int
2864sys_fadvise64_64(tcp)
2865struct tcb *tcp;
2866{
2867 if (entering(tcp)) {
2868 tprintf("%ld, %lld, %lld, ",
2869 tcp->u_arg[0],
2870# if defined IA64 || defined X86_64 || defined ALPHA
2871 (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
2872 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2873#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002874 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
2875 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002876 printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
2877#endif
2878 }
2879 return 0;
2880}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002881
2882#ifdef LINUX
2883static const struct xlat inotify_modes[] = {
2884 { 0x00000001, "IN_ACCESS" },
2885 { 0x00000002, "IN_MODIFY" },
2886 { 0x00000004, "IN_ATTRIB" },
2887 { 0x00000008, "IN_CLOSE_WRITE" },
2888 { 0x00000010, "IN_CLOSE_NOWRITE" },
2889 { 0x00000020, "IN_OPEN" },
2890 { 0x00000040, "IN_MOVED_FROM" },
2891 { 0x00000080, "IN_MOVED_TO" },
2892 { 0x00000100, "IN_CREATE" },
2893 { 0x00000200, "IN_DELETE" },
2894 { 0x00000400, "IN_DELETE_SELF" },
2895 { 0x00000800, "IN_MOVE_SELF" },
2896 { 0x00002000, "IN_UNMOUNT" },
2897 { 0x00004000, "IN_Q_OVERFLOW" },
2898 { 0x00008000, "IN_IGNORED" },
2899 { 0x01000000, "IN_ONLYDIR" },
2900 { 0x02000000, "IN_DONT_FOLLOW" },
2901 { 0x20000000, "IN_MASK_ADD" },
2902 { 0x40000000, "IN_ISDIR" },
2903 { 0x80000000, "IN_ONESHOT" }
2904};
2905
2906int
2907sys_inotify_add_watch(struct tcb *tcp)
2908{
2909 if (entering(tcp)) {
2910 tprintf("%ld, ", tcp->u_arg[0]);
2911 printpath(tcp, tcp->u_arg[1]);
2912 tprintf(", ");
2913 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2914 }
2915 return 0;
2916}
2917
2918int
2919sys_inotify_rm_watch(struct tcb *tcp)
2920{
2921 if (entering(tcp)) {
2922 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
2923 }
2924 return 0;
2925}
2926#endif