blob: 5eb67657693768d43c2afa22eff7b3692802f8b3 [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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000272
273#ifdef FNDELAY
274 { FNDELAY, "FNDELAY" },
275#endif
276#ifdef FAPPEND
277 { FAPPEND, "FAPPEND" },
278#endif
279#ifdef FMARK
280 { FMARK, "FMARK" },
281#endif
282#ifdef FDEFER
283 { FDEFER, "FDEFER" },
284#endif
285#ifdef FASYNC
286 { FASYNC, "FASYNC" },
287#endif
288#ifdef FSHLOCK
289 { FSHLOCK, "FSHLOCK" },
290#endif
291#ifdef FEXLOCK
292 { FEXLOCK, "FEXLOCK" },
293#endif
294#ifdef FCREAT
295 { FCREAT, "FCREAT" },
296#endif
297#ifdef FTRUNC
298 { FTRUNC, "FTRUNC" },
299#endif
300#ifdef FEXCL
301 { FEXCL, "FEXCL" },
302#endif
303#ifdef FNBIO
304 { FNBIO, "FNBIO" },
305#endif
306#ifdef FSYNC
307 { FSYNC, "FSYNC" },
308#endif
309#ifdef FNOCTTY
310 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000311#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000312#ifdef O_SHLOCK
313 { O_SHLOCK, "O_SHLOCK" },
314#endif
315#ifdef O_EXLOCK
316 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000317#endif
318 { 0, NULL },
319};
320
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000321#ifdef LINUX
322
323#ifndef AT_FDCWD
324# define AT_FDCWD -100
325#endif
326
327static void
328print_dirfd(long fd)
329{
330 if (fd == AT_FDCWD)
331 tprintf("AT_FDCWD, ");
332 else
333 tprintf("%ld, ", fd);
334}
335#endif
336
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000337/*
338 * low bits of the open(2) flags define access mode,
339 * other bits are real flags.
340 */
341void
342tprint_open_modes(struct tcb *tcp, mode_t flags)
343{
344 const char *str = xlookup(open_access_modes, flags & 3);
345
346 if (str)
347 {
348 tprintf("%s", str);
349 flags &= ~3;
350 if (!flags)
351 return;
352 tprintf("|");
353 }
354 printflags(open_mode_flags, flags, "O_???");
355}
356
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000357static int
358decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000359{
360 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000361 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000362 tprintf(", ");
363 /* flags */
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000364 tprint_open_modes(tcp, tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000365 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000366 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000367 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000368 }
369 }
370 return 0;
371}
372
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000373int
374sys_open(struct tcb *tcp)
375{
376 return decode_open(tcp, 0);
377}
378
379#ifdef LINUX
380int
381sys_openat(struct tcb *tcp)
382{
383 if (entering(tcp))
384 print_dirfd(tcp->u_arg[0]);
385 return decode_open(tcp, 1);
386}
387#endif
388
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000389#ifdef LINUXSPARC
Roland McGratha4d48532005-06-08 20:45:28 +0000390static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000391 { 0, "O_RDWR" },
392 { 1, "O_RDONLY" },
393 { 2, "O_WRONLY" },
394 { 0x80, "O_NONBLOCK" },
395 { 8, "O_APPEND" },
396 { 0x100, "O_CREAT" },
397 { 0x200, "O_TRUNC" },
398 { 0x400, "O_EXCL" },
399 { 0x800, "O_NOCTTY" },
400 { 0x10, "O_SYNC" },
401 { 0x40, "O_DSYNC" },
402 { 0x8000, "O_RSYNC" },
403 { 4, "O_NDELAY" },
404 { 0x1000, "O_PRIV" },
405 { 0, NULL },
406};
407
408int
409solaris_open(tcp)
410struct tcb *tcp;
411{
412 if (entering(tcp)) {
413 printpath(tcp, tcp->u_arg[0]);
414 tprintf(", ");
415 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000416 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000417 if (tcp->u_arg[1] & 0x100) {
418 /* mode */
419 tprintf(", %#lo", tcp->u_arg[2]);
420 }
421 }
422 return 0;
423}
424
425#endif
426
427int
428sys_creat(tcp)
429struct tcb *tcp;
430{
431 if (entering(tcp)) {
432 printpath(tcp, tcp->u_arg[0]);
433 tprintf(", %#lo", tcp->u_arg[1]);
434 }
435 return 0;
436}
437
Roland McGrathd9f816f2004-09-04 03:39:20 +0000438static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000439 { F_OK, "F_OK", },
440 { R_OK, "R_OK" },
441 { W_OK, "W_OK" },
442 { X_OK, "X_OK" },
443#ifdef EFF_ONLY_OK
444 { EFF_ONLY_OK, "EFF_ONLY_OK" },
445#endif
446#ifdef EX_OK
447 { EX_OK, "EX_OK" },
448#endif
449 { 0, NULL },
450};
451
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000452static int
453decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000454{
455 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000456 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000457 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000458 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000459 }
460 return 0;
461}
462
463int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000464sys_access(struct tcb *tcp)
465{
466 return decode_access(tcp, 0);
467}
468
469#ifdef LINUX
470int
471sys_faccessat(struct tcb *tcp)
472{
473 if (entering(tcp))
474 print_dirfd(tcp->u_arg[0]);
475 return decode_access(tcp, 1);
476}
477#endif
478
479int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000480sys_umask(tcp)
481struct tcb *tcp;
482{
483 if (entering(tcp)) {
484 tprintf("%#lo", tcp->u_arg[0]);
485 }
486 return RVAL_OCTAL;
487}
488
Roland McGrathd9f816f2004-09-04 03:39:20 +0000489static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000490 { SEEK_SET, "SEEK_SET" },
491 { SEEK_CUR, "SEEK_CUR" },
492 { SEEK_END, "SEEK_END" },
493 { 0, NULL },
494};
495
John Hughes70623be2001-03-08 13:59:00 +0000496#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000497int
498sys_lseek(tcp)
499struct tcb *tcp;
500{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000501 off_t offset;
502 int _whence;
503
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000504 if (entering(tcp)) {
505 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000506 offset = tcp->u_arg[1];
507 _whence = tcp->u_arg[2];
508 if (_whence == SEEK_SET)
509 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000510 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000511 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000512 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000513 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000514 return RVAL_UDECIMAL;
515}
John Hughes5a826b82001-03-07 13:21:24 +0000516#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517
Michal Ludvig53b320f2002-09-23 13:30:09 +0000518#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000519int
520sys_llseek (tcp)
521struct tcb *tcp;
522{
523 if (entering(tcp)) {
Roland McGrath8c304bc2004-10-19 22:59:55 +0000524 /*
525 * This one call takes explicitly two 32-bit arguments hi, lo,
526 * rather than one 64-bit argument for which LONG_LONG works
527 * appropriate for the native byte order.
528 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000529 if (tcp->u_arg[4] == SEEK_SET)
530 tprintf("%ld, %llu, ", tcp->u_arg[0],
Roland McGrath8c304bc2004-10-19 22:59:55 +0000531 (((long long int) tcp->u_arg[1]) << 32
532 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000533 else
534 tprintf("%ld, %lld, ", tcp->u_arg[0],
Roland McGrath8c304bc2004-10-19 22:59:55 +0000535 (((long long int) tcp->u_arg[1]) << 32
536 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000537 }
538 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000539 long long int off;
540 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541 tprintf("%#lx, ", tcp->u_arg[3]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000542 else
543 tprintf("[%llu], ", off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000544 printxval(whence, tcp->u_arg[4], "SEEK_???");
545 }
546 return 0;
547}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000548
549int
550sys_readahead (tcp)
551struct tcb *tcp;
552{
553 if (entering(tcp)) {
554 tprintf("%ld, %lld, %ld", tcp->u_arg[0],
555# if defined IA64 || defined X86_64 || defined ALPHA
556 (long long int) tcp->u_arg[1], tcp->u_arg[2]
557# else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +0000558 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]
Roland McGrath186c5ac2002-12-15 23:58:23 +0000559# endif
560 );
561 }
562 return 0;
563}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564#endif
565
John Hughes70623be2001-03-08 13:59:00 +0000566#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000567int
568sys_lseek64 (tcp)
569struct tcb *tcp;
570{
571 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000572 long long offset;
573 ALIGN64 (tcp, 1); /* FreeBSD aligns off_t args */
John Hughes0c79e012001-03-08 14:40:06 +0000574 offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +0000575 if (tcp->u_arg[3] == SEEK_SET)
576 tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
577 else
578 tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
579 printxval(whence, tcp->u_arg[3], "SEEK_???");
580 }
581 return RVAL_LUDECIMAL;
582}
583#endif
584
John Hughes70623be2001-03-08 13:59:00 +0000585#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000586int
587sys_truncate(tcp)
588struct tcb *tcp;
589{
590 if (entering(tcp)) {
591 printpath(tcp, tcp->u_arg[0]);
592 tprintf(", %lu", tcp->u_arg[1]);
593 }
594 return 0;
595}
John Hughes5a826b82001-03-07 13:21:24 +0000596#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000597
John Hughes70623be2001-03-08 13:59:00 +0000598#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000599int
600sys_truncate64(tcp)
601struct tcb *tcp;
602{
603 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000604 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000605 printpath(tcp, tcp->u_arg[0]);
John Hughes0c79e012001-03-08 14:40:06 +0000606 tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000607 }
608 return 0;
609}
610#endif
611
John Hughes70623be2001-03-08 13:59:00 +0000612#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000613int
614sys_ftruncate(tcp)
615struct tcb *tcp;
616{
617 if (entering(tcp)) {
618 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
619 }
620 return 0;
621}
John Hughes5a826b82001-03-07 13:21:24 +0000622#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000623
John Hughes70623be2001-03-08 13:59:00 +0000624#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000625int
626sys_ftruncate64(tcp)
627struct tcb *tcp;
628{
629 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000630 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000631 tprintf("%ld, %llu", tcp->u_arg[0],
John Hughes0c79e012001-03-08 14:40:06 +0000632 LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000633 }
634 return 0;
635}
636#endif
637
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000638/* several stats */
639
Roland McGrathd9f816f2004-09-04 03:39:20 +0000640static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000641 { S_IFREG, "S_IFREG" },
642 { S_IFSOCK, "S_IFSOCK" },
643 { S_IFIFO, "S_IFIFO" },
644 { S_IFLNK, "S_IFLNK" },
645 { S_IFDIR, "S_IFDIR" },
646 { S_IFBLK, "S_IFBLK" },
647 { S_IFCHR, "S_IFCHR" },
648 { 0, NULL },
649};
650
Roland McGrathf9c49b22004-10-06 22:11:54 +0000651static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000652sprintmode(mode)
653int mode;
654{
655 static char buf[64];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000656 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000657
658 if ((mode & S_IFMT) == 0)
659 s = "";
660 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
661 sprintf(buf, "%#o", mode);
662 return buf;
663 }
664 sprintf(buf, "%s%s%s%s", s,
665 (mode & S_ISUID) ? "|S_ISUID" : "",
666 (mode & S_ISGID) ? "|S_ISGID" : "",
667 (mode & S_ISVTX) ? "|S_ISVTX" : "");
668 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
669 if (mode)
670 sprintf(buf + strlen(buf), "|%#o", mode);
671 s = (*buf == '|') ? buf + 1 : buf;
672 return *s ? s : "0";
673}
674
675static char *
676sprinttime(t)
677time_t t;
678{
679 struct tm *tmp;
680 static char buf[32];
681
682 if (t == 0) {
683 sprintf(buf, "0");
684 return buf;
685 }
686 tmp = localtime(&t);
687 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
Wichert Akkerman3ed6dc22000-01-11 14:41:09 +0000688 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000689 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
690 return buf;
691}
692
693#ifdef LINUXSPARC
694typedef struct {
695 int tv_sec;
696 int tv_nsec;
697} timestruct_t;
698
699struct solstat {
700 unsigned st_dev;
701 int st_pad1[3]; /* network id */
702 unsigned st_ino;
703 unsigned st_mode;
704 unsigned st_nlink;
705 unsigned st_uid;
706 unsigned st_gid;
707 unsigned st_rdev;
708 int st_pad2[2];
709 int st_size;
710 int st_pad3; /* st_size, off_t expansion */
711 timestruct_t st_atime;
712 timestruct_t st_mtime;
713 timestruct_t st_ctime;
714 int st_blksize;
715 int st_blocks;
716 char st_fstype[16];
717 int st_pad4[8]; /* expansion area */
718};
719
720static void
721printstatsol(tcp, addr)
722struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000723long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000724{
725 struct solstat statbuf;
726
727 if (!addr) {
728 tprintf("NULL");
729 return;
730 }
731 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000732 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000733 return;
734 }
735 if (umove(tcp, addr, &statbuf) < 0) {
736 tprintf("{...}");
737 return;
738 }
739 if (!abbrev(tcp)) {
740 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
741 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
742 (unsigned long) (statbuf.st_dev & 0x3ffff),
743 (unsigned long) statbuf.st_ino,
744 sprintmode(statbuf.st_mode));
745 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
746 (unsigned long) statbuf.st_nlink,
747 (unsigned long) statbuf.st_uid,
748 (unsigned long) statbuf.st_gid);
749 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
750 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
751 }
752 else
753 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
754 switch (statbuf.st_mode & S_IFMT) {
755 case S_IFCHR: case S_IFBLK:
756 tprintf("st_rdev=makedev(%lu, %lu), ",
757 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
758 (unsigned long) (statbuf.st_rdev & 0x3ffff));
759 break;
760 default:
761 tprintf("st_size=%u, ", statbuf.st_size);
762 break;
763 }
764 if (!abbrev(tcp)) {
765 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
766 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
767 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
768 }
769 else
770 tprintf("...}");
771}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000772
773#if defined (SPARC64)
774static void
775printstat_sparc64(tcp, addr)
776struct tcb *tcp;
777long addr;
778{
779 struct stat_sparc64 statbuf;
780
781 if (!addr) {
782 tprintf("NULL");
783 return;
784 }
785 if (syserror(tcp) || !verbose(tcp)) {
786 tprintf("%#lx", addr);
787 return;
788 }
789 if (umove(tcp, addr, &statbuf) < 0) {
790 tprintf("{...}");
791 return;
792 }
793
794 if (!abbrev(tcp)) {
795 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
796 (unsigned long) major(statbuf.st_dev),
797 (unsigned long) minor(statbuf.st_dev),
798 (unsigned long) statbuf.st_ino,
799 sprintmode(statbuf.st_mode));
800 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
801 (unsigned long) statbuf.st_nlink,
802 (unsigned long) statbuf.st_uid,
803 (unsigned long) statbuf.st_gid);
804 tprintf("st_blksize=%lu, ",
805 (unsigned long) statbuf.st_blksize);
806 tprintf("st_blocks=%lu, ",
807 (unsigned long) statbuf.st_blocks);
808 }
809 else
810 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
811 switch (statbuf.st_mode & S_IFMT) {
812 case S_IFCHR: case S_IFBLK:
813 tprintf("st_rdev=makedev(%lu, %lu), ",
814 (unsigned long) major(statbuf.st_rdev),
815 (unsigned long) minor(statbuf.st_rdev));
816 break;
817 default:
818 tprintf("st_size=%lu, ", statbuf.st_size);
819 break;
820 }
821 if (!abbrev(tcp)) {
822 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
823 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
824 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
825 tprintf("}");
826 }
827 else
828 tprintf("...}");
829}
830#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000831#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000832
Roland McGratha4d48532005-06-08 20:45:28 +0000833static const struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000834#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000835 { UF_NODUMP, "UF_NODUMP" },
836 { UF_IMMUTABLE, "UF_IMMUTABLE" },
837 { UF_APPEND, "UF_APPEND" },
838 { UF_OPAQUE, "UF_OPAQUE" },
839 { UF_NOUNLINK, "UF_NOUNLINK" },
840 { SF_ARCHIVED, "SF_ARCHIVED" },
841 { SF_IMMUTABLE, "SF_IMMUTABLE" },
842 { SF_APPEND, "SF_APPEND" },
843 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000844#elif UNIXWARE >= 2
845#ifdef _S_ISMLD
846 { _S_ISMLD, "_S_ISMLD" },
847#endif
848#ifdef _S_ISMOUNTED
849 { _S_ISMOUNTED, "_S_ISMOUNTED" },
850#endif
851#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000852 { 0, NULL },
853};
854
John Hughesc0fc3fd2001-03-08 16:10:40 +0000855#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000856int
857sys_chflags(tcp)
858struct tcb *tcp;
859{
860 if (entering(tcp)) {
861 printpath(tcp, tcp->u_arg[0]);
862 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000863 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000864 }
865 return 0;
866}
867
868int
869sys_fchflags(tcp)
870struct tcb *tcp;
871{
872 if (entering(tcp)) {
873 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000874 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000875 }
876 return 0;
877}
878#endif
879
John Hughes70623be2001-03-08 13:59:00 +0000880#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000881static void
882realprintstat(tcp, statbuf)
883struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000884struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000885{
886 if (!abbrev(tcp)) {
887 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
888 (unsigned long) major(statbuf->st_dev),
889 (unsigned long) minor(statbuf->st_dev),
890 (unsigned long) statbuf->st_ino,
891 sprintmode(statbuf->st_mode));
892 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
893 (unsigned long) statbuf->st_nlink,
894 (unsigned long) statbuf->st_uid,
895 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000896#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000897 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000898#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
899#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000900 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000901#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000902 }
903 else
904 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
905 switch (statbuf->st_mode & S_IFMT) {
906 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000907#ifdef HAVE_STRUCT_STAT_ST_RDEV
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000908 tprintf("st_rdev=makedev(%lu, %lu), ",
909 (unsigned long) major(statbuf->st_rdev),
910 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000911#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000912 tprintf("st_size=makedev(%lu, %lu), ",
913 (unsigned long) major(statbuf->st_size),
914 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000915#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000916 break;
917 default:
918 tprintf("st_size=%lu, ", statbuf->st_size);
919 break;
920 }
921 if (!abbrev(tcp)) {
922 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
923 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000924 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000925#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000926 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000927 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000928#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000929#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000930 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
931#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000932#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000933 tprintf(", st_level=%ld", statbuf->st_level);
934#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000935#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000936 tprintf(", st_fstype=%.*s",
937 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
938#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000939#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000940 tprintf(", st_gen=%u", statbuf->st_gen);
941#endif
942 tprintf("}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000943 }
944 else
945 tprintf("...}");
946}
947
Nate Sammons771a6ff1999-04-05 22:39:31 +0000948
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000949static void
950printstat(tcp, addr)
951struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000952long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000953{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000954 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000955
956#ifdef LINUXSPARC
957 if (current_personality == 1) {
958 printstatsol(tcp, addr);
959 return;
960 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000961#ifdef SPARC64
962 else if (current_personality == 2) {
963 printstat_sparc64(tcp, addr);
964 return;
965 }
966#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000967#endif /* LINUXSPARC */
968
969 if (!addr) {
970 tprintf("NULL");
971 return;
972 }
973 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000974 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000975 return;
976 }
977 if (umove(tcp, addr, &statbuf) < 0) {
978 tprintf("{...}");
979 return;
980 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000981
982 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000983}
John Hughes70623be2001-03-08 13:59:00 +0000984#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000985
Wichert Akkermanc7926982000-04-10 22:22:31 +0000986#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000987static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000988printstat64(tcp, addr)
989struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000990long addr;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000991{
992 struct stat64 statbuf;
993
994#ifdef LINUXSPARC
995 if (current_personality == 1) {
996 printstatsol(tcp, addr);
997 return;
998 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000999#ifdef SPARC64
1000 else if (current_personality == 2) {
1001 printstat_sparc64(tcp, addr);
1002 return;
1003 }
1004#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001005#endif /* LINUXSPARC */
1006
1007 if (!addr) {
1008 tprintf("NULL");
1009 return;
1010 }
1011 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001012 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001013 return;
1014 }
1015 if (umove(tcp, addr, &statbuf) < 0) {
1016 tprintf("{...}");
1017 return;
1018 }
1019
1020 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001021#ifdef HAVE_LONG_LONG
1022 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1023#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001024 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001025#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001026 (unsigned long) major(statbuf.st_dev),
1027 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001028#ifdef HAVE_LONG_LONG
1029 (unsigned long long) statbuf.st_ino,
1030#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001031 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001032#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001033 sprintmode(statbuf.st_mode));
1034 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1035 (unsigned long) statbuf.st_nlink,
1036 (unsigned long) statbuf.st_uid,
1037 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001038#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001039 tprintf("st_blksize=%lu, ",
1040 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001041#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1042#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001043 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001044#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001045 }
1046 else
1047 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1048 switch (statbuf.st_mode & S_IFMT) {
1049 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001050#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001051 tprintf("st_rdev=makedev(%lu, %lu), ",
1052 (unsigned long) major(statbuf.st_rdev),
1053 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001054#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001055 tprintf("st_size=makedev(%lu, %lu), ",
1056 (unsigned long) major(statbuf.st_size),
1057 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001058#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001059 break;
1060 default:
1061 tprintf("st_size=%llu, ", statbuf.st_size);
1062 break;
1063 }
1064 if (!abbrev(tcp)) {
1065 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1066 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001067 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001068#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +00001069 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001070 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001071#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001072#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001073 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1074#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001075#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001076 tprintf(", st_level=%ld", statbuf.st_level);
1077#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001078#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001079 tprintf(", st_fstype=%.*s",
1080 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1081#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001082#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001083 tprintf(", st_gen=%u", statbuf.st_gen);
1084#endif
1085 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001086 }
1087 else
1088 tprintf("...}");
1089}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001090#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001091
Roland McGrath79db8af2003-06-27 21:20:09 +00001092#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001093static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001094convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001095const struct __old_kernel_stat *oldbuf;
1096struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001097{
1098 newbuf->st_dev=oldbuf->st_dev;
1099 newbuf->st_ino=oldbuf->st_ino;
1100 newbuf->st_mode=oldbuf->st_mode;
1101 newbuf->st_nlink=oldbuf->st_nlink;
1102 newbuf->st_uid=oldbuf->st_uid;
1103 newbuf->st_gid=oldbuf->st_gid;
1104 newbuf->st_rdev=oldbuf->st_rdev;
1105 newbuf->st_size=oldbuf->st_size;
1106 newbuf->st_atime=oldbuf->st_atime;
1107 newbuf->st_mtime=oldbuf->st_mtime;
1108 newbuf->st_ctime=oldbuf->st_ctime;
1109 newbuf->st_blksize=0; /* not supported in old_stat */
1110 newbuf->st_blocks=0; /* not supported in old_stat */
1111}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001112
1113
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001114static void
1115printoldstat(tcp, addr)
1116struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001117long addr;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001118{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001119 struct __old_kernel_stat statbuf;
1120 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001121
1122#ifdef LINUXSPARC
1123 if (current_personality == 1) {
1124 printstatsol(tcp, addr);
1125 return;
1126 }
1127#endif /* LINUXSPARC */
1128
1129 if (!addr) {
1130 tprintf("NULL");
1131 return;
1132 }
1133 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001134 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001135 return;
1136 }
1137 if (umove(tcp, addr, &statbuf) < 0) {
1138 tprintf("{...}");
1139 return;
1140 }
1141
1142 convertoldstat(&statbuf, &newstatbuf);
1143 realprintstat(tcp, &newstatbuf);
1144}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001145#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001146
John Hughes70623be2001-03-08 13:59:00 +00001147#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001148int
1149sys_stat(tcp)
1150struct tcb *tcp;
1151{
1152 if (entering(tcp)) {
1153 printpath(tcp, tcp->u_arg[0]);
1154 tprintf(", ");
1155 } else {
1156 printstat(tcp, tcp->u_arg[1]);
1157 }
1158 return 0;
1159}
John Hughesb8c9f772001-03-07 16:53:07 +00001160#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001161
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001162int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001163sys_stat64(tcp)
1164struct tcb *tcp;
1165{
1166#ifdef HAVE_STAT64
1167 if (entering(tcp)) {
1168 printpath(tcp, tcp->u_arg[0]);
1169 tprintf(", ");
1170 } else {
1171 printstat64(tcp, tcp->u_arg[1]);
1172 }
1173 return 0;
1174#else
1175 return printargs(tcp);
1176#endif
1177}
1178
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001179#ifdef LINUX
1180static const struct xlat fstatatflags[] = {
1181#ifndef AT_SYMLINK_NOFOLLOW
1182# define AT_SYMLINK_NOFOLLOW 0x100
1183#endif
1184 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1185 { 0, NULL },
1186};
Roland McGrath6afc5652007-07-24 01:57:11 +00001187#define utimensatflags fstatatflags
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001188
1189int
1190sys_newfstatat(struct tcb *tcp)
1191{
1192 if (entering(tcp)) {
1193 print_dirfd(tcp->u_arg[0]);
1194 printpath(tcp, tcp->u_arg[1]);
1195 tprintf(", ");
1196 } else {
Roland McGrath359c8ed2007-07-05 19:01:17 +00001197#if defined HAVE_STAT64 && !(defined POWERPC && defined __powerpc64__)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001198 printstat64(tcp, tcp->u_arg[2]);
1199#else
1200 printstat(tcp, tcp->u_arg[2]);
1201#endif
1202 tprintf(", ");
1203 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1204 }
1205 return 0;
1206}
1207#endif
1208
Roland McGrath79db8af2003-06-27 21:20:09 +00001209#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001210int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001211sys_oldstat(tcp)
1212struct tcb *tcp;
1213{
1214 if (entering(tcp)) {
1215 printpath(tcp, tcp->u_arg[0]);
1216 tprintf(", ");
1217 } else {
1218 printoldstat(tcp, tcp->u_arg[1]);
1219 }
1220 return 0;
1221}
Roland McGrath79db8af2003-06-27 21:20:09 +00001222#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001223
John Hughes70623be2001-03-08 13:59:00 +00001224#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001225int
1226sys_fstat(tcp)
1227struct tcb *tcp;
1228{
1229 if (entering(tcp))
1230 tprintf("%ld, ", tcp->u_arg[0]);
1231 else {
1232 printstat(tcp, tcp->u_arg[1]);
1233 }
1234 return 0;
1235}
John Hughesb8c9f772001-03-07 16:53:07 +00001236#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001237
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001238int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001239sys_fstat64(tcp)
1240struct tcb *tcp;
1241{
1242#ifdef HAVE_STAT64
1243 if (entering(tcp))
1244 tprintf("%ld, ", tcp->u_arg[0]);
1245 else {
1246 printstat64(tcp, tcp->u_arg[1]);
1247 }
1248 return 0;
1249#else
1250 return printargs(tcp);
1251#endif
1252}
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_oldfstat(tcp)
1257struct tcb *tcp;
1258{
1259 if (entering(tcp))
1260 tprintf("%ld, ", tcp->u_arg[0]);
1261 else {
1262 printoldstat(tcp, tcp->u_arg[1]);
1263 }
1264 return 0;
1265}
Roland McGrath79db8af2003-06-27 21:20:09 +00001266#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001267
John Hughes70623be2001-03-08 13:59:00 +00001268#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001269int
1270sys_lstat(tcp)
1271struct tcb *tcp;
1272{
1273 if (entering(tcp)) {
1274 printpath(tcp, tcp->u_arg[0]);
1275 tprintf(", ");
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_lstat64(tcp)
1285struct tcb *tcp;
1286{
1287#ifdef HAVE_STAT64
1288 if (entering(tcp)) {
1289 printpath(tcp, tcp->u_arg[0]);
1290 tprintf(", ");
1291 } else {
1292 printstat64(tcp, tcp->u_arg[1]);
1293 }
1294 return 0;
1295#else
1296 return printargs(tcp);
1297#endif
1298}
1299
Roland McGrath79db8af2003-06-27 21:20:09 +00001300#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001301int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001302sys_oldlstat(tcp)
1303struct tcb *tcp;
1304{
1305 if (entering(tcp)) {
1306 printpath(tcp, tcp->u_arg[0]);
1307 tprintf(", ");
1308 } else {
1309 printoldstat(tcp, tcp->u_arg[1]);
1310 }
1311 return 0;
1312}
Roland McGrath79db8af2003-06-27 21:20:09 +00001313#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001314
1315
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001316#if defined(SVR4) || defined(LINUXSPARC)
1317
1318int
1319sys_xstat(tcp)
1320struct tcb *tcp;
1321{
1322 if (entering(tcp)) {
1323 tprintf("%ld, ", tcp->u_arg[0]);
1324 printpath(tcp, tcp->u_arg[1]);
1325 tprintf(", ");
1326 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001327#ifdef _STAT64_VER
1328 if (tcp->u_arg[0] == _STAT64_VER)
1329 printstat64 (tcp, tcp->u_arg[2]);
1330 else
1331#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001332 printstat(tcp, tcp->u_arg[2]);
1333 }
1334 return 0;
1335}
1336
1337int
1338sys_fxstat(tcp)
1339struct tcb *tcp;
1340{
1341 if (entering(tcp))
1342 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1343 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001344#ifdef _STAT64_VER
1345 if (tcp->u_arg[0] == _STAT64_VER)
1346 printstat64 (tcp, tcp->u_arg[2]);
1347 else
1348#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001349 printstat(tcp, tcp->u_arg[2]);
1350 }
1351 return 0;
1352}
1353
1354int
1355sys_lxstat(tcp)
1356struct tcb *tcp;
1357{
1358 if (entering(tcp)) {
1359 tprintf("%ld, ", tcp->u_arg[0]);
1360 printpath(tcp, tcp->u_arg[1]);
1361 tprintf(", ");
1362 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001363#ifdef _STAT64_VER
1364 if (tcp->u_arg[0] == _STAT64_VER)
1365 printstat64 (tcp, tcp->u_arg[2]);
1366 else
1367#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001368 printstat(tcp, tcp->u_arg[2]);
1369 }
1370 return 0;
1371}
1372
1373int
1374sys_xmknod(tcp)
1375struct tcb *tcp;
1376{
1377 int mode = tcp->u_arg[2];
1378
1379 if (entering(tcp)) {
1380 tprintf("%ld, ", tcp->u_arg[0]);
1381 printpath(tcp, tcp->u_arg[1]);
1382 tprintf(", %s", sprintmode(mode));
1383 switch (mode & S_IFMT) {
1384 case S_IFCHR: case S_IFBLK:
1385#ifdef LINUXSPARC
1386 tprintf(", makedev(%lu, %lu)",
1387 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1388 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001389#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001390 tprintf(", makedev(%lu, %lu)",
1391 (unsigned long) major(tcp->u_arg[3]),
1392 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001393#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001394 break;
1395 default:
1396 break;
1397 }
1398 }
1399 return 0;
1400}
1401
Wichert Akkerman8829a551999-06-11 13:18:40 +00001402#ifdef HAVE_SYS_ACL_H
1403
1404#include <sys/acl.h>
1405
Roland McGratha4d48532005-06-08 20:45:28 +00001406static const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001407#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001408 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001409#endif
1410#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001411 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001412#endif
1413#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001414 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001415#endif
1416#ifdef ACL_GET
1417 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001418#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001419#ifdef ACL_SET
1420 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001421#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001422#ifdef ACL_CNT
1423 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001424#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001425 { 0, NULL },
1426};
1427
1428int
1429sys_acl(tcp)
1430struct tcb *tcp;
1431{
1432 if (entering(tcp)) {
1433 printpath(tcp, tcp->u_arg[0]);
1434 tprintf(", ");
1435 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1436 tprintf(", %ld", tcp->u_arg[2]);
1437 /*
1438 * FIXME - dump out the list of aclent_t's pointed to
1439 * by "tcp->u_arg[3]" if it's not NULL.
1440 */
1441 if (tcp->u_arg[3])
1442 tprintf(", %#lx", tcp->u_arg[3]);
1443 else
1444 tprintf(", NULL");
1445 }
1446 return 0;
1447}
1448
1449
1450int
1451sys_facl(tcp)
1452struct tcb *tcp;
1453{
1454 if (entering(tcp)) {
1455 tprintf("%ld, ", tcp->u_arg[0]);
1456 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1457 tprintf(", %ld", tcp->u_arg[2]);
1458 /*
1459 * FIXME - dump out the list of aclent_t's pointed to
1460 * by "tcp->u_arg[3]" if it's not NULL.
1461 */
1462 if (tcp->u_arg[3])
1463 tprintf(", %#lx", tcp->u_arg[3]);
1464 else
1465 tprintf(", NULL");
1466 }
1467 return 0;
1468}
1469
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001470
Roland McGratha4d48532005-06-08 20:45:28 +00001471static const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001472#ifdef IPC_SHM
1473 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001474#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001475#ifdef IPC_SEM
1476 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001477#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001478#ifdef IPC_MSG
1479 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001480#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001481 { 0, NULL },
1482};
1483
1484
1485int
1486sys_aclipc(tcp)
1487struct tcb *tcp;
1488{
1489 if (entering(tcp)) {
1490 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1491 tprintf(", %#lx, ", tcp->u_arg[1]);
1492 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1493 tprintf(", %ld", tcp->u_arg[3]);
1494 /*
1495 * FIXME - dump out the list of aclent_t's pointed to
1496 * by "tcp->u_arg[4]" if it's not NULL.
1497 */
1498 if (tcp->u_arg[4])
1499 tprintf(", %#lx", tcp->u_arg[4]);
1500 else
1501 tprintf(", NULL");
1502 }
1503 return 0;
1504}
1505
1506
1507
Wichert Akkerman8829a551999-06-11 13:18:40 +00001508#endif /* HAVE_SYS_ACL_H */
1509
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001510#endif /* SVR4 || LINUXSPARC */
1511
Michal Ludvig53b320f2002-09-23 13:30:09 +00001512#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001513
Roland McGrathd9f816f2004-09-04 03:39:20 +00001514static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001515 { 0x73757245, "CODA_SUPER_MAGIC" },
1516 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1517 { 0x1373, "DEVFS_SUPER_MAGIC" },
1518 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1519 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001520 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1521 { 0xef53, "EXT2_SUPER_MAGIC" },
1522 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001523 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001524 { 0x9660, "ISOFS_SUPER_MAGIC" },
1525 { 0x137f, "MINIX_SUPER_MAGIC" },
1526 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001527 { 0x2468, "MINIX2_SUPER_MAGIC" },
1528 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001529 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001530 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001531 { 0x6969, "NFS_SUPER_MAGIC" },
1532 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001533 { 0x002f, "QNX4_SUPER_MAGIC" },
1534 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1535 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1536 { 0x517b, "SMB_SUPER_MAGIC" },
1537 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1538 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1539 { 0x00011954, "UFS_MAGIC" },
1540 { 0x54190100, "UFS_CIGAM" },
1541 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001542 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001543 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001544 { 0, NULL },
1545};
1546
Michal Ludvig53b320f2002-09-23 13:30:09 +00001547#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001548
1549#ifndef SVR4
1550
Roland McGrathf9c49b22004-10-06 22:11:54 +00001551static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001552sprintfstype(magic)
1553int magic;
1554{
1555 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001556#ifdef LINUX
Roland McGrathf9c49b22004-10-06 22:11:54 +00001557 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001558
1559 s = xlookup(fsmagic, magic);
1560 if (s) {
1561 sprintf(buf, "\"%s\"", s);
1562 return buf;
1563 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001564#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001565 sprintf(buf, "%#x", magic);
1566 return buf;
1567}
1568
1569static void
1570printstatfs(tcp, addr)
1571struct tcb *tcp;
1572long addr;
1573{
1574 struct statfs statbuf;
1575
1576 if (syserror(tcp) || !verbose(tcp)) {
1577 tprintf("%#lx", addr);
1578 return;
1579 }
1580 if (umove(tcp, addr, &statbuf) < 0) {
1581 tprintf("{...}");
1582 return;
1583 }
1584#ifdef ALPHA
1585
1586 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1587 sprintfstype(statbuf.f_type),
1588 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001589 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1590 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1591 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1592 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001593#else /* !ALPHA */
1594 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1595 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001596 (unsigned long)statbuf.f_bsize,
1597 (unsigned long)statbuf.f_blocks,
1598 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001599 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1600 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001601 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001602 (unsigned long)statbuf.f_ffree,
1603 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001604#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001605 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001606#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001607#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001608#ifdef _STATFS_F_FRSIZE
1609 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1610#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001611 tprintf("}");
1612}
1613
1614int
1615sys_statfs(tcp)
1616struct tcb *tcp;
1617{
1618 if (entering(tcp)) {
1619 printpath(tcp, tcp->u_arg[0]);
1620 tprintf(", ");
1621 } else {
1622 printstatfs(tcp, tcp->u_arg[1]);
1623 }
1624 return 0;
1625}
1626
1627int
1628sys_fstatfs(tcp)
1629struct tcb *tcp;
1630{
1631 if (entering(tcp)) {
1632 tprintf("%lu, ", tcp->u_arg[0]);
1633 } else {
1634 printstatfs(tcp, tcp->u_arg[1]);
1635 }
1636 return 0;
1637}
1638
Roland McGrathab147c52003-07-17 09:03:02 +00001639#ifdef LINUX
1640static void
1641printstatfs64(tcp, addr)
1642struct tcb *tcp;
1643long addr;
1644{
1645 struct statfs64 statbuf;
1646
1647 if (syserror(tcp) || !verbose(tcp)) {
1648 tprintf("%#lx", addr);
1649 return;
1650 }
1651 if (umove(tcp, addr, &statbuf) < 0) {
1652 tprintf("{...}");
1653 return;
1654 }
Roland McGrath08738432005-06-03 02:40:39 +00001655 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001656 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001657 (unsigned long long)statbuf.f_bsize,
1658 (unsigned long long)statbuf.f_blocks,
1659 (unsigned long long)statbuf.f_bfree);
1660 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1661 (unsigned long long)statbuf.f_bavail,
1662 (unsigned long long)statbuf.f_files,
1663 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001664 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1665 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001666#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001667 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001668#endif
1669 tprintf("}");
1670}
1671
1672int
1673sys_statfs64(tcp)
1674struct tcb *tcp;
1675{
1676 if (entering(tcp)) {
1677 printpath(tcp, tcp->u_arg[0]);
1678 tprintf(", %lu, ", tcp->u_arg[1]);
1679 } else {
1680 if (tcp->u_arg[1] == sizeof (struct statfs64))
1681 printstatfs64(tcp, tcp->u_arg[2]);
1682 else
1683 tprintf("{???}");
1684 }
1685 return 0;
1686}
1687
1688int
1689sys_fstatfs64(tcp)
1690struct tcb *tcp;
1691{
1692 if (entering(tcp)) {
1693 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1694 } else {
1695 if (tcp->u_arg[1] == sizeof (struct statfs64))
1696 printstatfs64(tcp, tcp->u_arg[2]);
1697 else
1698 tprintf("{???}");
1699 }
1700 return 0;
1701}
1702#endif
1703
Michal Ludvig53b320f2002-09-23 13:30:09 +00001704#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001705
1706int
1707osf_statfs(tcp)
1708struct tcb *tcp;
1709{
1710 if (entering(tcp)) {
1711 printpath(tcp, tcp->u_arg[0]);
1712 tprintf(", ");
1713 } else {
1714 printstatfs(tcp, tcp->u_arg[1]);
1715 tprintf(", %lu", tcp->u_arg[2]);
1716 }
1717 return 0;
1718}
1719
1720int
1721osf_fstatfs(tcp)
1722struct tcb *tcp;
1723{
1724 if (entering(tcp)) {
1725 tprintf("%lu, ", tcp->u_arg[0]);
1726 } else {
1727 printstatfs(tcp, tcp->u_arg[1]);
1728 tprintf(", %lu", tcp->u_arg[2]);
1729 }
1730 return 0;
1731}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001732#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001733
1734#endif /* !SVR4 */
1735
1736#ifdef SUNOS4
1737
1738int
1739sys_ustat(tcp)
1740struct tcb *tcp;
1741{
1742 struct ustat statbuf;
1743
1744 if (entering(tcp)) {
1745 tprintf("makedev(%lu, %lu), ",
1746 (long) major(tcp->u_arg[0]),
1747 (long) minor(tcp->u_arg[0]));
1748 }
1749 else {
1750 if (syserror(tcp) || !verbose(tcp))
1751 tprintf("%#lx", tcp->u_arg[1]);
1752 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1753 tprintf("{...}");
1754 else {
1755 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1756 statbuf.f_tfree, statbuf.f_tinode);
1757 tprintf("f_fname=\"%.*s\", ",
1758 (int) sizeof(statbuf.f_fname),
1759 statbuf.f_fname);
1760 tprintf("f_fpack=\"%.*s\"}",
1761 (int) sizeof(statbuf.f_fpack),
1762 statbuf.f_fpack);
1763 }
1764 }
1765 return 0;
1766}
1767
1768#endif /* SUNOS4 */
1769
Wichert Akkermanc7926982000-04-10 22:22:31 +00001770int
1771sys_pivotroot(tcp)
1772struct tcb *tcp;
1773{
1774 if (entering(tcp)) {
1775 printpath(tcp, tcp->u_arg[0]);
1776 tprintf(", ");
1777 printpath(tcp, tcp->u_arg[1]);
1778 }
1779 return 0;
1780}
1781
1782
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001783/* directory */
1784int
1785sys_chdir(tcp)
1786struct tcb *tcp;
1787{
1788 if (entering(tcp)) {
1789 printpath(tcp, tcp->u_arg[0]);
1790 }
1791 return 0;
1792}
1793
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001794static int
1795decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001796{
1797 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001798 printpath(tcp, tcp->u_arg[offset]);
1799 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001800 }
1801 return 0;
1802}
1803
1804int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001805sys_mkdir(struct tcb *tcp)
1806{
1807 return decode_mkdir(tcp, 0);
1808}
1809
1810#ifdef LINUX
1811int
1812sys_mkdirat(struct tcb *tcp)
1813{
1814 if (entering(tcp))
1815 print_dirfd(tcp->u_arg[0]);
1816 return decode_mkdir(tcp, 1);
1817}
1818#endif
1819
1820int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001821sys_rmdir(tcp)
1822struct tcb *tcp;
1823{
1824 if (entering(tcp)) {
1825 printpath(tcp, tcp->u_arg[0]);
1826 }
1827 return 0;
1828}
1829
1830int
1831sys_fchdir(tcp)
1832struct tcb *tcp;
1833{
1834 if (entering(tcp)) {
1835 tprintf("%ld", tcp->u_arg[0]);
1836 }
1837 return 0;
1838}
1839
1840int
1841sys_chroot(tcp)
1842struct tcb *tcp;
1843{
1844 if (entering(tcp)) {
1845 printpath(tcp, tcp->u_arg[0]);
1846 }
1847 return 0;
1848}
1849
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001850#if defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001851int
1852sys_fchroot(tcp)
1853struct tcb *tcp;
1854{
1855 if (entering(tcp)) {
1856 tprintf("%ld", tcp->u_arg[0]);
1857 }
1858 return 0;
1859}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001860#endif /* SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001861
1862int
1863sys_link(tcp)
1864struct tcb *tcp;
1865{
1866 if (entering(tcp)) {
1867 printpath(tcp, tcp->u_arg[0]);
1868 tprintf(", ");
1869 printpath(tcp, tcp->u_arg[1]);
1870 }
1871 return 0;
1872}
1873
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001874#ifdef LINUX
1875int
1876sys_linkat(struct tcb *tcp)
1877{
1878 if (entering(tcp)) {
1879 print_dirfd(tcp->u_arg[0]);
1880 printpath(tcp, tcp->u_arg[1]);
1881 tprintf(", ");
1882 print_dirfd(tcp->u_arg[2]);
1883 printpath(tcp, tcp->u_arg[3]);
1884 tprintf(", %ld", tcp->u_arg[4]);
1885 }
1886 return 0;
1887}
1888#endif
1889
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001890int
1891sys_unlink(tcp)
1892struct tcb *tcp;
1893{
1894 if (entering(tcp)) {
1895 printpath(tcp, tcp->u_arg[0]);
1896 }
1897 return 0;
1898}
1899
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001900#ifdef LINUX
1901static const struct xlat unlinkatflags[] = {
1902#ifndef AT_REMOVEDIR
1903# define AT_REMOVEDIR 0x200
1904#endif
1905 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1906 { 0, NULL },
1907};
1908
1909int
1910sys_unlinkat(struct tcb *tcp)
1911{
1912 if (entering(tcp)) {
1913 print_dirfd(tcp->u_arg[0]);
1914 printpath(tcp, tcp->u_arg[1]);
1915 tprintf(", ");
1916 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1917 }
1918 return 0;
1919}
1920#endif
1921
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001922int
1923sys_symlink(tcp)
1924struct tcb *tcp;
1925{
1926 if (entering(tcp)) {
1927 printpath(tcp, tcp->u_arg[0]);
1928 tprintf(", ");
1929 printpath(tcp, tcp->u_arg[1]);
1930 }
1931 return 0;
1932}
1933
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001934#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001935int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001936sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001937{
1938 if (entering(tcp)) {
1939 printpath(tcp, tcp->u_arg[0]);
1940 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001941 print_dirfd(tcp->u_arg[1]);
1942 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001943 }
1944 return 0;
1945}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001946#endif
1947
1948static int
1949decode_readlink(struct tcb *tcp, int offset)
1950{
1951 if (entering(tcp)) {
1952 printpath(tcp, tcp->u_arg[offset]);
1953 tprintf(", ");
1954 } else {
1955 if (syserror(tcp))
1956 tprintf("%#lx", tcp->u_arg[offset + 1]);
1957 else
1958 printpathn(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1959 tprintf(", %lu", tcp->u_arg[offset + 2]);
1960 }
1961 return 0;
1962}
1963
1964int
1965sys_readlink(struct tcb *tcp)
1966{
1967 return decode_readlink(tcp, 0);
1968}
1969
1970#ifdef LINUX
1971int
1972sys_readlinkat(struct tcb *tcp)
1973{
1974 if (entering(tcp))
1975 print_dirfd(tcp->u_arg[0]);
1976 return decode_readlink(tcp, 1);
1977}
1978#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001979
1980int
1981sys_rename(tcp)
1982struct tcb *tcp;
1983{
1984 if (entering(tcp)) {
1985 printpath(tcp, tcp->u_arg[0]);
1986 tprintf(", ");
1987 printpath(tcp, tcp->u_arg[1]);
1988 }
1989 return 0;
1990}
1991
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001992#ifdef LINUX
1993int
1994sys_renameat(struct tcb *tcp)
1995{
1996 if (entering(tcp)) {
1997 print_dirfd(tcp->u_arg[0]);
1998 printpath(tcp, tcp->u_arg[1]);
1999 tprintf(", ");
2000 print_dirfd(tcp->u_arg[2]);
2001 printpath(tcp, tcp->u_arg[3]);
2002 }
2003 return 0;
2004}
2005#endif
2006
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002007int
2008sys_chown(tcp)
2009struct tcb *tcp;
2010{
2011 if (entering(tcp)) {
2012 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002013 printuid(", ", tcp->u_arg[1]);
2014 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002015 }
2016 return 0;
2017}
2018
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002019#ifdef LINUX
2020int
2021sys_fchownat(struct tcb *tcp)
2022{
2023 if (entering(tcp)) {
2024 print_dirfd(tcp->u_arg[0]);
2025 printpath(tcp, tcp->u_arg[1]);
2026 printuid(", ", tcp->u_arg[2]);
2027 printuid(", ", tcp->u_arg[3]);
2028 tprintf(", ");
2029 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
2030 }
2031 return 0;
2032}
2033#endif
2034
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002035int
2036sys_fchown(tcp)
2037struct tcb *tcp;
2038{
2039 if (entering(tcp)) {
Roland McGrath6bc12202003-11-13 22:32:27 +00002040 tprintf("%ld", tcp->u_arg[0]);
2041 printuid(", ", tcp->u_arg[1]);
2042 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002043 }
2044 return 0;
2045}
2046
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002047static int
2048decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002049{
2050 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002051 printpath(tcp, tcp->u_arg[offset]);
2052 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002053 }
2054 return 0;
2055}
2056
2057int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002058sys_chmod(struct tcb *tcp)
2059{
2060 return decode_chmod(tcp, 0);
2061}
2062
2063#ifdef LINUX
2064int
2065sys_fchmodat(struct tcb *tcp)
2066{
2067 if (entering(tcp))
2068 print_dirfd(tcp->u_arg[0]);
2069 return decode_chmod(tcp, 1);
2070}
2071#endif
2072
2073int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002074sys_fchmod(tcp)
2075struct tcb *tcp;
2076{
2077 if (entering(tcp)) {
2078 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
2079 }
2080 return 0;
2081}
2082
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002083#ifdef ALPHA
2084int
2085sys_osf_utimes(tcp)
2086struct tcb *tcp;
2087{
2088 if (entering(tcp)) {
2089 printpath(tcp, tcp->u_arg[0]);
2090 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002091 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002092 }
2093 return 0;
2094}
2095#endif
2096
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002097static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002098decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002099{
2100 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002101 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002102 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002103 if (tcp->u_arg[offset + 1] == 0)
2104 tprintf("NULL");
2105 else {
2106 tprintf("{");
2107 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2108 BITNESS_CURRENT, special);
2109 tprintf(", ");
2110 printtv_bitness(tcp, tcp->u_arg[offset + 1]
2111 + sizeof (struct timeval),
2112 BITNESS_CURRENT, special);
2113 tprintf("}");
2114 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002115 }
2116 return 0;
2117}
2118
2119int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002120sys_utimes(struct tcb *tcp)
2121{
Roland McGrath6afc5652007-07-24 01:57:11 +00002122 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002123}
2124
2125#ifdef LINUX
2126int
2127sys_futimesat(struct tcb *tcp)
2128{
2129 if (entering(tcp))
2130 print_dirfd(tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002131 return decode_utimes(tcp, 1, 0);
2132}
2133
2134int
2135sys_utimensat(struct tcb *tcp)
2136{
2137 if (entering(tcp)) {
2138 print_dirfd(tcp->u_arg[0]);
2139 decode_utimes(tcp, 1, 1);
2140 tprintf(", ");
2141 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2142 }
2143 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002144}
2145#endif
2146
2147int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002148sys_utime(tcp)
2149struct tcb *tcp;
2150{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002151 union {
2152 long utl[2];
2153 int uti[2];
2154 } u;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002155
2156 if (entering(tcp)) {
2157 printpath(tcp, tcp->u_arg[0]);
2158 tprintf(", ");
2159 if (!tcp->u_arg[1])
2160 tprintf("NULL");
2161 else if (!verbose(tcp))
2162 tprintf("%#lx", tcp->u_arg[1]);
Roland McGrath7e9817c2007-07-05 20:31:58 +00002163 else if (umoven(tcp, tcp->u_arg[1],
2164 2 * personality_wordsize[current_personality],
2165 (char *) &u) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002166 tprintf("[?, ?]");
Roland McGrath7e9817c2007-07-05 20:31:58 +00002167 else if (personality_wordsize[current_personality]
2168 == sizeof u.utl[0]) {
2169 tprintf("[%s,", sprinttime(u.utl[0]));
2170 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002171 }
Roland McGrath7e9817c2007-07-05 20:31:58 +00002172 else if (personality_wordsize[current_personality]
2173 == sizeof u.uti[0]) {
2174 tprintf("[%s,", sprinttime(u.uti[0]));
2175 tprintf(" %s]", sprinttime(u.uti[1]));
2176 }
2177 else
2178 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002179 }
2180 return 0;
2181}
2182
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002183static int
2184decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002185{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002186 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002187
2188 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002189 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002190 tprintf(", %s", sprintmode(mode));
2191 switch (mode & S_IFMT) {
2192 case S_IFCHR: case S_IFBLK:
2193#ifdef LINUXSPARC
2194 if (current_personality == 1)
2195 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002196 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2197 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002198 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002199#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002200 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002201 (unsigned long) major(tcp->u_arg[offset + 2]),
2202 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002203 break;
2204 default:
2205 break;
2206 }
2207 }
2208 return 0;
2209}
2210
2211int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002212sys_mknod(struct tcb *tcp)
2213{
2214 return decode_mknod(tcp, 0);
2215}
2216
2217#ifdef LINUX
2218int
2219sys_mknodat(struct tcb *tcp)
2220{
2221 if (entering(tcp))
2222 print_dirfd(tcp->u_arg[0]);
2223 return decode_mknod(tcp, 1);
2224}
2225#endif
2226
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002227#ifdef FREEBSD
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002228int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002229sys_mkfifo(tcp)
2230struct tcb *tcp;
2231{
2232 if (entering(tcp)) {
2233 printpath(tcp, tcp->u_arg[0]);
2234 tprintf(", %#lo", tcp->u_arg[1]);
2235 }
2236 return 0;
2237}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002238#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002239
2240int
2241sys_fsync(tcp)
2242struct tcb *tcp;
2243{
2244 if (entering(tcp)) {
2245 tprintf("%ld", tcp->u_arg[0]);
2246 }
2247 return 0;
2248}
2249
Michal Ludvig53b320f2002-09-23 13:30:09 +00002250#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002251
2252static void
2253printdir(tcp, addr)
2254struct tcb *tcp;
2255long addr;
2256{
2257 struct dirent d;
2258
2259 if (!verbose(tcp)) {
2260 tprintf("%#lx", addr);
2261 return;
2262 }
2263 if (umove(tcp, addr, &d) < 0) {
2264 tprintf("{...}");
2265 return;
2266 }
2267 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002268 tprintf("d_name=");
2269 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2270 tprintf("}");
2271}
2272
2273int
2274sys_readdir(tcp)
2275struct tcb *tcp;
2276{
2277 if (entering(tcp)) {
2278 tprintf("%lu, ", tcp->u_arg[0]);
2279 } else {
2280 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2281 tprintf("%#lx", tcp->u_arg[1]);
2282 else
2283 printdir(tcp, tcp->u_arg[1]);
2284 /* Not much point in printing this out, it is always 1. */
2285 if (tcp->u_arg[2] != 1)
2286 tprintf(", %lu", tcp->u_arg[2]);
2287 }
2288 return 0;
2289}
2290
Michal Ludvig53b320f2002-09-23 13:30:09 +00002291#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002292
Roland McGrath40542842004-01-13 09:47:49 +00002293#if defined FREEBSD || defined LINUX
Roland McGratha4d48532005-06-08 20:45:28 +00002294static const struct xlat direnttypes[] = {
Roland McGrath40542842004-01-13 09:47:49 +00002295 { DT_UNKNOWN, "DT_UNKNOWN" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002296 { DT_FIFO, "DT_FIFO" },
2297 { DT_CHR, "DT_CHR" },
2298 { DT_DIR, "DT_DIR" },
2299 { DT_BLK, "DT_BLK" },
2300 { DT_REG, "DT_REG" },
2301 { DT_LNK, "DT_LNK" },
2302 { DT_SOCK, "DT_SOCK" },
2303 { DT_WHT, "DT_WHT" },
2304 { 0, NULL },
2305};
2306
2307#endif
2308
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002309int
2310sys_getdents(tcp)
2311struct tcb *tcp;
2312{
2313 int i, len, dents = 0;
2314 char *buf;
2315
2316 if (entering(tcp)) {
2317 tprintf("%lu, ", tcp->u_arg[0]);
2318 return 0;
2319 }
2320 if (syserror(tcp) || !verbose(tcp)) {
2321 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2322 return 0;
2323 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002324 len = tcp->u_rval;
2325 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002326 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2327 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002328 return 0;
2329 }
2330 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002331 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002332 free(buf);
2333 return 0;
2334 }
2335 if (!abbrev(tcp))
2336 tprintf("{");
2337 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002338 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002339#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002340 if (!abbrev(tcp)) {
2341 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2342 i ? " " : "", d->d_ino, d->d_off);
2343 tprintf("d_reclen=%u, d_name=\"%s\"}",
2344 d->d_reclen, d->d_name);
2345 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002346#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002347#ifdef SVR4
2348 if (!abbrev(tcp)) {
2349 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002350 i ? " " : "",
2351 (unsigned long) d->d_ino,
2352 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002353 tprintf("d_reclen=%u, d_name=\"%s\"}",
2354 d->d_reclen, d->d_name);
2355 }
2356#endif /* SVR4 */
2357#ifdef SUNOS4
2358 if (!abbrev(tcp)) {
2359 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2360 i ? " " : "", d->d_off, d->d_fileno,
2361 d->d_reclen);
2362 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2363 d->d_namlen, d->d_namlen, d->d_name);
2364 }
2365#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002366#ifdef FREEBSD
2367 if (!abbrev(tcp)) {
2368 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2369 i ? " " : "", d->d_fileno, d->d_reclen);
2370 printxval(direnttypes, d->d_type, "DT_???");
2371 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2372 d->d_namlen, d->d_namlen, d->d_name);
2373 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002374#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002375 if (!d->d_reclen) {
2376 tprintf("/* d_reclen == 0, problem here */");
2377 break;
2378 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002379 i += d->d_reclen;
2380 dents++;
2381 }
2382 if (!abbrev(tcp))
2383 tprintf("}");
2384 else
2385 tprintf("/* %u entries */", dents);
2386 tprintf(", %lu", tcp->u_arg[2]);
2387 free(buf);
2388 return 0;
2389}
2390
John Hughesbdf48f52001-03-06 15:08:09 +00002391
2392#if _LFS64_LARGEFILE
2393int
2394sys_getdents64(tcp)
2395struct tcb *tcp;
2396{
2397 int i, len, dents = 0;
2398 char *buf;
2399
2400 if (entering(tcp)) {
2401 tprintf("%lu, ", tcp->u_arg[0]);
2402 return 0;
2403 }
2404 if (syserror(tcp) || !verbose(tcp)) {
2405 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2406 return 0;
2407 }
2408 len = tcp->u_rval;
2409 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002410 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2411 fprintf(stderr, "out of memory\n");
John Hughesbdf48f52001-03-06 15:08:09 +00002412 return 0;
2413 }
2414 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002415 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002416 free(buf);
2417 return 0;
2418 }
2419 if (!abbrev(tcp))
2420 tprintf("{");
2421 for (i = 0; i < len;) {
2422 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002423#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002424 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002425 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002426 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002427 d->d_ino,
2428 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002429#ifdef LINUX
2430 tprintf("d_type=");
2431 printxval(direnttypes, d->d_type, "DT_???");
2432 tprintf(", ");
2433#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002434 tprintf("d_reclen=%u, d_name=\"%s\"}",
2435 d->d_reclen, d->d_name);
2436 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002437#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002438#ifdef SUNOS4
2439 if (!abbrev(tcp)) {
2440 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2441 i ? " " : "", d->d_off, d->d_fileno,
2442 d->d_reclen);
2443 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2444 d->d_namlen, d->d_namlen, d->d_name);
2445 }
2446#endif /* SUNOS4 */
2447 i += d->d_reclen;
2448 dents++;
2449 }
2450 if (!abbrev(tcp))
2451 tprintf("}");
2452 else
2453 tprintf("/* %u entries */", dents);
2454 tprintf(", %lu", tcp->u_arg[2]);
2455 free(buf);
2456 return 0;
2457}
2458#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002459
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002460#ifdef FREEBSD
2461int
2462sys_getdirentries(tcp)
2463struct tcb * tcp;
2464{
2465 int i, len, dents = 0;
2466 long basep;
2467 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002468
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002469 if (entering(tcp)) {
2470 tprintf("%lu, ", tcp->u_arg[0]);
2471 return 0;
2472 }
2473 if (syserror(tcp) || !verbose(tcp)) {
2474 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2475 return 0;
2476 }
2477 len = tcp->u_rval;
2478 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002479 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2480 fprintf(stderr, "out of memory\n");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002481 return 0;
2482 }
2483 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002484 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002485 free(buf);
2486 return 0;
2487 }
2488 if (!abbrev(tcp))
2489 tprintf("{");
2490 for (i = 0; i < len;) {
2491 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2492 if (!abbrev(tcp)) {
2493 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2494 i ? " " : "", d->d_fileno, d->d_reclen);
2495 printxval(direnttypes, d->d_type, "DT_???");
2496 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2497 d->d_namlen, d->d_namlen, d->d_name);
2498 }
2499 i += d->d_reclen;
2500 dents++;
2501 }
2502 if (!abbrev(tcp))
2503 tprintf("}");
2504 else
2505 tprintf("/* %u entries */", dents);
2506 free(buf);
2507 tprintf(", %lu", tcp->u_arg[2]);
2508 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2509 tprintf(", %#lx", tcp->u_arg[3]);
2510 else
2511 tprintf(", [%lu]", basep);
2512 return 0;
2513}
2514#endif
2515
Michal Ludvig53b320f2002-09-23 13:30:09 +00002516#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002517int
2518sys_getcwd(tcp)
2519struct tcb *tcp;
2520{
2521 if (exiting(tcp)) {
2522 if (syserror(tcp))
2523 tprintf("%#lx", tcp->u_arg[0]);
2524 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002525 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002526 tprintf(", %lu", tcp->u_arg[1]);
2527 }
2528 return 0;
2529}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002530#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002531
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002532#ifdef FREEBSD
2533int
2534sys___getcwd(tcp)
2535struct tcb *tcp;
2536{
2537 if (exiting(tcp)) {
2538 if (syserror(tcp))
2539 tprintf("%#lx", tcp->u_arg[0]);
2540 else
2541 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2542 tprintf(", %lu", tcp->u_arg[1]);
2543 }
2544 return 0;
2545}
2546#endif
2547
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002548#ifdef HAVE_SYS_ASYNCH_H
2549
2550int
2551sys_aioread(tcp)
2552struct tcb *tcp;
2553{
2554 struct aio_result_t res;
2555
2556 if (entering(tcp)) {
2557 tprintf("%lu, ", tcp->u_arg[0]);
2558 } else {
2559 if (syserror(tcp))
2560 tprintf("%#lx", tcp->u_arg[1]);
2561 else
2562 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2563 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2564 printxval(whence, tcp->u_arg[4], "L_???");
2565 if (syserror(tcp) || tcp->u_arg[5] == 0
2566 || umove(tcp, tcp->u_arg[5], &res) < 0)
2567 tprintf(", %#lx", tcp->u_arg[5]);
2568 else
2569 tprintf(", {aio_return %d aio_errno %d}",
2570 res.aio_return, res.aio_errno);
2571 }
2572 return 0;
2573}
2574
2575int
2576sys_aiowrite(tcp)
2577struct tcb *tcp;
2578{
2579 struct aio_result_t res;
2580
2581 if (entering(tcp)) {
2582 tprintf("%lu, ", tcp->u_arg[0]);
2583 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2584 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2585 printxval(whence, tcp->u_arg[4], "L_???");
2586 }
2587 else {
2588 if (tcp->u_arg[5] == 0)
2589 tprintf(", NULL");
2590 else if (syserror(tcp)
2591 || umove(tcp, tcp->u_arg[5], &res) < 0)
2592 tprintf(", %#lx", tcp->u_arg[5]);
2593 else
2594 tprintf(", {aio_return %d aio_errno %d}",
2595 res.aio_return, res.aio_errno);
2596 }
2597 return 0;
2598}
2599
2600int
2601sys_aiowait(tcp)
2602struct tcb *tcp;
2603{
2604 if (entering(tcp))
2605 printtv(tcp, tcp->u_arg[0]);
2606 return 0;
2607}
2608
2609int
2610sys_aiocancel(tcp)
2611struct tcb *tcp;
2612{
2613 struct aio_result_t res;
2614
2615 if (exiting(tcp)) {
2616 if (tcp->u_arg[0] == 0)
2617 tprintf("NULL");
2618 else if (syserror(tcp)
2619 || umove(tcp, tcp->u_arg[0], &res) < 0)
2620 tprintf("%#lx", tcp->u_arg[0]);
2621 else
2622 tprintf("{aio_return %d aio_errno %d}",
2623 res.aio_return, res.aio_errno);
2624 }
2625 return 0;
2626}
2627
2628#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002629
Roland McGratha4d48532005-06-08 20:45:28 +00002630static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002631#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002632 { XATTR_CREATE, "XATTR_CREATE" },
2633 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002634#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002635 { 0, NULL }
2636};
2637
Roland McGrath3292e222004-08-31 06:30:48 +00002638static void
2639print_xattr_val(tcp, failed, arg, insize, size)
2640struct tcb *tcp;
2641int failed;
2642unsigned long arg;
Roland McGrathaa524c82005-06-01 19:22:06 +00002643unsigned long insize, size;
Roland McGrath3292e222004-08-31 06:30:48 +00002644{
Roland McGrath883567c2005-02-02 03:38:32 +00002645 if (!failed) {
Roland McGrathaa524c82005-06-01 19:22:06 +00002646 unsigned long capacity = 4 * size + 1;
2647 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
Roland McGrath883567c2005-02-02 03:38:32 +00002648 if (buf == NULL || /* probably a bogus size argument */
Roland McGrathf7746422005-03-01 23:02:32 +00002649 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
Roland McGrath883567c2005-02-02 03:38:32 +00002650 failed = 1;
2651 }
2652 else {
2653 unsigned char *out = buf;
2654 unsigned char *in = &buf[3 * size];
2655 size_t i;
2656 for (i = 0; i < size; ++i)
2657 if (isprint(in[i]))
2658 *out++ = in[i];
2659 else {
Roland McGrath3292e222004-08-31 06:30:48 +00002660#define tohex(n) "0123456789abcdef"[n]
Roland McGrath883567c2005-02-02 03:38:32 +00002661 *out++ = '\\';
2662 *out++ = 'x';
2663 *out++ = tohex(in[i] / 16);
2664 *out++ = tohex(in[i] % 16);
2665 }
2666 /* Don't print terminating NUL if there is one. */
Dmitry V. Levin504eb0b2006-10-11 22:58:31 +00002667 if (i > 0 && in[i - 1] == '\0')
Roland McGrath883567c2005-02-02 03:38:32 +00002668 out -= 4;
2669 *out = '\0';
2670 tprintf(", \"%s\", %ld", buf, insize);
2671 }
2672 free(buf);
2673 }
2674 if (failed)
2675 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002676}
2677
Roland McGrath186c5ac2002-12-15 23:58:23 +00002678int
2679sys_setxattr(tcp)
2680struct tcb *tcp;
2681{
2682 if (entering(tcp)) {
2683 printpath(tcp, tcp->u_arg[0]);
2684 tprintf(", ");
2685 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002686 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2687 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002688 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002689 }
2690 return 0;
2691}
2692
2693int
2694sys_fsetxattr(tcp)
2695struct tcb *tcp;
2696{
2697 if (entering(tcp)) {
2698 tprintf("%ld, ", tcp->u_arg[0]);
2699 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002700 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2701 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002702 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002703 }
2704 return 0;
2705}
2706
2707int
2708sys_getxattr(tcp)
2709struct tcb *tcp;
2710{
2711 if (entering(tcp)) {
2712 printpath(tcp, tcp->u_arg[0]);
2713 tprintf(", ");
2714 printstr(tcp, tcp->u_arg[1], -1);
2715 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002716 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2717 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002718 }
2719 return 0;
2720}
2721
2722int
2723sys_fgetxattr(tcp)
2724struct tcb *tcp;
2725{
2726 if (entering(tcp)) {
2727 tprintf("%ld, ", tcp->u_arg[0]);
2728 printstr(tcp, tcp->u_arg[1], -1);
2729 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002730 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2731 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002732 }
2733 return 0;
2734}
2735
2736int
2737sys_listxattr(tcp)
2738struct tcb *tcp;
2739{
2740 if (entering(tcp)) {
2741 printpath(tcp, tcp->u_arg[0]);
2742 } else {
2743 /* XXX Print value in format */
2744 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2745 }
2746 return 0;
2747}
2748
2749int
2750sys_flistxattr(tcp)
2751struct tcb *tcp;
2752{
2753 if (entering(tcp)) {
2754 tprintf("%ld", tcp->u_arg[0]);
2755 } else {
2756 /* XXX Print value in format */
2757 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2758 }
2759 return 0;
2760}
2761
2762int
2763sys_removexattr(tcp)
2764struct tcb *tcp;
2765{
2766 if (entering(tcp)) {
2767 printpath(tcp, tcp->u_arg[0]);
2768 tprintf(", ");
2769 printstr(tcp, tcp->u_arg[1], -1);
2770 }
2771 return 0;
2772}
2773
2774int
2775sys_fremovexattr(tcp)
2776struct tcb *tcp;
2777{
2778 if (entering(tcp)) {
2779 tprintf("%ld, ", tcp->u_arg[0]);
2780 printstr(tcp, tcp->u_arg[1], -1);
2781 }
2782 return 0;
2783}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002784
2785
2786static const struct xlat advise[] = {
2787 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2788 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2789 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2790 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2791 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2792 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2793 { 0, NULL }
2794};
2795
2796
Roland McGrathe27ed342004-10-20 02:24:19 +00002797#ifdef LINUX
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002798int
2799sys_fadvise64(tcp)
2800struct tcb *tcp;
2801{
2802 if (entering(tcp)) {
2803 tprintf("%ld, %lld, %ld, ",
2804 tcp->u_arg[0],
2805# if defined IA64 || defined X86_64 || defined ALPHA
2806 (long long int) tcp->u_arg[1], tcp->u_arg[2]);
2807 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2808#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002809 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
2810 printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002811#endif
2812 }
2813 return 0;
2814}
2815#endif
2816
2817
2818int
2819sys_fadvise64_64(tcp)
2820struct tcb *tcp;
2821{
2822 if (entering(tcp)) {
2823 tprintf("%ld, %lld, %lld, ",
2824 tcp->u_arg[0],
2825# if defined IA64 || defined X86_64 || defined ALPHA
2826 (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
2827 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2828#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002829 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
2830 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002831 printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
2832#endif
2833 }
2834 return 0;
2835}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002836
2837#ifdef LINUX
2838static const struct xlat inotify_modes[] = {
2839 { 0x00000001, "IN_ACCESS" },
2840 { 0x00000002, "IN_MODIFY" },
2841 { 0x00000004, "IN_ATTRIB" },
2842 { 0x00000008, "IN_CLOSE_WRITE" },
2843 { 0x00000010, "IN_CLOSE_NOWRITE" },
2844 { 0x00000020, "IN_OPEN" },
2845 { 0x00000040, "IN_MOVED_FROM" },
2846 { 0x00000080, "IN_MOVED_TO" },
2847 { 0x00000100, "IN_CREATE" },
2848 { 0x00000200, "IN_DELETE" },
2849 { 0x00000400, "IN_DELETE_SELF" },
2850 { 0x00000800, "IN_MOVE_SELF" },
2851 { 0x00002000, "IN_UNMOUNT" },
2852 { 0x00004000, "IN_Q_OVERFLOW" },
2853 { 0x00008000, "IN_IGNORED" },
2854 { 0x01000000, "IN_ONLYDIR" },
2855 { 0x02000000, "IN_DONT_FOLLOW" },
2856 { 0x20000000, "IN_MASK_ADD" },
2857 { 0x40000000, "IN_ISDIR" },
2858 { 0x80000000, "IN_ONESHOT" }
2859};
2860
2861int
2862sys_inotify_add_watch(struct tcb *tcp)
2863{
2864 if (entering(tcp)) {
2865 tprintf("%ld, ", tcp->u_arg[0]);
2866 printpath(tcp, tcp->u_arg[1]);
2867 tprintf(", ");
2868 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2869 }
2870 return 0;
2871}
2872
2873int
2874sys_inotify_rm_watch(struct tcb *tcp)
2875{
2876 if (entering(tcp)) {
2877 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
2878 }
2879 return 0;
2880}
2881#endif