blob: 92621797e1661d589730e16e7bece8ce4cee6250 [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{
2127 long ut[2];
2128
2129 if (entering(tcp)) {
2130 printpath(tcp, tcp->u_arg[0]);
2131 tprintf(", ");
2132 if (!tcp->u_arg[1])
2133 tprintf("NULL");
2134 else if (!verbose(tcp))
2135 tprintf("%#lx", tcp->u_arg[1]);
2136 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
2137 (char *) ut) < 0)
2138 tprintf("[?, ?]");
2139 else {
2140 tprintf("[%s,", sprinttime(ut[0]));
2141 tprintf(" %s]", sprinttime(ut[1]));
2142 }
2143 }
2144 return 0;
2145}
2146
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002147static int
2148decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002149{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002150 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002151
2152 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002153 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002154 tprintf(", %s", sprintmode(mode));
2155 switch (mode & S_IFMT) {
2156 case S_IFCHR: case S_IFBLK:
2157#ifdef LINUXSPARC
2158 if (current_personality == 1)
2159 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002160 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2161 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002162 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002163#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002164 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002165 (unsigned long) major(tcp->u_arg[offset + 2]),
2166 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002167 break;
2168 default:
2169 break;
2170 }
2171 }
2172 return 0;
2173}
2174
2175int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002176sys_mknod(struct tcb *tcp)
2177{
2178 return decode_mknod(tcp, 0);
2179}
2180
2181#ifdef LINUX
2182int
2183sys_mknodat(struct tcb *tcp)
2184{
2185 if (entering(tcp))
2186 print_dirfd(tcp->u_arg[0]);
2187 return decode_mknod(tcp, 1);
2188}
2189#endif
2190
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002191#ifdef FREEBSD
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002192int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002193sys_mkfifo(tcp)
2194struct tcb *tcp;
2195{
2196 if (entering(tcp)) {
2197 printpath(tcp, tcp->u_arg[0]);
2198 tprintf(", %#lo", tcp->u_arg[1]);
2199 }
2200 return 0;
2201}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002202#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002203
2204int
2205sys_fsync(tcp)
2206struct tcb *tcp;
2207{
2208 if (entering(tcp)) {
2209 tprintf("%ld", tcp->u_arg[0]);
2210 }
2211 return 0;
2212}
2213
Michal Ludvig53b320f2002-09-23 13:30:09 +00002214#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002215
2216static void
2217printdir(tcp, addr)
2218struct tcb *tcp;
2219long addr;
2220{
2221 struct dirent d;
2222
2223 if (!verbose(tcp)) {
2224 tprintf("%#lx", addr);
2225 return;
2226 }
2227 if (umove(tcp, addr, &d) < 0) {
2228 tprintf("{...}");
2229 return;
2230 }
2231 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002232 tprintf("d_name=");
2233 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2234 tprintf("}");
2235}
2236
2237int
2238sys_readdir(tcp)
2239struct tcb *tcp;
2240{
2241 if (entering(tcp)) {
2242 tprintf("%lu, ", tcp->u_arg[0]);
2243 } else {
2244 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2245 tprintf("%#lx", tcp->u_arg[1]);
2246 else
2247 printdir(tcp, tcp->u_arg[1]);
2248 /* Not much point in printing this out, it is always 1. */
2249 if (tcp->u_arg[2] != 1)
2250 tprintf(", %lu", tcp->u_arg[2]);
2251 }
2252 return 0;
2253}
2254
Michal Ludvig53b320f2002-09-23 13:30:09 +00002255#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002256
Roland McGrath40542842004-01-13 09:47:49 +00002257#if defined FREEBSD || defined LINUX
Roland McGratha4d48532005-06-08 20:45:28 +00002258static const struct xlat direnttypes[] = {
Roland McGrath40542842004-01-13 09:47:49 +00002259 { DT_UNKNOWN, "DT_UNKNOWN" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002260 { DT_FIFO, "DT_FIFO" },
2261 { DT_CHR, "DT_CHR" },
2262 { DT_DIR, "DT_DIR" },
2263 { DT_BLK, "DT_BLK" },
2264 { DT_REG, "DT_REG" },
2265 { DT_LNK, "DT_LNK" },
2266 { DT_SOCK, "DT_SOCK" },
2267 { DT_WHT, "DT_WHT" },
2268 { 0, NULL },
2269};
2270
2271#endif
2272
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002273int
2274sys_getdents(tcp)
2275struct tcb *tcp;
2276{
2277 int i, len, dents = 0;
2278 char *buf;
2279
2280 if (entering(tcp)) {
2281 tprintf("%lu, ", tcp->u_arg[0]);
2282 return 0;
2283 }
2284 if (syserror(tcp) || !verbose(tcp)) {
2285 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2286 return 0;
2287 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002288 len = tcp->u_rval;
2289 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002290 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2291 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002292 return 0;
2293 }
2294 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002295 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002296 free(buf);
2297 return 0;
2298 }
2299 if (!abbrev(tcp))
2300 tprintf("{");
2301 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002302 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002303#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002304 if (!abbrev(tcp)) {
2305 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2306 i ? " " : "", d->d_ino, d->d_off);
2307 tprintf("d_reclen=%u, d_name=\"%s\"}",
2308 d->d_reclen, d->d_name);
2309 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002310#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002311#ifdef SVR4
2312 if (!abbrev(tcp)) {
2313 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002314 i ? " " : "",
2315 (unsigned long) d->d_ino,
2316 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002317 tprintf("d_reclen=%u, d_name=\"%s\"}",
2318 d->d_reclen, d->d_name);
2319 }
2320#endif /* SVR4 */
2321#ifdef SUNOS4
2322 if (!abbrev(tcp)) {
2323 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2324 i ? " " : "", d->d_off, d->d_fileno,
2325 d->d_reclen);
2326 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2327 d->d_namlen, d->d_namlen, d->d_name);
2328 }
2329#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002330#ifdef FREEBSD
2331 if (!abbrev(tcp)) {
2332 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2333 i ? " " : "", d->d_fileno, d->d_reclen);
2334 printxval(direnttypes, d->d_type, "DT_???");
2335 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2336 d->d_namlen, d->d_namlen, d->d_name);
2337 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002338#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002339 if (!d->d_reclen) {
2340 tprintf("/* d_reclen == 0, problem here */");
2341 break;
2342 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002343 i += d->d_reclen;
2344 dents++;
2345 }
2346 if (!abbrev(tcp))
2347 tprintf("}");
2348 else
2349 tprintf("/* %u entries */", dents);
2350 tprintf(", %lu", tcp->u_arg[2]);
2351 free(buf);
2352 return 0;
2353}
2354
John Hughesbdf48f52001-03-06 15:08:09 +00002355
2356#if _LFS64_LARGEFILE
2357int
2358sys_getdents64(tcp)
2359struct tcb *tcp;
2360{
2361 int i, len, dents = 0;
2362 char *buf;
2363
2364 if (entering(tcp)) {
2365 tprintf("%lu, ", tcp->u_arg[0]);
2366 return 0;
2367 }
2368 if (syserror(tcp) || !verbose(tcp)) {
2369 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2370 return 0;
2371 }
2372 len = tcp->u_rval;
2373 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002374 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2375 fprintf(stderr, "out of memory\n");
John Hughesbdf48f52001-03-06 15:08:09 +00002376 return 0;
2377 }
2378 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002379 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002380 free(buf);
2381 return 0;
2382 }
2383 if (!abbrev(tcp))
2384 tprintf("{");
2385 for (i = 0; i < len;) {
2386 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002387#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002388 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002389 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002390 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002391 d->d_ino,
2392 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002393#ifdef LINUX
2394 tprintf("d_type=");
2395 printxval(direnttypes, d->d_type, "DT_???");
2396 tprintf(", ");
2397#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002398 tprintf("d_reclen=%u, d_name=\"%s\"}",
2399 d->d_reclen, d->d_name);
2400 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002401#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002402#ifdef SUNOS4
2403 if (!abbrev(tcp)) {
2404 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2405 i ? " " : "", d->d_off, d->d_fileno,
2406 d->d_reclen);
2407 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2408 d->d_namlen, d->d_namlen, d->d_name);
2409 }
2410#endif /* SUNOS4 */
2411 i += d->d_reclen;
2412 dents++;
2413 }
2414 if (!abbrev(tcp))
2415 tprintf("}");
2416 else
2417 tprintf("/* %u entries */", dents);
2418 tprintf(", %lu", tcp->u_arg[2]);
2419 free(buf);
2420 return 0;
2421}
2422#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002423
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002424#ifdef FREEBSD
2425int
2426sys_getdirentries(tcp)
2427struct tcb * tcp;
2428{
2429 int i, len, dents = 0;
2430 long basep;
2431 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002432
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002433 if (entering(tcp)) {
2434 tprintf("%lu, ", tcp->u_arg[0]);
2435 return 0;
2436 }
2437 if (syserror(tcp) || !verbose(tcp)) {
2438 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2439 return 0;
2440 }
2441 len = tcp->u_rval;
2442 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002443 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2444 fprintf(stderr, "out of memory\n");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002445 return 0;
2446 }
2447 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002448 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002449 free(buf);
2450 return 0;
2451 }
2452 if (!abbrev(tcp))
2453 tprintf("{");
2454 for (i = 0; i < len;) {
2455 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2456 if (!abbrev(tcp)) {
2457 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2458 i ? " " : "", d->d_fileno, d->d_reclen);
2459 printxval(direnttypes, d->d_type, "DT_???");
2460 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2461 d->d_namlen, d->d_namlen, d->d_name);
2462 }
2463 i += d->d_reclen;
2464 dents++;
2465 }
2466 if (!abbrev(tcp))
2467 tprintf("}");
2468 else
2469 tprintf("/* %u entries */", dents);
2470 free(buf);
2471 tprintf(", %lu", tcp->u_arg[2]);
2472 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2473 tprintf(", %#lx", tcp->u_arg[3]);
2474 else
2475 tprintf(", [%lu]", basep);
2476 return 0;
2477}
2478#endif
2479
Michal Ludvig53b320f2002-09-23 13:30:09 +00002480#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002481int
2482sys_getcwd(tcp)
2483struct tcb *tcp;
2484{
2485 if (exiting(tcp)) {
2486 if (syserror(tcp))
2487 tprintf("%#lx", tcp->u_arg[0]);
2488 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002489 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002490 tprintf(", %lu", tcp->u_arg[1]);
2491 }
2492 return 0;
2493}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002494#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002495
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002496#ifdef FREEBSD
2497int
2498sys___getcwd(tcp)
2499struct tcb *tcp;
2500{
2501 if (exiting(tcp)) {
2502 if (syserror(tcp))
2503 tprintf("%#lx", tcp->u_arg[0]);
2504 else
2505 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2506 tprintf(", %lu", tcp->u_arg[1]);
2507 }
2508 return 0;
2509}
2510#endif
2511
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002512#ifdef HAVE_SYS_ASYNCH_H
2513
2514int
2515sys_aioread(tcp)
2516struct tcb *tcp;
2517{
2518 struct aio_result_t res;
2519
2520 if (entering(tcp)) {
2521 tprintf("%lu, ", tcp->u_arg[0]);
2522 } else {
2523 if (syserror(tcp))
2524 tprintf("%#lx", tcp->u_arg[1]);
2525 else
2526 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2527 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2528 printxval(whence, tcp->u_arg[4], "L_???");
2529 if (syserror(tcp) || tcp->u_arg[5] == 0
2530 || umove(tcp, tcp->u_arg[5], &res) < 0)
2531 tprintf(", %#lx", tcp->u_arg[5]);
2532 else
2533 tprintf(", {aio_return %d aio_errno %d}",
2534 res.aio_return, res.aio_errno);
2535 }
2536 return 0;
2537}
2538
2539int
2540sys_aiowrite(tcp)
2541struct tcb *tcp;
2542{
2543 struct aio_result_t res;
2544
2545 if (entering(tcp)) {
2546 tprintf("%lu, ", tcp->u_arg[0]);
2547 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2548 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2549 printxval(whence, tcp->u_arg[4], "L_???");
2550 }
2551 else {
2552 if (tcp->u_arg[5] == 0)
2553 tprintf(", NULL");
2554 else if (syserror(tcp)
2555 || umove(tcp, tcp->u_arg[5], &res) < 0)
2556 tprintf(", %#lx", tcp->u_arg[5]);
2557 else
2558 tprintf(", {aio_return %d aio_errno %d}",
2559 res.aio_return, res.aio_errno);
2560 }
2561 return 0;
2562}
2563
2564int
2565sys_aiowait(tcp)
2566struct tcb *tcp;
2567{
2568 if (entering(tcp))
2569 printtv(tcp, tcp->u_arg[0]);
2570 return 0;
2571}
2572
2573int
2574sys_aiocancel(tcp)
2575struct tcb *tcp;
2576{
2577 struct aio_result_t res;
2578
2579 if (exiting(tcp)) {
2580 if (tcp->u_arg[0] == 0)
2581 tprintf("NULL");
2582 else if (syserror(tcp)
2583 || umove(tcp, tcp->u_arg[0], &res) < 0)
2584 tprintf("%#lx", tcp->u_arg[0]);
2585 else
2586 tprintf("{aio_return %d aio_errno %d}",
2587 res.aio_return, res.aio_errno);
2588 }
2589 return 0;
2590}
2591
2592#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002593
Roland McGratha4d48532005-06-08 20:45:28 +00002594static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002595#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002596 { XATTR_CREATE, "XATTR_CREATE" },
2597 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002598#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002599 { 0, NULL }
2600};
2601
Roland McGrath3292e222004-08-31 06:30:48 +00002602static void
2603print_xattr_val(tcp, failed, arg, insize, size)
2604struct tcb *tcp;
2605int failed;
2606unsigned long arg;
Roland McGrathaa524c82005-06-01 19:22:06 +00002607unsigned long insize, size;
Roland McGrath3292e222004-08-31 06:30:48 +00002608{
Roland McGrath883567c2005-02-02 03:38:32 +00002609 if (!failed) {
Roland McGrathaa524c82005-06-01 19:22:06 +00002610 unsigned long capacity = 4 * size + 1;
2611 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
Roland McGrath883567c2005-02-02 03:38:32 +00002612 if (buf == NULL || /* probably a bogus size argument */
Roland McGrathf7746422005-03-01 23:02:32 +00002613 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
Roland McGrath883567c2005-02-02 03:38:32 +00002614 failed = 1;
2615 }
2616 else {
2617 unsigned char *out = buf;
2618 unsigned char *in = &buf[3 * size];
2619 size_t i;
2620 for (i = 0; i < size; ++i)
2621 if (isprint(in[i]))
2622 *out++ = in[i];
2623 else {
Roland McGrath3292e222004-08-31 06:30:48 +00002624#define tohex(n) "0123456789abcdef"[n]
Roland McGrath883567c2005-02-02 03:38:32 +00002625 *out++ = '\\';
2626 *out++ = 'x';
2627 *out++ = tohex(in[i] / 16);
2628 *out++ = tohex(in[i] % 16);
2629 }
2630 /* Don't print terminating NUL if there is one. */
Dmitry V. Levin504eb0b2006-10-11 22:58:31 +00002631 if (i > 0 && in[i - 1] == '\0')
Roland McGrath883567c2005-02-02 03:38:32 +00002632 out -= 4;
2633 *out = '\0';
2634 tprintf(", \"%s\", %ld", buf, insize);
2635 }
2636 free(buf);
2637 }
2638 if (failed)
2639 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002640}
2641
Roland McGrath186c5ac2002-12-15 23:58:23 +00002642int
2643sys_setxattr(tcp)
2644struct tcb *tcp;
2645{
2646 if (entering(tcp)) {
2647 printpath(tcp, tcp->u_arg[0]);
2648 tprintf(", ");
2649 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002650 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2651 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002652 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002653 }
2654 return 0;
2655}
2656
2657int
2658sys_fsetxattr(tcp)
2659struct tcb *tcp;
2660{
2661 if (entering(tcp)) {
2662 tprintf("%ld, ", tcp->u_arg[0]);
2663 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002664 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2665 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002666 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002667 }
2668 return 0;
2669}
2670
2671int
2672sys_getxattr(tcp)
2673struct tcb *tcp;
2674{
2675 if (entering(tcp)) {
2676 printpath(tcp, tcp->u_arg[0]);
2677 tprintf(", ");
2678 printstr(tcp, tcp->u_arg[1], -1);
2679 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002680 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2681 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002682 }
2683 return 0;
2684}
2685
2686int
2687sys_fgetxattr(tcp)
2688struct tcb *tcp;
2689{
2690 if (entering(tcp)) {
2691 tprintf("%ld, ", tcp->u_arg[0]);
2692 printstr(tcp, tcp->u_arg[1], -1);
2693 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002694 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2695 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002696 }
2697 return 0;
2698}
2699
2700int
2701sys_listxattr(tcp)
2702struct tcb *tcp;
2703{
2704 if (entering(tcp)) {
2705 printpath(tcp, tcp->u_arg[0]);
2706 } else {
2707 /* XXX Print value in format */
2708 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2709 }
2710 return 0;
2711}
2712
2713int
2714sys_flistxattr(tcp)
2715struct tcb *tcp;
2716{
2717 if (entering(tcp)) {
2718 tprintf("%ld", tcp->u_arg[0]);
2719 } else {
2720 /* XXX Print value in format */
2721 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2722 }
2723 return 0;
2724}
2725
2726int
2727sys_removexattr(tcp)
2728struct tcb *tcp;
2729{
2730 if (entering(tcp)) {
2731 printpath(tcp, tcp->u_arg[0]);
2732 tprintf(", ");
2733 printstr(tcp, tcp->u_arg[1], -1);
2734 }
2735 return 0;
2736}
2737
2738int
2739sys_fremovexattr(tcp)
2740struct tcb *tcp;
2741{
2742 if (entering(tcp)) {
2743 tprintf("%ld, ", tcp->u_arg[0]);
2744 printstr(tcp, tcp->u_arg[1], -1);
2745 }
2746 return 0;
2747}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002748
2749
2750static const struct xlat advise[] = {
2751 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2752 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2753 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2754 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2755 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2756 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2757 { 0, NULL }
2758};
2759
2760
Roland McGrathe27ed342004-10-20 02:24:19 +00002761#ifdef LINUX
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002762int
2763sys_fadvise64(tcp)
2764struct tcb *tcp;
2765{
2766 if (entering(tcp)) {
2767 tprintf("%ld, %lld, %ld, ",
2768 tcp->u_arg[0],
2769# if defined IA64 || defined X86_64 || defined ALPHA
2770 (long long int) tcp->u_arg[1], tcp->u_arg[2]);
2771 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2772#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002773 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
2774 printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002775#endif
2776 }
2777 return 0;
2778}
2779#endif
2780
2781
2782int
2783sys_fadvise64_64(tcp)
2784struct tcb *tcp;
2785{
2786 if (entering(tcp)) {
2787 tprintf("%ld, %lld, %lld, ",
2788 tcp->u_arg[0],
2789# if defined IA64 || defined X86_64 || defined ALPHA
2790 (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
2791 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2792#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002793 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
2794 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002795 printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
2796#endif
2797 }
2798 return 0;
2799}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002800
2801#ifdef LINUX
2802static const struct xlat inotify_modes[] = {
2803 { 0x00000001, "IN_ACCESS" },
2804 { 0x00000002, "IN_MODIFY" },
2805 { 0x00000004, "IN_ATTRIB" },
2806 { 0x00000008, "IN_CLOSE_WRITE" },
2807 { 0x00000010, "IN_CLOSE_NOWRITE" },
2808 { 0x00000020, "IN_OPEN" },
2809 { 0x00000040, "IN_MOVED_FROM" },
2810 { 0x00000080, "IN_MOVED_TO" },
2811 { 0x00000100, "IN_CREATE" },
2812 { 0x00000200, "IN_DELETE" },
2813 { 0x00000400, "IN_DELETE_SELF" },
2814 { 0x00000800, "IN_MOVE_SELF" },
2815 { 0x00002000, "IN_UNMOUNT" },
2816 { 0x00004000, "IN_Q_OVERFLOW" },
2817 { 0x00008000, "IN_IGNORED" },
2818 { 0x01000000, "IN_ONLYDIR" },
2819 { 0x02000000, "IN_DONT_FOLLOW" },
2820 { 0x20000000, "IN_MASK_ADD" },
2821 { 0x40000000, "IN_ISDIR" },
2822 { 0x80000000, "IN_ONESHOT" }
2823};
2824
2825int
2826sys_inotify_add_watch(struct tcb *tcp)
2827{
2828 if (entering(tcp)) {
2829 tprintf("%ld, ", tcp->u_arg[0]);
2830 printpath(tcp, tcp->u_arg[1]);
2831 tprintf(", ");
2832 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2833 }
2834 return 0;
2835}
2836
2837int
2838sys_inotify_rm_watch(struct tcb *tcp)
2839{
2840 if (entering(tcp)) {
2841 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
2842 }
2843 return 0;
2844}
2845#endif