blob: 7c17063ff40d1289b2c5805889c825bdec07db17 [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};
1187
1188int
1189sys_newfstatat(struct tcb *tcp)
1190{
1191 if (entering(tcp)) {
1192 print_dirfd(tcp->u_arg[0]);
1193 printpath(tcp, tcp->u_arg[1]);
1194 tprintf(", ");
1195 } else {
Roland McGrath359c8ed2007-07-05 19:01:17 +00001196#if defined HAVE_STAT64 && !(defined POWERPC && defined __powerpc64__)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001197 printstat64(tcp, tcp->u_arg[2]);
1198#else
1199 printstat(tcp, tcp->u_arg[2]);
1200#endif
1201 tprintf(", ");
1202 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1203 }
1204 return 0;
1205}
1206#endif
1207
Roland McGrath79db8af2003-06-27 21:20:09 +00001208#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001209int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001210sys_oldstat(tcp)
1211struct tcb *tcp;
1212{
1213 if (entering(tcp)) {
1214 printpath(tcp, tcp->u_arg[0]);
1215 tprintf(", ");
1216 } else {
1217 printoldstat(tcp, tcp->u_arg[1]);
1218 }
1219 return 0;
1220}
Roland McGrath79db8af2003-06-27 21:20:09 +00001221#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001222
John Hughes70623be2001-03-08 13:59:00 +00001223#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001224int
1225sys_fstat(tcp)
1226struct tcb *tcp;
1227{
1228 if (entering(tcp))
1229 tprintf("%ld, ", tcp->u_arg[0]);
1230 else {
1231 printstat(tcp, tcp->u_arg[1]);
1232 }
1233 return 0;
1234}
John Hughesb8c9f772001-03-07 16:53:07 +00001235#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001236
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001237int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001238sys_fstat64(tcp)
1239struct tcb *tcp;
1240{
1241#ifdef HAVE_STAT64
1242 if (entering(tcp))
1243 tprintf("%ld, ", tcp->u_arg[0]);
1244 else {
1245 printstat64(tcp, tcp->u_arg[1]);
1246 }
1247 return 0;
1248#else
1249 return printargs(tcp);
1250#endif
1251}
1252
Roland McGrath79db8af2003-06-27 21:20:09 +00001253#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001254int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001255sys_oldfstat(tcp)
1256struct tcb *tcp;
1257{
1258 if (entering(tcp))
1259 tprintf("%ld, ", tcp->u_arg[0]);
1260 else {
1261 printoldstat(tcp, tcp->u_arg[1]);
1262 }
1263 return 0;
1264}
Roland McGrath79db8af2003-06-27 21:20:09 +00001265#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001266
John Hughes70623be2001-03-08 13:59:00 +00001267#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001268int
1269sys_lstat(tcp)
1270struct tcb *tcp;
1271{
1272 if (entering(tcp)) {
1273 printpath(tcp, tcp->u_arg[0]);
1274 tprintf(", ");
1275 } else {
1276 printstat(tcp, tcp->u_arg[1]);
1277 }
1278 return 0;
1279}
John Hughesb8c9f772001-03-07 16:53:07 +00001280#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001281
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001282int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001283sys_lstat64(tcp)
1284struct tcb *tcp;
1285{
1286#ifdef HAVE_STAT64
1287 if (entering(tcp)) {
1288 printpath(tcp, tcp->u_arg[0]);
1289 tprintf(", ");
1290 } else {
1291 printstat64(tcp, tcp->u_arg[1]);
1292 }
1293 return 0;
1294#else
1295 return printargs(tcp);
1296#endif
1297}
1298
Roland McGrath79db8af2003-06-27 21:20:09 +00001299#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001300int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001301sys_oldlstat(tcp)
1302struct tcb *tcp;
1303{
1304 if (entering(tcp)) {
1305 printpath(tcp, tcp->u_arg[0]);
1306 tprintf(", ");
1307 } else {
1308 printoldstat(tcp, tcp->u_arg[1]);
1309 }
1310 return 0;
1311}
Roland McGrath79db8af2003-06-27 21:20:09 +00001312#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001313
1314
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001315#if defined(SVR4) || defined(LINUXSPARC)
1316
1317int
1318sys_xstat(tcp)
1319struct tcb *tcp;
1320{
1321 if (entering(tcp)) {
1322 tprintf("%ld, ", tcp->u_arg[0]);
1323 printpath(tcp, tcp->u_arg[1]);
1324 tprintf(", ");
1325 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001326#ifdef _STAT64_VER
1327 if (tcp->u_arg[0] == _STAT64_VER)
1328 printstat64 (tcp, tcp->u_arg[2]);
1329 else
1330#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001331 printstat(tcp, tcp->u_arg[2]);
1332 }
1333 return 0;
1334}
1335
1336int
1337sys_fxstat(tcp)
1338struct tcb *tcp;
1339{
1340 if (entering(tcp))
1341 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1342 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001343#ifdef _STAT64_VER
1344 if (tcp->u_arg[0] == _STAT64_VER)
1345 printstat64 (tcp, tcp->u_arg[2]);
1346 else
1347#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001348 printstat(tcp, tcp->u_arg[2]);
1349 }
1350 return 0;
1351}
1352
1353int
1354sys_lxstat(tcp)
1355struct tcb *tcp;
1356{
1357 if (entering(tcp)) {
1358 tprintf("%ld, ", tcp->u_arg[0]);
1359 printpath(tcp, tcp->u_arg[1]);
1360 tprintf(", ");
1361 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001362#ifdef _STAT64_VER
1363 if (tcp->u_arg[0] == _STAT64_VER)
1364 printstat64 (tcp, tcp->u_arg[2]);
1365 else
1366#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001367 printstat(tcp, tcp->u_arg[2]);
1368 }
1369 return 0;
1370}
1371
1372int
1373sys_xmknod(tcp)
1374struct tcb *tcp;
1375{
1376 int mode = tcp->u_arg[2];
1377
1378 if (entering(tcp)) {
1379 tprintf("%ld, ", tcp->u_arg[0]);
1380 printpath(tcp, tcp->u_arg[1]);
1381 tprintf(", %s", sprintmode(mode));
1382 switch (mode & S_IFMT) {
1383 case S_IFCHR: case S_IFBLK:
1384#ifdef LINUXSPARC
1385 tprintf(", makedev(%lu, %lu)",
1386 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1387 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001388#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001389 tprintf(", makedev(%lu, %lu)",
1390 (unsigned long) major(tcp->u_arg[3]),
1391 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001392#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001393 break;
1394 default:
1395 break;
1396 }
1397 }
1398 return 0;
1399}
1400
Wichert Akkerman8829a551999-06-11 13:18:40 +00001401#ifdef HAVE_SYS_ACL_H
1402
1403#include <sys/acl.h>
1404
Roland McGratha4d48532005-06-08 20:45:28 +00001405static const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001406#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001407 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001408#endif
1409#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001410 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001411#endif
1412#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001413 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001414#endif
1415#ifdef ACL_GET
1416 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001417#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001418#ifdef ACL_SET
1419 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001420#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001421#ifdef ACL_CNT
1422 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001423#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001424 { 0, NULL },
1425};
1426
1427int
1428sys_acl(tcp)
1429struct tcb *tcp;
1430{
1431 if (entering(tcp)) {
1432 printpath(tcp, tcp->u_arg[0]);
1433 tprintf(", ");
1434 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1435 tprintf(", %ld", tcp->u_arg[2]);
1436 /*
1437 * FIXME - dump out the list of aclent_t's pointed to
1438 * by "tcp->u_arg[3]" if it's not NULL.
1439 */
1440 if (tcp->u_arg[3])
1441 tprintf(", %#lx", tcp->u_arg[3]);
1442 else
1443 tprintf(", NULL");
1444 }
1445 return 0;
1446}
1447
1448
1449int
1450sys_facl(tcp)
1451struct tcb *tcp;
1452{
1453 if (entering(tcp)) {
1454 tprintf("%ld, ", tcp->u_arg[0]);
1455 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1456 tprintf(", %ld", tcp->u_arg[2]);
1457 /*
1458 * FIXME - dump out the list of aclent_t's pointed to
1459 * by "tcp->u_arg[3]" if it's not NULL.
1460 */
1461 if (tcp->u_arg[3])
1462 tprintf(", %#lx", tcp->u_arg[3]);
1463 else
1464 tprintf(", NULL");
1465 }
1466 return 0;
1467}
1468
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001469
Roland McGratha4d48532005-06-08 20:45:28 +00001470static const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001471#ifdef IPC_SHM
1472 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001473#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001474#ifdef IPC_SEM
1475 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001476#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001477#ifdef IPC_MSG
1478 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001479#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001480 { 0, NULL },
1481};
1482
1483
1484int
1485sys_aclipc(tcp)
1486struct tcb *tcp;
1487{
1488 if (entering(tcp)) {
1489 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1490 tprintf(", %#lx, ", tcp->u_arg[1]);
1491 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1492 tprintf(", %ld", tcp->u_arg[3]);
1493 /*
1494 * FIXME - dump out the list of aclent_t's pointed to
1495 * by "tcp->u_arg[4]" if it's not NULL.
1496 */
1497 if (tcp->u_arg[4])
1498 tprintf(", %#lx", tcp->u_arg[4]);
1499 else
1500 tprintf(", NULL");
1501 }
1502 return 0;
1503}
1504
1505
1506
Wichert Akkerman8829a551999-06-11 13:18:40 +00001507#endif /* HAVE_SYS_ACL_H */
1508
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001509#endif /* SVR4 || LINUXSPARC */
1510
Michal Ludvig53b320f2002-09-23 13:30:09 +00001511#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001512
Roland McGrathd9f816f2004-09-04 03:39:20 +00001513static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001514 { 0x73757245, "CODA_SUPER_MAGIC" },
1515 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1516 { 0x1373, "DEVFS_SUPER_MAGIC" },
1517 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1518 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001519 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1520 { 0xef53, "EXT2_SUPER_MAGIC" },
1521 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001522 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001523 { 0x9660, "ISOFS_SUPER_MAGIC" },
1524 { 0x137f, "MINIX_SUPER_MAGIC" },
1525 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001526 { 0x2468, "MINIX2_SUPER_MAGIC" },
1527 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001528 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001529 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001530 { 0x6969, "NFS_SUPER_MAGIC" },
1531 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001532 { 0x002f, "QNX4_SUPER_MAGIC" },
1533 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1534 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1535 { 0x517b, "SMB_SUPER_MAGIC" },
1536 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1537 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1538 { 0x00011954, "UFS_MAGIC" },
1539 { 0x54190100, "UFS_CIGAM" },
1540 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001541 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001542 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001543 { 0, NULL },
1544};
1545
Michal Ludvig53b320f2002-09-23 13:30:09 +00001546#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001547
1548#ifndef SVR4
1549
Roland McGrathf9c49b22004-10-06 22:11:54 +00001550static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001551sprintfstype(magic)
1552int magic;
1553{
1554 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001555#ifdef LINUX
Roland McGrathf9c49b22004-10-06 22:11:54 +00001556 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001557
1558 s = xlookup(fsmagic, magic);
1559 if (s) {
1560 sprintf(buf, "\"%s\"", s);
1561 return buf;
1562 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001563#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001564 sprintf(buf, "%#x", magic);
1565 return buf;
1566}
1567
1568static void
1569printstatfs(tcp, addr)
1570struct tcb *tcp;
1571long addr;
1572{
1573 struct statfs statbuf;
1574
1575 if (syserror(tcp) || !verbose(tcp)) {
1576 tprintf("%#lx", addr);
1577 return;
1578 }
1579 if (umove(tcp, addr, &statbuf) < 0) {
1580 tprintf("{...}");
1581 return;
1582 }
1583#ifdef ALPHA
1584
1585 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1586 sprintfstype(statbuf.f_type),
1587 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001588 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1589 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1590 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1591 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001592#else /* !ALPHA */
1593 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1594 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001595 (unsigned long)statbuf.f_bsize,
1596 (unsigned long)statbuf.f_blocks,
1597 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001598 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1599 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001600 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001601 (unsigned long)statbuf.f_ffree,
1602 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001603#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001604 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001605#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001606#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001607#ifdef _STATFS_F_FRSIZE
1608 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1609#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001610 tprintf("}");
1611}
1612
1613int
1614sys_statfs(tcp)
1615struct tcb *tcp;
1616{
1617 if (entering(tcp)) {
1618 printpath(tcp, tcp->u_arg[0]);
1619 tprintf(", ");
1620 } else {
1621 printstatfs(tcp, tcp->u_arg[1]);
1622 }
1623 return 0;
1624}
1625
1626int
1627sys_fstatfs(tcp)
1628struct tcb *tcp;
1629{
1630 if (entering(tcp)) {
1631 tprintf("%lu, ", tcp->u_arg[0]);
1632 } else {
1633 printstatfs(tcp, tcp->u_arg[1]);
1634 }
1635 return 0;
1636}
1637
Roland McGrathab147c52003-07-17 09:03:02 +00001638#ifdef LINUX
1639static void
1640printstatfs64(tcp, addr)
1641struct tcb *tcp;
1642long addr;
1643{
1644 struct statfs64 statbuf;
1645
1646 if (syserror(tcp) || !verbose(tcp)) {
1647 tprintf("%#lx", addr);
1648 return;
1649 }
1650 if (umove(tcp, addr, &statbuf) < 0) {
1651 tprintf("{...}");
1652 return;
1653 }
Roland McGrath08738432005-06-03 02:40:39 +00001654 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001655 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001656 (unsigned long long)statbuf.f_bsize,
1657 (unsigned long long)statbuf.f_blocks,
1658 (unsigned long long)statbuf.f_bfree);
1659 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1660 (unsigned long long)statbuf.f_bavail,
1661 (unsigned long long)statbuf.f_files,
1662 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001663 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1664 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001665#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001666 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001667#endif
1668 tprintf("}");
1669}
1670
1671int
1672sys_statfs64(tcp)
1673struct tcb *tcp;
1674{
1675 if (entering(tcp)) {
1676 printpath(tcp, tcp->u_arg[0]);
1677 tprintf(", %lu, ", tcp->u_arg[1]);
1678 } else {
1679 if (tcp->u_arg[1] == sizeof (struct statfs64))
1680 printstatfs64(tcp, tcp->u_arg[2]);
1681 else
1682 tprintf("{???}");
1683 }
1684 return 0;
1685}
1686
1687int
1688sys_fstatfs64(tcp)
1689struct tcb *tcp;
1690{
1691 if (entering(tcp)) {
1692 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1693 } else {
1694 if (tcp->u_arg[1] == sizeof (struct statfs64))
1695 printstatfs64(tcp, tcp->u_arg[2]);
1696 else
1697 tprintf("{???}");
1698 }
1699 return 0;
1700}
1701#endif
1702
Michal Ludvig53b320f2002-09-23 13:30:09 +00001703#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001704
1705int
1706osf_statfs(tcp)
1707struct tcb *tcp;
1708{
1709 if (entering(tcp)) {
1710 printpath(tcp, tcp->u_arg[0]);
1711 tprintf(", ");
1712 } else {
1713 printstatfs(tcp, tcp->u_arg[1]);
1714 tprintf(", %lu", tcp->u_arg[2]);
1715 }
1716 return 0;
1717}
1718
1719int
1720osf_fstatfs(tcp)
1721struct tcb *tcp;
1722{
1723 if (entering(tcp)) {
1724 tprintf("%lu, ", tcp->u_arg[0]);
1725 } else {
1726 printstatfs(tcp, tcp->u_arg[1]);
1727 tprintf(", %lu", tcp->u_arg[2]);
1728 }
1729 return 0;
1730}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001731#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001732
1733#endif /* !SVR4 */
1734
1735#ifdef SUNOS4
1736
1737int
1738sys_ustat(tcp)
1739struct tcb *tcp;
1740{
1741 struct ustat statbuf;
1742
1743 if (entering(tcp)) {
1744 tprintf("makedev(%lu, %lu), ",
1745 (long) major(tcp->u_arg[0]),
1746 (long) minor(tcp->u_arg[0]));
1747 }
1748 else {
1749 if (syserror(tcp) || !verbose(tcp))
1750 tprintf("%#lx", tcp->u_arg[1]);
1751 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1752 tprintf("{...}");
1753 else {
1754 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1755 statbuf.f_tfree, statbuf.f_tinode);
1756 tprintf("f_fname=\"%.*s\", ",
1757 (int) sizeof(statbuf.f_fname),
1758 statbuf.f_fname);
1759 tprintf("f_fpack=\"%.*s\"}",
1760 (int) sizeof(statbuf.f_fpack),
1761 statbuf.f_fpack);
1762 }
1763 }
1764 return 0;
1765}
1766
1767#endif /* SUNOS4 */
1768
Wichert Akkermanc7926982000-04-10 22:22:31 +00001769int
1770sys_pivotroot(tcp)
1771struct tcb *tcp;
1772{
1773 if (entering(tcp)) {
1774 printpath(tcp, tcp->u_arg[0]);
1775 tprintf(", ");
1776 printpath(tcp, tcp->u_arg[1]);
1777 }
1778 return 0;
1779}
1780
1781
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001782/* directory */
1783int
1784sys_chdir(tcp)
1785struct tcb *tcp;
1786{
1787 if (entering(tcp)) {
1788 printpath(tcp, tcp->u_arg[0]);
1789 }
1790 return 0;
1791}
1792
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001793static int
1794decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001795{
1796 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001797 printpath(tcp, tcp->u_arg[offset]);
1798 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001799 }
1800 return 0;
1801}
1802
1803int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001804sys_mkdir(struct tcb *tcp)
1805{
1806 return decode_mkdir(tcp, 0);
1807}
1808
1809#ifdef LINUX
1810int
1811sys_mkdirat(struct tcb *tcp)
1812{
1813 if (entering(tcp))
1814 print_dirfd(tcp->u_arg[0]);
1815 return decode_mkdir(tcp, 1);
1816}
1817#endif
1818
1819int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001820sys_rmdir(tcp)
1821struct tcb *tcp;
1822{
1823 if (entering(tcp)) {
1824 printpath(tcp, tcp->u_arg[0]);
1825 }
1826 return 0;
1827}
1828
1829int
1830sys_fchdir(tcp)
1831struct tcb *tcp;
1832{
1833 if (entering(tcp)) {
1834 tprintf("%ld", tcp->u_arg[0]);
1835 }
1836 return 0;
1837}
1838
1839int
1840sys_chroot(tcp)
1841struct tcb *tcp;
1842{
1843 if (entering(tcp)) {
1844 printpath(tcp, tcp->u_arg[0]);
1845 }
1846 return 0;
1847}
1848
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001849#if defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001850int
1851sys_fchroot(tcp)
1852struct tcb *tcp;
1853{
1854 if (entering(tcp)) {
1855 tprintf("%ld", tcp->u_arg[0]);
1856 }
1857 return 0;
1858}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001859#endif /* SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001860
1861int
1862sys_link(tcp)
1863struct tcb *tcp;
1864{
1865 if (entering(tcp)) {
1866 printpath(tcp, tcp->u_arg[0]);
1867 tprintf(", ");
1868 printpath(tcp, tcp->u_arg[1]);
1869 }
1870 return 0;
1871}
1872
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001873#ifdef LINUX
1874int
1875sys_linkat(struct tcb *tcp)
1876{
1877 if (entering(tcp)) {
1878 print_dirfd(tcp->u_arg[0]);
1879 printpath(tcp, tcp->u_arg[1]);
1880 tprintf(", ");
1881 print_dirfd(tcp->u_arg[2]);
1882 printpath(tcp, tcp->u_arg[3]);
1883 tprintf(", %ld", tcp->u_arg[4]);
1884 }
1885 return 0;
1886}
1887#endif
1888
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001889int
1890sys_unlink(tcp)
1891struct tcb *tcp;
1892{
1893 if (entering(tcp)) {
1894 printpath(tcp, tcp->u_arg[0]);
1895 }
1896 return 0;
1897}
1898
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001899#ifdef LINUX
1900static const struct xlat unlinkatflags[] = {
1901#ifndef AT_REMOVEDIR
1902# define AT_REMOVEDIR 0x200
1903#endif
1904 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1905 { 0, NULL },
1906};
1907
1908int
1909sys_unlinkat(struct tcb *tcp)
1910{
1911 if (entering(tcp)) {
1912 print_dirfd(tcp->u_arg[0]);
1913 printpath(tcp, tcp->u_arg[1]);
1914 tprintf(", ");
1915 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1916 }
1917 return 0;
1918}
1919#endif
1920
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001921int
1922sys_symlink(tcp)
1923struct tcb *tcp;
1924{
1925 if (entering(tcp)) {
1926 printpath(tcp, tcp->u_arg[0]);
1927 tprintf(", ");
1928 printpath(tcp, tcp->u_arg[1]);
1929 }
1930 return 0;
1931}
1932
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001933#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001934int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001935sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001936{
1937 if (entering(tcp)) {
1938 printpath(tcp, tcp->u_arg[0]);
1939 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001940 print_dirfd(tcp->u_arg[1]);
1941 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001942 }
1943 return 0;
1944}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001945#endif
1946
1947static int
1948decode_readlink(struct tcb *tcp, int offset)
1949{
1950 if (entering(tcp)) {
1951 printpath(tcp, tcp->u_arg[offset]);
1952 tprintf(", ");
1953 } else {
1954 if (syserror(tcp))
1955 tprintf("%#lx", tcp->u_arg[offset + 1]);
1956 else
1957 printpathn(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1958 tprintf(", %lu", tcp->u_arg[offset + 2]);
1959 }
1960 return 0;
1961}
1962
1963int
1964sys_readlink(struct tcb *tcp)
1965{
1966 return decode_readlink(tcp, 0);
1967}
1968
1969#ifdef LINUX
1970int
1971sys_readlinkat(struct tcb *tcp)
1972{
1973 if (entering(tcp))
1974 print_dirfd(tcp->u_arg[0]);
1975 return decode_readlink(tcp, 1);
1976}
1977#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001978
1979int
1980sys_rename(tcp)
1981struct tcb *tcp;
1982{
1983 if (entering(tcp)) {
1984 printpath(tcp, tcp->u_arg[0]);
1985 tprintf(", ");
1986 printpath(tcp, tcp->u_arg[1]);
1987 }
1988 return 0;
1989}
1990
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001991#ifdef LINUX
1992int
1993sys_renameat(struct tcb *tcp)
1994{
1995 if (entering(tcp)) {
1996 print_dirfd(tcp->u_arg[0]);
1997 printpath(tcp, tcp->u_arg[1]);
1998 tprintf(", ");
1999 print_dirfd(tcp->u_arg[2]);
2000 printpath(tcp, tcp->u_arg[3]);
2001 }
2002 return 0;
2003}
2004#endif
2005
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002006int
2007sys_chown(tcp)
2008struct tcb *tcp;
2009{
2010 if (entering(tcp)) {
2011 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002012 printuid(", ", tcp->u_arg[1]);
2013 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002014 }
2015 return 0;
2016}
2017
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002018#ifdef LINUX
2019int
2020sys_fchownat(struct tcb *tcp)
2021{
2022 if (entering(tcp)) {
2023 print_dirfd(tcp->u_arg[0]);
2024 printpath(tcp, tcp->u_arg[1]);
2025 printuid(", ", tcp->u_arg[2]);
2026 printuid(", ", tcp->u_arg[3]);
2027 tprintf(", ");
2028 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
2029 }
2030 return 0;
2031}
2032#endif
2033
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002034int
2035sys_fchown(tcp)
2036struct tcb *tcp;
2037{
2038 if (entering(tcp)) {
Roland McGrath6bc12202003-11-13 22:32:27 +00002039 tprintf("%ld", tcp->u_arg[0]);
2040 printuid(", ", tcp->u_arg[1]);
2041 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002042 }
2043 return 0;
2044}
2045
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002046static int
2047decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002048{
2049 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002050 printpath(tcp, tcp->u_arg[offset]);
2051 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002052 }
2053 return 0;
2054}
2055
2056int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002057sys_chmod(struct tcb *tcp)
2058{
2059 return decode_chmod(tcp, 0);
2060}
2061
2062#ifdef LINUX
2063int
2064sys_fchmodat(struct tcb *tcp)
2065{
2066 if (entering(tcp))
2067 print_dirfd(tcp->u_arg[0]);
2068 return decode_chmod(tcp, 1);
2069}
2070#endif
2071
2072int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002073sys_fchmod(tcp)
2074struct tcb *tcp;
2075{
2076 if (entering(tcp)) {
2077 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
2078 }
2079 return 0;
2080}
2081
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002082#ifdef ALPHA
2083int
2084sys_osf_utimes(tcp)
2085struct tcb *tcp;
2086{
2087 if (entering(tcp)) {
2088 printpath(tcp, tcp->u_arg[0]);
2089 tprintf(", ");
Dmitry V. Levina7945a32006-12-13 17:10:11 +00002090 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002091 }
2092 return 0;
2093}
2094#endif
2095
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002096static int
2097decode_utimes(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002098{
2099 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002100 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002101 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002102 printtv(tcp, tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002103 }
2104 return 0;
2105}
2106
2107int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002108sys_utimes(struct tcb *tcp)
2109{
2110 return decode_utimes(tcp, 0);
2111}
2112
2113#ifdef LINUX
2114int
2115sys_futimesat(struct tcb *tcp)
2116{
2117 if (entering(tcp))
2118 print_dirfd(tcp->u_arg[0]);
2119 return decode_utimes(tcp, 1);
2120}
2121#endif
2122
2123int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002124sys_utime(tcp)
2125struct tcb *tcp;
2126{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002127 union {
2128 long utl[2];
2129 int uti[2];
2130 } u;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002131
2132 if (entering(tcp)) {
2133 printpath(tcp, tcp->u_arg[0]);
2134 tprintf(", ");
2135 if (!tcp->u_arg[1])
2136 tprintf("NULL");
2137 else if (!verbose(tcp))
2138 tprintf("%#lx", tcp->u_arg[1]);
Roland McGrath7e9817c2007-07-05 20:31:58 +00002139 else if (umoven(tcp, tcp->u_arg[1],
2140 2 * personality_wordsize[current_personality],
2141 (char *) &u) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002142 tprintf("[?, ?]");
Roland McGrath7e9817c2007-07-05 20:31:58 +00002143 else if (personality_wordsize[current_personality]
2144 == sizeof u.utl[0]) {
2145 tprintf("[%s,", sprinttime(u.utl[0]));
2146 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002147 }
Roland McGrath7e9817c2007-07-05 20:31:58 +00002148 else if (personality_wordsize[current_personality]
2149 == sizeof u.uti[0]) {
2150 tprintf("[%s,", sprinttime(u.uti[0]));
2151 tprintf(" %s]", sprinttime(u.uti[1]));
2152 }
2153 else
2154 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002155 }
2156 return 0;
2157}
2158
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002159static int
2160decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002161{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002162 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002163
2164 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002165 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002166 tprintf(", %s", sprintmode(mode));
2167 switch (mode & S_IFMT) {
2168 case S_IFCHR: case S_IFBLK:
2169#ifdef LINUXSPARC
2170 if (current_personality == 1)
2171 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002172 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2173 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002174 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002175#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002176 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002177 (unsigned long) major(tcp->u_arg[offset + 2]),
2178 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002179 break;
2180 default:
2181 break;
2182 }
2183 }
2184 return 0;
2185}
2186
2187int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002188sys_mknod(struct tcb *tcp)
2189{
2190 return decode_mknod(tcp, 0);
2191}
2192
2193#ifdef LINUX
2194int
2195sys_mknodat(struct tcb *tcp)
2196{
2197 if (entering(tcp))
2198 print_dirfd(tcp->u_arg[0]);
2199 return decode_mknod(tcp, 1);
2200}
2201#endif
2202
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002203#ifdef FREEBSD
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002204int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002205sys_mkfifo(tcp)
2206struct tcb *tcp;
2207{
2208 if (entering(tcp)) {
2209 printpath(tcp, tcp->u_arg[0]);
2210 tprintf(", %#lo", tcp->u_arg[1]);
2211 }
2212 return 0;
2213}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002214#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002215
2216int
2217sys_fsync(tcp)
2218struct tcb *tcp;
2219{
2220 if (entering(tcp)) {
2221 tprintf("%ld", tcp->u_arg[0]);
2222 }
2223 return 0;
2224}
2225
Michal Ludvig53b320f2002-09-23 13:30:09 +00002226#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002227
2228static void
2229printdir(tcp, addr)
2230struct tcb *tcp;
2231long addr;
2232{
2233 struct dirent d;
2234
2235 if (!verbose(tcp)) {
2236 tprintf("%#lx", addr);
2237 return;
2238 }
2239 if (umove(tcp, addr, &d) < 0) {
2240 tprintf("{...}");
2241 return;
2242 }
2243 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002244 tprintf("d_name=");
2245 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2246 tprintf("}");
2247}
2248
2249int
2250sys_readdir(tcp)
2251struct tcb *tcp;
2252{
2253 if (entering(tcp)) {
2254 tprintf("%lu, ", tcp->u_arg[0]);
2255 } else {
2256 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2257 tprintf("%#lx", tcp->u_arg[1]);
2258 else
2259 printdir(tcp, tcp->u_arg[1]);
2260 /* Not much point in printing this out, it is always 1. */
2261 if (tcp->u_arg[2] != 1)
2262 tprintf(", %lu", tcp->u_arg[2]);
2263 }
2264 return 0;
2265}
2266
Michal Ludvig53b320f2002-09-23 13:30:09 +00002267#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002268
Roland McGrath40542842004-01-13 09:47:49 +00002269#if defined FREEBSD || defined LINUX
Roland McGratha4d48532005-06-08 20:45:28 +00002270static const struct xlat direnttypes[] = {
Roland McGrath40542842004-01-13 09:47:49 +00002271 { DT_UNKNOWN, "DT_UNKNOWN" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002272 { DT_FIFO, "DT_FIFO" },
2273 { DT_CHR, "DT_CHR" },
2274 { DT_DIR, "DT_DIR" },
2275 { DT_BLK, "DT_BLK" },
2276 { DT_REG, "DT_REG" },
2277 { DT_LNK, "DT_LNK" },
2278 { DT_SOCK, "DT_SOCK" },
2279 { DT_WHT, "DT_WHT" },
2280 { 0, NULL },
2281};
2282
2283#endif
2284
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002285int
2286sys_getdents(tcp)
2287struct tcb *tcp;
2288{
2289 int i, len, dents = 0;
2290 char *buf;
2291
2292 if (entering(tcp)) {
2293 tprintf("%lu, ", tcp->u_arg[0]);
2294 return 0;
2295 }
2296 if (syserror(tcp) || !verbose(tcp)) {
2297 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2298 return 0;
2299 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002300 len = tcp->u_rval;
2301 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002302 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2303 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002304 return 0;
2305 }
2306 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002307 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002308 free(buf);
2309 return 0;
2310 }
2311 if (!abbrev(tcp))
2312 tprintf("{");
2313 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002314 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002315#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002316 if (!abbrev(tcp)) {
2317 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2318 i ? " " : "", d->d_ino, d->d_off);
2319 tprintf("d_reclen=%u, d_name=\"%s\"}",
2320 d->d_reclen, d->d_name);
2321 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002322#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002323#ifdef SVR4
2324 if (!abbrev(tcp)) {
2325 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002326 i ? " " : "",
2327 (unsigned long) d->d_ino,
2328 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002329 tprintf("d_reclen=%u, d_name=\"%s\"}",
2330 d->d_reclen, d->d_name);
2331 }
2332#endif /* SVR4 */
2333#ifdef SUNOS4
2334 if (!abbrev(tcp)) {
2335 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2336 i ? " " : "", d->d_off, d->d_fileno,
2337 d->d_reclen);
2338 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2339 d->d_namlen, d->d_namlen, d->d_name);
2340 }
2341#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002342#ifdef FREEBSD
2343 if (!abbrev(tcp)) {
2344 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2345 i ? " " : "", d->d_fileno, d->d_reclen);
2346 printxval(direnttypes, d->d_type, "DT_???");
2347 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2348 d->d_namlen, d->d_namlen, d->d_name);
2349 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002350#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002351 if (!d->d_reclen) {
2352 tprintf("/* d_reclen == 0, problem here */");
2353 break;
2354 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002355 i += d->d_reclen;
2356 dents++;
2357 }
2358 if (!abbrev(tcp))
2359 tprintf("}");
2360 else
2361 tprintf("/* %u entries */", dents);
2362 tprintf(", %lu", tcp->u_arg[2]);
2363 free(buf);
2364 return 0;
2365}
2366
John Hughesbdf48f52001-03-06 15:08:09 +00002367
2368#if _LFS64_LARGEFILE
2369int
2370sys_getdents64(tcp)
2371struct tcb *tcp;
2372{
2373 int i, len, dents = 0;
2374 char *buf;
2375
2376 if (entering(tcp)) {
2377 tprintf("%lu, ", tcp->u_arg[0]);
2378 return 0;
2379 }
2380 if (syserror(tcp) || !verbose(tcp)) {
2381 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2382 return 0;
2383 }
2384 len = tcp->u_rval;
2385 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002386 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2387 fprintf(stderr, "out of memory\n");
John Hughesbdf48f52001-03-06 15:08:09 +00002388 return 0;
2389 }
2390 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002391 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002392 free(buf);
2393 return 0;
2394 }
2395 if (!abbrev(tcp))
2396 tprintf("{");
2397 for (i = 0; i < len;) {
2398 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002399#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002400 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002401 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002402 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002403 d->d_ino,
2404 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002405#ifdef LINUX
2406 tprintf("d_type=");
2407 printxval(direnttypes, d->d_type, "DT_???");
2408 tprintf(", ");
2409#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002410 tprintf("d_reclen=%u, d_name=\"%s\"}",
2411 d->d_reclen, d->d_name);
2412 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002413#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002414#ifdef SUNOS4
2415 if (!abbrev(tcp)) {
2416 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2417 i ? " " : "", d->d_off, d->d_fileno,
2418 d->d_reclen);
2419 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2420 d->d_namlen, d->d_namlen, d->d_name);
2421 }
2422#endif /* SUNOS4 */
2423 i += d->d_reclen;
2424 dents++;
2425 }
2426 if (!abbrev(tcp))
2427 tprintf("}");
2428 else
2429 tprintf("/* %u entries */", dents);
2430 tprintf(", %lu", tcp->u_arg[2]);
2431 free(buf);
2432 return 0;
2433}
2434#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002435
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002436#ifdef FREEBSD
2437int
2438sys_getdirentries(tcp)
2439struct tcb * tcp;
2440{
2441 int i, len, dents = 0;
2442 long basep;
2443 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002444
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002445 if (entering(tcp)) {
2446 tprintf("%lu, ", tcp->u_arg[0]);
2447 return 0;
2448 }
2449 if (syserror(tcp) || !verbose(tcp)) {
2450 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2451 return 0;
2452 }
2453 len = tcp->u_rval;
2454 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002455 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2456 fprintf(stderr, "out of memory\n");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002457 return 0;
2458 }
2459 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002460 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002461 free(buf);
2462 return 0;
2463 }
2464 if (!abbrev(tcp))
2465 tprintf("{");
2466 for (i = 0; i < len;) {
2467 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2468 if (!abbrev(tcp)) {
2469 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2470 i ? " " : "", d->d_fileno, d->d_reclen);
2471 printxval(direnttypes, d->d_type, "DT_???");
2472 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2473 d->d_namlen, d->d_namlen, d->d_name);
2474 }
2475 i += d->d_reclen;
2476 dents++;
2477 }
2478 if (!abbrev(tcp))
2479 tprintf("}");
2480 else
2481 tprintf("/* %u entries */", dents);
2482 free(buf);
2483 tprintf(", %lu", tcp->u_arg[2]);
2484 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2485 tprintf(", %#lx", tcp->u_arg[3]);
2486 else
2487 tprintf(", [%lu]", basep);
2488 return 0;
2489}
2490#endif
2491
Michal Ludvig53b320f2002-09-23 13:30:09 +00002492#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002493int
2494sys_getcwd(tcp)
2495struct tcb *tcp;
2496{
2497 if (exiting(tcp)) {
2498 if (syserror(tcp))
2499 tprintf("%#lx", tcp->u_arg[0]);
2500 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002501 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002502 tprintf(", %lu", tcp->u_arg[1]);
2503 }
2504 return 0;
2505}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002506#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002507
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002508#ifdef FREEBSD
2509int
2510sys___getcwd(tcp)
2511struct tcb *tcp;
2512{
2513 if (exiting(tcp)) {
2514 if (syserror(tcp))
2515 tprintf("%#lx", tcp->u_arg[0]);
2516 else
2517 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2518 tprintf(", %lu", tcp->u_arg[1]);
2519 }
2520 return 0;
2521}
2522#endif
2523
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002524#ifdef HAVE_SYS_ASYNCH_H
2525
2526int
2527sys_aioread(tcp)
2528struct tcb *tcp;
2529{
2530 struct aio_result_t res;
2531
2532 if (entering(tcp)) {
2533 tprintf("%lu, ", tcp->u_arg[0]);
2534 } else {
2535 if (syserror(tcp))
2536 tprintf("%#lx", tcp->u_arg[1]);
2537 else
2538 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2539 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2540 printxval(whence, tcp->u_arg[4], "L_???");
2541 if (syserror(tcp) || tcp->u_arg[5] == 0
2542 || umove(tcp, tcp->u_arg[5], &res) < 0)
2543 tprintf(", %#lx", tcp->u_arg[5]);
2544 else
2545 tprintf(", {aio_return %d aio_errno %d}",
2546 res.aio_return, res.aio_errno);
2547 }
2548 return 0;
2549}
2550
2551int
2552sys_aiowrite(tcp)
2553struct tcb *tcp;
2554{
2555 struct aio_result_t res;
2556
2557 if (entering(tcp)) {
2558 tprintf("%lu, ", tcp->u_arg[0]);
2559 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2560 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2561 printxval(whence, tcp->u_arg[4], "L_???");
2562 }
2563 else {
2564 if (tcp->u_arg[5] == 0)
2565 tprintf(", NULL");
2566 else if (syserror(tcp)
2567 || umove(tcp, tcp->u_arg[5], &res) < 0)
2568 tprintf(", %#lx", tcp->u_arg[5]);
2569 else
2570 tprintf(", {aio_return %d aio_errno %d}",
2571 res.aio_return, res.aio_errno);
2572 }
2573 return 0;
2574}
2575
2576int
2577sys_aiowait(tcp)
2578struct tcb *tcp;
2579{
2580 if (entering(tcp))
2581 printtv(tcp, tcp->u_arg[0]);
2582 return 0;
2583}
2584
2585int
2586sys_aiocancel(tcp)
2587struct tcb *tcp;
2588{
2589 struct aio_result_t res;
2590
2591 if (exiting(tcp)) {
2592 if (tcp->u_arg[0] == 0)
2593 tprintf("NULL");
2594 else if (syserror(tcp)
2595 || umove(tcp, tcp->u_arg[0], &res) < 0)
2596 tprintf("%#lx", tcp->u_arg[0]);
2597 else
2598 tprintf("{aio_return %d aio_errno %d}",
2599 res.aio_return, res.aio_errno);
2600 }
2601 return 0;
2602}
2603
2604#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002605
Roland McGratha4d48532005-06-08 20:45:28 +00002606static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002607#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002608 { XATTR_CREATE, "XATTR_CREATE" },
2609 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002610#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002611 { 0, NULL }
2612};
2613
Roland McGrath3292e222004-08-31 06:30:48 +00002614static void
2615print_xattr_val(tcp, failed, arg, insize, size)
2616struct tcb *tcp;
2617int failed;
2618unsigned long arg;
Roland McGrathaa524c82005-06-01 19:22:06 +00002619unsigned long insize, size;
Roland McGrath3292e222004-08-31 06:30:48 +00002620{
Roland McGrath883567c2005-02-02 03:38:32 +00002621 if (!failed) {
Roland McGrathaa524c82005-06-01 19:22:06 +00002622 unsigned long capacity = 4 * size + 1;
2623 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
Roland McGrath883567c2005-02-02 03:38:32 +00002624 if (buf == NULL || /* probably a bogus size argument */
Roland McGrathf7746422005-03-01 23:02:32 +00002625 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
Roland McGrath883567c2005-02-02 03:38:32 +00002626 failed = 1;
2627 }
2628 else {
2629 unsigned char *out = buf;
2630 unsigned char *in = &buf[3 * size];
2631 size_t i;
2632 for (i = 0; i < size; ++i)
2633 if (isprint(in[i]))
2634 *out++ = in[i];
2635 else {
Roland McGrath3292e222004-08-31 06:30:48 +00002636#define tohex(n) "0123456789abcdef"[n]
Roland McGrath883567c2005-02-02 03:38:32 +00002637 *out++ = '\\';
2638 *out++ = 'x';
2639 *out++ = tohex(in[i] / 16);
2640 *out++ = tohex(in[i] % 16);
2641 }
2642 /* Don't print terminating NUL if there is one. */
Dmitry V. Levin504eb0b2006-10-11 22:58:31 +00002643 if (i > 0 && in[i - 1] == '\0')
Roland McGrath883567c2005-02-02 03:38:32 +00002644 out -= 4;
2645 *out = '\0';
2646 tprintf(", \"%s\", %ld", buf, insize);
2647 }
2648 free(buf);
2649 }
2650 if (failed)
2651 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002652}
2653
Roland McGrath186c5ac2002-12-15 23:58:23 +00002654int
2655sys_setxattr(tcp)
2656struct tcb *tcp;
2657{
2658 if (entering(tcp)) {
2659 printpath(tcp, tcp->u_arg[0]);
2660 tprintf(", ");
2661 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002662 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2663 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002664 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002665 }
2666 return 0;
2667}
2668
2669int
2670sys_fsetxattr(tcp)
2671struct tcb *tcp;
2672{
2673 if (entering(tcp)) {
2674 tprintf("%ld, ", tcp->u_arg[0]);
2675 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002676 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2677 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002678 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002679 }
2680 return 0;
2681}
2682
2683int
2684sys_getxattr(tcp)
2685struct tcb *tcp;
2686{
2687 if (entering(tcp)) {
2688 printpath(tcp, tcp->u_arg[0]);
2689 tprintf(", ");
2690 printstr(tcp, tcp->u_arg[1], -1);
2691 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002692 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2693 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002694 }
2695 return 0;
2696}
2697
2698int
2699sys_fgetxattr(tcp)
2700struct tcb *tcp;
2701{
2702 if (entering(tcp)) {
2703 tprintf("%ld, ", tcp->u_arg[0]);
2704 printstr(tcp, tcp->u_arg[1], -1);
2705 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002706 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2707 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002708 }
2709 return 0;
2710}
2711
2712int
2713sys_listxattr(tcp)
2714struct tcb *tcp;
2715{
2716 if (entering(tcp)) {
2717 printpath(tcp, tcp->u_arg[0]);
2718 } else {
2719 /* XXX Print value in format */
2720 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2721 }
2722 return 0;
2723}
2724
2725int
2726sys_flistxattr(tcp)
2727struct tcb *tcp;
2728{
2729 if (entering(tcp)) {
2730 tprintf("%ld", tcp->u_arg[0]);
2731 } else {
2732 /* XXX Print value in format */
2733 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2734 }
2735 return 0;
2736}
2737
2738int
2739sys_removexattr(tcp)
2740struct tcb *tcp;
2741{
2742 if (entering(tcp)) {
2743 printpath(tcp, tcp->u_arg[0]);
2744 tprintf(", ");
2745 printstr(tcp, tcp->u_arg[1], -1);
2746 }
2747 return 0;
2748}
2749
2750int
2751sys_fremovexattr(tcp)
2752struct tcb *tcp;
2753{
2754 if (entering(tcp)) {
2755 tprintf("%ld, ", tcp->u_arg[0]);
2756 printstr(tcp, tcp->u_arg[1], -1);
2757 }
2758 return 0;
2759}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002760
2761
2762static const struct xlat advise[] = {
2763 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2764 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2765 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2766 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2767 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2768 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2769 { 0, NULL }
2770};
2771
2772
Roland McGrathe27ed342004-10-20 02:24:19 +00002773#ifdef LINUX
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002774int
2775sys_fadvise64(tcp)
2776struct tcb *tcp;
2777{
2778 if (entering(tcp)) {
2779 tprintf("%ld, %lld, %ld, ",
2780 tcp->u_arg[0],
2781# if defined IA64 || defined X86_64 || defined ALPHA
2782 (long long int) tcp->u_arg[1], tcp->u_arg[2]);
2783 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2784#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002785 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
2786 printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002787#endif
2788 }
2789 return 0;
2790}
2791#endif
2792
2793
2794int
2795sys_fadvise64_64(tcp)
2796struct tcb *tcp;
2797{
2798 if (entering(tcp)) {
2799 tprintf("%ld, %lld, %lld, ",
2800 tcp->u_arg[0],
2801# if defined IA64 || defined X86_64 || defined ALPHA
2802 (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
2803 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2804#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002805 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
2806 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002807 printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
2808#endif
2809 }
2810 return 0;
2811}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002812
2813#ifdef LINUX
2814static const struct xlat inotify_modes[] = {
2815 { 0x00000001, "IN_ACCESS" },
2816 { 0x00000002, "IN_MODIFY" },
2817 { 0x00000004, "IN_ATTRIB" },
2818 { 0x00000008, "IN_CLOSE_WRITE" },
2819 { 0x00000010, "IN_CLOSE_NOWRITE" },
2820 { 0x00000020, "IN_OPEN" },
2821 { 0x00000040, "IN_MOVED_FROM" },
2822 { 0x00000080, "IN_MOVED_TO" },
2823 { 0x00000100, "IN_CREATE" },
2824 { 0x00000200, "IN_DELETE" },
2825 { 0x00000400, "IN_DELETE_SELF" },
2826 { 0x00000800, "IN_MOVE_SELF" },
2827 { 0x00002000, "IN_UNMOUNT" },
2828 { 0x00004000, "IN_Q_OVERFLOW" },
2829 { 0x00008000, "IN_IGNORED" },
2830 { 0x01000000, "IN_ONLYDIR" },
2831 { 0x02000000, "IN_DONT_FOLLOW" },
2832 { 0x20000000, "IN_MASK_ADD" },
2833 { 0x40000000, "IN_ISDIR" },
2834 { 0x80000000, "IN_ONESHOT" }
2835};
2836
2837int
2838sys_inotify_add_watch(struct tcb *tcp)
2839{
2840 if (entering(tcp)) {
2841 tprintf("%ld, ", tcp->u_arg[0]);
2842 printpath(tcp, tcp->u_arg[1]);
2843 tprintf(", ");
2844 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2845 }
2846 return 0;
2847}
2848
2849int
2850sys_inotify_rm_watch(struct tcb *tcp)
2851{
2852 if (entering(tcp)) {
2853 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
2854 }
2855 return 0;
2856}
2857#endif