blob: ea6df327b49cf86d35f32f52d8b99b7592963967 [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>
Roland McGrathc531e572008-08-01 01:13:10 +000037
Michal Ludvig53b320f2002-09-23 13:30:09 +000038#ifdef LINUX
Roland McGrathc531e572008-08-01 01:13:10 +000039struct kernel_dirent {
40 unsigned long d_ino;
41 unsigned long d_off;
42 unsigned short d_reclen;
43 char d_name[1];
44};
Wichert Akkerman9524bb91999-05-25 23:11:18 +000045#else
Roland McGrathc531e572008-08-01 01:13:10 +000046# define kernel_dirent dirent
Wichert Akkerman9524bb91999-05-25 23:11:18 +000047#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000048
Michal Ludvig53b320f2002-09-23 13:30:09 +000049#ifdef LINUX
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000050# ifdef LINUXSPARC
51struct stat {
52 unsigned short st_dev;
53 unsigned int st_ino;
54 unsigned short st_mode;
55 short st_nlink;
56 unsigned short st_uid;
57 unsigned short st_gid;
58 unsigned short st_rdev;
59 unsigned int st_size;
60 int st_atime;
61 unsigned int __unused1;
62 int st_mtime;
63 unsigned int __unused2;
64 int st_ctime;
65 unsigned int __unused3;
66 int st_blksize;
67 int st_blocks;
68 unsigned int __unused4[2];
69};
Roland McGrath6d1a65c2004-07-12 07:44:08 +000070#if defined(SPARC64)
71struct stat_sparc64 {
72 unsigned int st_dev;
73 unsigned long st_ino;
74 unsigned int st_mode;
75 unsigned int st_nlink;
76 unsigned int st_uid;
77 unsigned int st_gid;
78 unsigned int st_rdev;
79 long st_size;
80 long st_atime;
81 long st_mtime;
82 long st_ctime;
83 long st_blksize;
84 long st_blocks;
85 unsigned long __unused4[2];
86};
87#endif /* SPARC64 */
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000088# define stat kernel_stat
89# include <asm/stat.h>
90# undef stat
91# else
Wichert Akkerman5b4d1281999-07-09 00:32:54 +000092# undef dev_t
93# undef ino_t
94# undef mode_t
95# undef nlink_t
96# undef uid_t
97# undef gid_t
98# undef off_t
99# undef loff_t
100
Wichert Akkermana6013701999-07-08 14:00:58 +0000101# define dev_t __kernel_dev_t
102# define ino_t __kernel_ino_t
103# define mode_t __kernel_mode_t
104# define nlink_t __kernel_nlink_t
105# define uid_t __kernel_uid_t
106# define gid_t __kernel_gid_t
107# define off_t __kernel_off_t
108# define loff_t __kernel_loff_t
109
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000110# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +0000111
112# undef dev_t
113# undef ino_t
114# undef mode_t
115# undef nlink_t
116# undef uid_t
117# undef gid_t
118# undef off_t
119# undef loff_t
Wichert Akkerman5b4d1281999-07-09 00:32:54 +0000120
121# define dev_t dev_t
122# define ino_t ino_t
123# define mode_t mode_t
124# define nlink_t nlink_t
125# define uid_t uid_t
126# define gid_t gid_t
127# define off_t off_t
128# define loff_t loff_t
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000129# endif
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000130# ifdef HPPA /* asm-parisc/stat.h defines stat64 */
131# undef stat64
132# endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000133# define stat libc_stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000134# define stat64 libc_stat64
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000135# include <sys/stat.h>
136# undef stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000137# undef stat64
Roland McGrathca16a402003-01-09 06:53:22 +0000138 /* These might be macros. */
139# undef st_atime
140# undef st_mtime
141# undef st_ctime
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000142# ifdef HPPA
143# define stat64 hpux_stat64
144# endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000145#else
146# include <sys/stat.h>
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000147#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000148
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000149#include <fcntl.h>
150
151#ifdef SVR4
152# include <sys/cred.h>
153#endif /* SVR4 */
154
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000155#ifdef HAVE_SYS_VFS_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000156#include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000157#endif
158
Roland McGrath186c5ac2002-12-15 23:58:23 +0000159#ifdef HAVE_LINUX_XATTR_H
160#include <linux/xattr.h>
161#elif defined linux
162#define XATTR_CREATE 1
163#define XATTR_REPLACE 2
164#endif
165
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000166#ifdef FREEBSD
167#include <sys/param.h>
168#include <sys/mount.h>
169#include <sys/stat.h>
John Hughes70623be2001-03-08 13:59:00 +0000170#endif
171
Dmitry V. Levin1f336e52006-10-14 20:20:46 +0000172#if _LFS64_LARGEFILE && (defined(LINUX) || defined(SVR4))
173# ifdef HAVE_INTTYPES_H
174# include <inttypes.h>
175# else
176# define PRId64 "lld"
177# define PRIu64 "llu"
178# endif
179#endif
180
John Hughes70623be2001-03-08 13:59:00 +0000181#if HAVE_LONG_LONG_OFF_T
182/*
183 * Ugly hacks for systems that have typedef long long off_t
184 */
John Hughesb8c9f772001-03-07 16:53:07 +0000185
186#define stat64 stat
187#define HAVE_STAT64 1 /* Ugly hack */
John Hughes70623be2001-03-08 13:59:00 +0000188
189#define sys_stat64 sys_stat
190#define sys_fstat64 sys_fstat
191#define sys_lstat64 sys_lstat
192#define sys_lseek64 sys_lseek
193#define sys_truncate64 sys_truncate
194#define sys_ftruncate64 sys_ftruncate
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000195#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000196
197#ifdef MAJOR_IN_SYSMACROS
198#include <sys/sysmacros.h>
199#endif
200
201#ifdef MAJOR_IN_MKDEV
202#include <sys/mkdev.h>
203#endif
204
205#ifdef HAVE_SYS_ASYNCH_H
206#include <sys/asynch.h>
207#endif
208
209#ifdef SUNOS4
210#include <ustat.h>
211#endif
212
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000213const struct xlat open_access_modes[] = {
214 { O_RDONLY, "O_RDONLY" },
215 { O_WRONLY, "O_WRONLY" },
216 { O_RDWR, "O_RDWR" },
217#ifdef O_ACCMODE
218 { O_ACCMODE, "O_ACCMODE" },
219#endif
220 { 0, NULL },
221};
222
223const struct xlat open_mode_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000224 { O_CREAT, "O_CREAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000225 { O_EXCL, "O_EXCL" },
226 { O_NOCTTY, "O_NOCTTY" },
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000227 { O_TRUNC, "O_TRUNC" },
228 { O_APPEND, "O_APPEND" },
229 { O_NONBLOCK, "O_NONBLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000230#ifdef O_SYNC
231 { O_SYNC, "O_SYNC" },
232#endif
233#ifdef O_ASYNC
234 { O_ASYNC, "O_ASYNC" },
235#endif
236#ifdef O_DSYNC
237 { O_DSYNC, "O_DSYNC" },
238#endif
239#ifdef O_RSYNC
240 { O_RSYNC, "O_RSYNC" },
241#endif
242#ifdef O_NDELAY
243 { O_NDELAY, "O_NDELAY" },
244#endif
245#ifdef O_PRIV
246 { O_PRIV, "O_PRIV" },
247#endif
248#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000249 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000250#endif
251#ifdef O_LARGEFILE
Roland McGrathfee836e2005-02-02 22:11:32 +0000252# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
253# undef O_LARGEFILE
254# ifdef SPARC64
255# define O_LARGEFILE 0x40000
256# elif defined X86_64 || defined S390X
257# define O_LARGEFILE 0100000
258# endif
259# endif
Roland McGrath663a8a02005-02-04 09:49:56 +0000260# ifdef O_LARGEFILE
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000261 { O_LARGEFILE, "O_LARGEFILE" },
Roland McGrath663a8a02005-02-04 09:49:56 +0000262# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000263#endif
264#ifdef O_DIRECTORY
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000265 { O_DIRECTORY, "O_DIRECTORY" },
266#endif
267#ifdef O_NOFOLLOW
268 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000269#endif
Roland McGrath1025c3e2005-05-09 07:40:35 +0000270#ifdef O_NOATIME
271 { O_NOATIME, "O_NOATIME" },
272#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000273#ifdef O_CLOEXEC
274 { O_CLOEXEC, "O_CLOEXEC" },
275#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000276
277#ifdef FNDELAY
278 { FNDELAY, "FNDELAY" },
279#endif
280#ifdef FAPPEND
281 { FAPPEND, "FAPPEND" },
282#endif
283#ifdef FMARK
284 { FMARK, "FMARK" },
285#endif
286#ifdef FDEFER
287 { FDEFER, "FDEFER" },
288#endif
289#ifdef FASYNC
290 { FASYNC, "FASYNC" },
291#endif
292#ifdef FSHLOCK
293 { FSHLOCK, "FSHLOCK" },
294#endif
295#ifdef FEXLOCK
296 { FEXLOCK, "FEXLOCK" },
297#endif
298#ifdef FCREAT
299 { FCREAT, "FCREAT" },
300#endif
301#ifdef FTRUNC
302 { FTRUNC, "FTRUNC" },
303#endif
304#ifdef FEXCL
305 { FEXCL, "FEXCL" },
306#endif
307#ifdef FNBIO
308 { FNBIO, "FNBIO" },
309#endif
310#ifdef FSYNC
311 { FSYNC, "FSYNC" },
312#endif
313#ifdef FNOCTTY
314 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000315#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000316#ifdef O_SHLOCK
317 { O_SHLOCK, "O_SHLOCK" },
318#endif
319#ifdef O_EXLOCK
320 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000321#endif
322 { 0, NULL },
323};
324
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000325#ifdef LINUX
326
327#ifndef AT_FDCWD
328# define AT_FDCWD -100
329#endif
330
331static void
332print_dirfd(long fd)
333{
334 if (fd == AT_FDCWD)
335 tprintf("AT_FDCWD, ");
336 else
337 tprintf("%ld, ", fd);
338}
339#endif
340
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000341/*
342 * low bits of the open(2) flags define access mode,
343 * other bits are real flags.
344 */
345void
346tprint_open_modes(struct tcb *tcp, mode_t flags)
347{
348 const char *str = xlookup(open_access_modes, flags & 3);
349
350 if (str)
351 {
352 tprintf("%s", str);
353 flags &= ~3;
354 if (!flags)
355 return;
356 tprintf("|");
357 }
358 printflags(open_mode_flags, flags, "O_???");
359}
360
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000361static int
362decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000363{
364 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000365 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000366 tprintf(", ");
367 /* flags */
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000368 tprint_open_modes(tcp, tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000369 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000370 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000371 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000372 }
373 }
374 return 0;
375}
376
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000377int
378sys_open(struct tcb *tcp)
379{
380 return decode_open(tcp, 0);
381}
382
383#ifdef LINUX
384int
385sys_openat(struct tcb *tcp)
386{
387 if (entering(tcp))
388 print_dirfd(tcp->u_arg[0]);
389 return decode_open(tcp, 1);
390}
391#endif
392
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000393#ifdef LINUXSPARC
Roland McGratha4d48532005-06-08 20:45:28 +0000394static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000395 { 0, "O_RDWR" },
396 { 1, "O_RDONLY" },
397 { 2, "O_WRONLY" },
398 { 0x80, "O_NONBLOCK" },
399 { 8, "O_APPEND" },
400 { 0x100, "O_CREAT" },
401 { 0x200, "O_TRUNC" },
402 { 0x400, "O_EXCL" },
403 { 0x800, "O_NOCTTY" },
404 { 0x10, "O_SYNC" },
405 { 0x40, "O_DSYNC" },
406 { 0x8000, "O_RSYNC" },
407 { 4, "O_NDELAY" },
408 { 0x1000, "O_PRIV" },
409 { 0, NULL },
410};
411
412int
413solaris_open(tcp)
414struct tcb *tcp;
415{
416 if (entering(tcp)) {
417 printpath(tcp, tcp->u_arg[0]);
418 tprintf(", ");
419 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000420 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000421 if (tcp->u_arg[1] & 0x100) {
422 /* mode */
423 tprintf(", %#lo", tcp->u_arg[2]);
424 }
425 }
426 return 0;
427}
428
429#endif
430
431int
432sys_creat(tcp)
433struct tcb *tcp;
434{
435 if (entering(tcp)) {
436 printpath(tcp, tcp->u_arg[0]);
437 tprintf(", %#lo", tcp->u_arg[1]);
438 }
439 return 0;
440}
441
Roland McGrathd9f816f2004-09-04 03:39:20 +0000442static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000443 { F_OK, "F_OK", },
444 { R_OK, "R_OK" },
445 { W_OK, "W_OK" },
446 { X_OK, "X_OK" },
447#ifdef EFF_ONLY_OK
448 { EFF_ONLY_OK, "EFF_ONLY_OK" },
449#endif
450#ifdef EX_OK
451 { EX_OK, "EX_OK" },
452#endif
453 { 0, NULL },
454};
455
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000456static int
457decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000458{
459 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000460 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000461 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000462 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000463 }
464 return 0;
465}
466
467int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000468sys_access(struct tcb *tcp)
469{
470 return decode_access(tcp, 0);
471}
472
473#ifdef LINUX
474int
475sys_faccessat(struct tcb *tcp)
476{
477 if (entering(tcp))
478 print_dirfd(tcp->u_arg[0]);
479 return decode_access(tcp, 1);
480}
481#endif
482
483int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000484sys_umask(tcp)
485struct tcb *tcp;
486{
487 if (entering(tcp)) {
488 tprintf("%#lo", tcp->u_arg[0]);
489 }
490 return RVAL_OCTAL;
491}
492
Roland McGrathd9f816f2004-09-04 03:39:20 +0000493static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000494 { SEEK_SET, "SEEK_SET" },
495 { SEEK_CUR, "SEEK_CUR" },
496 { SEEK_END, "SEEK_END" },
497 { 0, NULL },
498};
499
John Hughes70623be2001-03-08 13:59:00 +0000500#ifndef HAVE_LONG_LONG_OFF_T
Roland McGrath542c2c62008-05-20 01:11:56 +0000501#if defined (LINUX_MIPSN32)
502int
503sys_lseek(tcp)
504struct tcb *tcp;
505{
506 long long offset;
507 int _whence;
508
509 if (entering(tcp)) {
510 tprintf("%ld, ", tcp->u_arg[0]);
511 offset = tcp->ext_arg[1];
512 _whence = tcp->u_arg[2];
513 if (_whence == SEEK_SET)
514 tprintf("%llu, ", offset);
515 else
516 tprintf("%lld, ", offset);
517 printxval(whence, _whence, "SEEK_???");
518 }
519 return RVAL_UDECIMAL;
520}
521#else /* !LINUX_MIPSN32 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522int
523sys_lseek(tcp)
524struct tcb *tcp;
525{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000526 off_t offset;
527 int _whence;
528
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000529 if (entering(tcp)) {
530 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000531 offset = tcp->u_arg[1];
532 _whence = tcp->u_arg[2];
533 if (_whence == SEEK_SET)
534 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000535 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000536 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000537 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000538 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000539 return RVAL_UDECIMAL;
540}
Roland McGrath542c2c62008-05-20 01:11:56 +0000541#endif /* LINUX_MIPSN32 */
John Hughes5a826b82001-03-07 13:21:24 +0000542#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000543
Michal Ludvig53b320f2002-09-23 13:30:09 +0000544#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000545int
546sys_llseek (tcp)
547struct tcb *tcp;
548{
549 if (entering(tcp)) {
Roland McGrath8c304bc2004-10-19 22:59:55 +0000550 /*
551 * This one call takes explicitly two 32-bit arguments hi, lo,
552 * rather than one 64-bit argument for which LONG_LONG works
553 * appropriate for the native byte order.
554 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000555 if (tcp->u_arg[4] == SEEK_SET)
556 tprintf("%ld, %llu, ", tcp->u_arg[0],
Roland McGrath8c304bc2004-10-19 22:59:55 +0000557 (((long long int) tcp->u_arg[1]) << 32
558 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000559 else
560 tprintf("%ld, %lld, ", tcp->u_arg[0],
Roland McGrath8c304bc2004-10-19 22:59:55 +0000561 (((long long int) tcp->u_arg[1]) << 32
562 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000563 }
564 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000565 long long int off;
566 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000567 tprintf("%#lx, ", tcp->u_arg[3]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000568 else
569 tprintf("[%llu], ", off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000570 printxval(whence, tcp->u_arg[4], "SEEK_???");
571 }
572 return 0;
573}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000574
575int
576sys_readahead (tcp)
577struct tcb *tcp;
578{
579 if (entering(tcp)) {
580 tprintf("%ld, %lld, %ld", tcp->u_arg[0],
Roland McGrath542c2c62008-05-20 01:11:56 +0000581# if defined LINUX_MIPSN32
582 tcp->ext_arg[1], tcp->u_arg[2]
583# elif defined IA64 || defined X86_64 || defined ALPHA || defined LINUX_MIPSN64
Roland McGrath186c5ac2002-12-15 23:58:23 +0000584 (long long int) tcp->u_arg[1], tcp->u_arg[2]
585# else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +0000586 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]
Roland McGrath186c5ac2002-12-15 23:58:23 +0000587# endif
588 );
589 }
590 return 0;
591}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000592#endif
593
John Hughes70623be2001-03-08 13:59:00 +0000594#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000595int
596sys_lseek64 (tcp)
597struct tcb *tcp;
598{
599 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000600 long long offset;
601 ALIGN64 (tcp, 1); /* FreeBSD aligns off_t args */
John Hughes0c79e012001-03-08 14:40:06 +0000602 offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +0000603 if (tcp->u_arg[3] == SEEK_SET)
604 tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
605 else
606 tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
607 printxval(whence, tcp->u_arg[3], "SEEK_???");
608 }
609 return RVAL_LUDECIMAL;
610}
611#endif
612
John Hughes70623be2001-03-08 13:59:00 +0000613#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000614int
615sys_truncate(tcp)
616struct tcb *tcp;
617{
618 if (entering(tcp)) {
619 printpath(tcp, tcp->u_arg[0]);
620 tprintf(", %lu", tcp->u_arg[1]);
621 }
622 return 0;
623}
John Hughes5a826b82001-03-07 13:21:24 +0000624#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000625
John Hughes70623be2001-03-08 13:59:00 +0000626#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000627int
628sys_truncate64(tcp)
629struct tcb *tcp;
630{
631 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000632 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000633 printpath(tcp, tcp->u_arg[0]);
John Hughes0c79e012001-03-08 14:40:06 +0000634 tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000635 }
636 return 0;
637}
638#endif
639
John Hughes70623be2001-03-08 13:59:00 +0000640#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000641int
642sys_ftruncate(tcp)
643struct tcb *tcp;
644{
645 if (entering(tcp)) {
646 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
647 }
648 return 0;
649}
John Hughes5a826b82001-03-07 13:21:24 +0000650#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000651
John Hughes70623be2001-03-08 13:59:00 +0000652#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000653int
654sys_ftruncate64(tcp)
655struct tcb *tcp;
656{
657 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000658 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000659 tprintf("%ld, %llu", tcp->u_arg[0],
John Hughes0c79e012001-03-08 14:40:06 +0000660 LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000661 }
662 return 0;
663}
664#endif
665
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000666/* several stats */
667
Roland McGrathd9f816f2004-09-04 03:39:20 +0000668static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000669 { S_IFREG, "S_IFREG" },
670 { S_IFSOCK, "S_IFSOCK" },
671 { S_IFIFO, "S_IFIFO" },
672 { S_IFLNK, "S_IFLNK" },
673 { S_IFDIR, "S_IFDIR" },
674 { S_IFBLK, "S_IFBLK" },
675 { S_IFCHR, "S_IFCHR" },
676 { 0, NULL },
677};
678
Roland McGrathf9c49b22004-10-06 22:11:54 +0000679static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000680sprintmode(mode)
681int mode;
682{
683 static char buf[64];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000684 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000685
686 if ((mode & S_IFMT) == 0)
687 s = "";
688 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
689 sprintf(buf, "%#o", mode);
690 return buf;
691 }
692 sprintf(buf, "%s%s%s%s", s,
693 (mode & S_ISUID) ? "|S_ISUID" : "",
694 (mode & S_ISGID) ? "|S_ISGID" : "",
695 (mode & S_ISVTX) ? "|S_ISVTX" : "");
696 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
697 if (mode)
698 sprintf(buf + strlen(buf), "|%#o", mode);
699 s = (*buf == '|') ? buf + 1 : buf;
700 return *s ? s : "0";
701}
702
703static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000704sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000705{
706 struct tm *tmp;
707 static char buf[32];
708
709 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000710 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000711 return buf;
712 }
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000713 if ((tmp = localtime(&t)))
714 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
715 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
716 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
717 else
718 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
719
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000720 return buf;
721}
722
723#ifdef LINUXSPARC
724typedef struct {
725 int tv_sec;
726 int tv_nsec;
727} timestruct_t;
728
729struct solstat {
730 unsigned st_dev;
731 int st_pad1[3]; /* network id */
732 unsigned st_ino;
733 unsigned st_mode;
734 unsigned st_nlink;
735 unsigned st_uid;
736 unsigned st_gid;
737 unsigned st_rdev;
738 int st_pad2[2];
739 int st_size;
740 int st_pad3; /* st_size, off_t expansion */
741 timestruct_t st_atime;
742 timestruct_t st_mtime;
743 timestruct_t st_ctime;
744 int st_blksize;
745 int st_blocks;
746 char st_fstype[16];
747 int st_pad4[8]; /* expansion area */
748};
749
750static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000751printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000752{
753 struct solstat statbuf;
754
755 if (!addr) {
756 tprintf("NULL");
757 return;
758 }
759 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000760 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000761 return;
762 }
763 if (umove(tcp, addr, &statbuf) < 0) {
764 tprintf("{...}");
765 return;
766 }
767 if (!abbrev(tcp)) {
768 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
769 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
770 (unsigned long) (statbuf.st_dev & 0x3ffff),
771 (unsigned long) statbuf.st_ino,
772 sprintmode(statbuf.st_mode));
773 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
774 (unsigned long) statbuf.st_nlink,
775 (unsigned long) statbuf.st_uid,
776 (unsigned long) statbuf.st_gid);
777 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
778 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
779 }
780 else
781 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
782 switch (statbuf.st_mode & S_IFMT) {
783 case S_IFCHR: case S_IFBLK:
784 tprintf("st_rdev=makedev(%lu, %lu), ",
785 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
786 (unsigned long) (statbuf.st_rdev & 0x3ffff));
787 break;
788 default:
789 tprintf("st_size=%u, ", statbuf.st_size);
790 break;
791 }
792 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000793 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
794 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
795 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000796 }
797 else
798 tprintf("...}");
799}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000800
801#if defined (SPARC64)
802static void
803printstat_sparc64(tcp, addr)
804struct tcb *tcp;
805long addr;
806{
807 struct stat_sparc64 statbuf;
808
809 if (!addr) {
810 tprintf("NULL");
811 return;
812 }
813 if (syserror(tcp) || !verbose(tcp)) {
814 tprintf("%#lx", addr);
815 return;
816 }
817 if (umove(tcp, addr, &statbuf) < 0) {
818 tprintf("{...}");
819 return;
820 }
821
822 if (!abbrev(tcp)) {
823 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
824 (unsigned long) major(statbuf.st_dev),
825 (unsigned long) minor(statbuf.st_dev),
826 (unsigned long) statbuf.st_ino,
827 sprintmode(statbuf.st_mode));
828 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
829 (unsigned long) statbuf.st_nlink,
830 (unsigned long) statbuf.st_uid,
831 (unsigned long) statbuf.st_gid);
832 tprintf("st_blksize=%lu, ",
833 (unsigned long) statbuf.st_blksize);
834 tprintf("st_blocks=%lu, ",
835 (unsigned long) statbuf.st_blocks);
836 }
837 else
838 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
839 switch (statbuf.st_mode & S_IFMT) {
840 case S_IFCHR: case S_IFBLK:
841 tprintf("st_rdev=makedev(%lu, %lu), ",
842 (unsigned long) major(statbuf.st_rdev),
843 (unsigned long) minor(statbuf.st_rdev));
844 break;
845 default:
846 tprintf("st_size=%lu, ", statbuf.st_size);
847 break;
848 }
849 if (!abbrev(tcp)) {
850 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
851 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
852 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
853 tprintf("}");
854 }
855 else
856 tprintf("...}");
857}
858#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000859#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000860
Roland McGratha4d48532005-06-08 20:45:28 +0000861static const struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000862#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000863 { UF_NODUMP, "UF_NODUMP" },
864 { UF_IMMUTABLE, "UF_IMMUTABLE" },
865 { UF_APPEND, "UF_APPEND" },
866 { UF_OPAQUE, "UF_OPAQUE" },
867 { UF_NOUNLINK, "UF_NOUNLINK" },
868 { SF_ARCHIVED, "SF_ARCHIVED" },
869 { SF_IMMUTABLE, "SF_IMMUTABLE" },
870 { SF_APPEND, "SF_APPEND" },
871 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000872#elif UNIXWARE >= 2
873#ifdef _S_ISMLD
874 { _S_ISMLD, "_S_ISMLD" },
875#endif
876#ifdef _S_ISMOUNTED
877 { _S_ISMOUNTED, "_S_ISMOUNTED" },
878#endif
879#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000880 { 0, NULL },
881};
882
John Hughesc0fc3fd2001-03-08 16:10:40 +0000883#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000884int
885sys_chflags(tcp)
886struct tcb *tcp;
887{
888 if (entering(tcp)) {
889 printpath(tcp, tcp->u_arg[0]);
890 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000891 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000892 }
893 return 0;
894}
895
896int
897sys_fchflags(tcp)
898struct tcb *tcp;
899{
900 if (entering(tcp)) {
901 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000902 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000903 }
904 return 0;
905}
906#endif
907
John Hughes70623be2001-03-08 13:59:00 +0000908#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000909static void
910realprintstat(tcp, statbuf)
911struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000912struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000913{
914 if (!abbrev(tcp)) {
915 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
916 (unsigned long) major(statbuf->st_dev),
917 (unsigned long) minor(statbuf->st_dev),
918 (unsigned long) statbuf->st_ino,
919 sprintmode(statbuf->st_mode));
920 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
921 (unsigned long) statbuf->st_nlink,
922 (unsigned long) statbuf->st_uid,
923 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000924#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000925 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000926#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
927#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000928 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000929#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000930 }
931 else
932 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
933 switch (statbuf->st_mode & S_IFMT) {
934 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000935#ifdef HAVE_STRUCT_STAT_ST_RDEV
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000936 tprintf("st_rdev=makedev(%lu, %lu), ",
937 (unsigned long) major(statbuf->st_rdev),
938 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000939#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000940 tprintf("st_size=makedev(%lu, %lu), ",
941 (unsigned long) major(statbuf->st_size),
942 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000943#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000944 break;
945 default:
946 tprintf("st_size=%lu, ", statbuf->st_size);
947 break;
948 }
949 if (!abbrev(tcp)) {
950 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
951 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000952 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000953#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000954 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000955 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000956#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000957#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000958 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
959#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000960#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000961 tprintf(", st_level=%ld", statbuf->st_level);
962#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000963#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000964 tprintf(", st_fstype=%.*s",
965 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
966#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000967#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000968 tprintf(", st_gen=%u", statbuf->st_gen);
969#endif
970 tprintf("}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000971 }
972 else
973 tprintf("...}");
974}
975
Nate Sammons771a6ff1999-04-05 22:39:31 +0000976
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000977static void
978printstat(tcp, addr)
979struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000980long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000981{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000982 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000983
984#ifdef LINUXSPARC
985 if (current_personality == 1) {
986 printstatsol(tcp, addr);
987 return;
988 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000989#ifdef SPARC64
990 else if (current_personality == 2) {
991 printstat_sparc64(tcp, addr);
992 return;
993 }
994#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000995#endif /* LINUXSPARC */
996
997 if (!addr) {
998 tprintf("NULL");
999 return;
1000 }
1001 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001002 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001003 return;
1004 }
1005 if (umove(tcp, addr, &statbuf) < 0) {
1006 tprintf("{...}");
1007 return;
1008 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001009
1010 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001011}
John Hughes70623be2001-03-08 13:59:00 +00001012#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001013
Roland McGrathe6d0f712007-08-07 01:22:49 +00001014#if !defined HAVE_STAT64 && defined LINUX && defined X86_64
1015/*
1016 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1017 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1018 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1019 * __GNUC__ is needed for the required __attribute__ below.
1020 */
1021struct stat64 {
1022 unsigned long long st_dev;
1023 unsigned char __pad0[4];
1024 unsigned int __st_ino;
1025 unsigned int st_mode;
1026 unsigned int st_nlink;
1027 unsigned int st_uid;
1028 unsigned int st_gid;
1029 unsigned long long st_rdev;
1030 unsigned char __pad3[4];
1031 long long st_size;
1032 unsigned int st_blksize;
1033 unsigned long long st_blocks;
1034 unsigned int st_atime;
1035 unsigned int st_atime_nsec;
1036 unsigned int st_mtime;
1037 unsigned int st_mtime_nsec;
1038 unsigned int st_ctime;
1039 unsigned int st_ctime_nsec;
1040 unsigned long long st_ino;
1041} __attribute__((packed));
1042# define HAVE_STAT64 1
1043# define STAT64_SIZE 96
1044#endif
1045
Wichert Akkermanc7926982000-04-10 22:22:31 +00001046#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001047static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001048printstat64(tcp, addr)
1049struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001050long addr;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001051{
1052 struct stat64 statbuf;
1053
Roland McGrathe6d0f712007-08-07 01:22:49 +00001054#ifdef STAT64_SIZE
1055 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1056#endif
1057
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001058#ifdef LINUXSPARC
1059 if (current_personality == 1) {
1060 printstatsol(tcp, addr);
1061 return;
1062 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001063#ifdef SPARC64
1064 else if (current_personality == 2) {
1065 printstat_sparc64(tcp, addr);
1066 return;
1067 }
1068#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001069#endif /* LINUXSPARC */
1070
1071 if (!addr) {
1072 tprintf("NULL");
1073 return;
1074 }
1075 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001076 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001077 return;
1078 }
1079 if (umove(tcp, addr, &statbuf) < 0) {
1080 tprintf("{...}");
1081 return;
1082 }
1083
1084 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001085#ifdef HAVE_LONG_LONG
1086 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1087#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001088 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001089#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001090 (unsigned long) major(statbuf.st_dev),
1091 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001092#ifdef HAVE_LONG_LONG
1093 (unsigned long long) statbuf.st_ino,
1094#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001095 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001096#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001097 sprintmode(statbuf.st_mode));
1098 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1099 (unsigned long) statbuf.st_nlink,
1100 (unsigned long) statbuf.st_uid,
1101 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001102#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001103 tprintf("st_blksize=%lu, ",
1104 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001105#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1106#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001107 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001108#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001109 }
1110 else
1111 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1112 switch (statbuf.st_mode & S_IFMT) {
1113 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001114#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001115 tprintf("st_rdev=makedev(%lu, %lu), ",
1116 (unsigned long) major(statbuf.st_rdev),
1117 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001118#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001119 tprintf("st_size=makedev(%lu, %lu), ",
1120 (unsigned long) major(statbuf.st_size),
1121 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001122#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001123 break;
1124 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001125#ifdef HAVE_LONG_LONG
1126 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1127#else
1128 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1129#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001130 break;
1131 }
1132 if (!abbrev(tcp)) {
1133 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1134 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001135 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001136#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +00001137 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001138 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001139#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001140#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001141 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1142#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001143#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001144 tprintf(", st_level=%ld", statbuf.st_level);
1145#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001146#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001147 tprintf(", st_fstype=%.*s",
1148 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1149#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001150#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001151 tprintf(", st_gen=%u", statbuf.st_gen);
1152#endif
1153 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001154 }
1155 else
1156 tprintf("...}");
1157}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001158#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001159
Roland McGrath79db8af2003-06-27 21:20:09 +00001160#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001161static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001162convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001163const struct __old_kernel_stat *oldbuf;
1164struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001165{
1166 newbuf->st_dev=oldbuf->st_dev;
1167 newbuf->st_ino=oldbuf->st_ino;
1168 newbuf->st_mode=oldbuf->st_mode;
1169 newbuf->st_nlink=oldbuf->st_nlink;
1170 newbuf->st_uid=oldbuf->st_uid;
1171 newbuf->st_gid=oldbuf->st_gid;
1172 newbuf->st_rdev=oldbuf->st_rdev;
1173 newbuf->st_size=oldbuf->st_size;
1174 newbuf->st_atime=oldbuf->st_atime;
1175 newbuf->st_mtime=oldbuf->st_mtime;
1176 newbuf->st_ctime=oldbuf->st_ctime;
1177 newbuf->st_blksize=0; /* not supported in old_stat */
1178 newbuf->st_blocks=0; /* not supported in old_stat */
1179}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001180
1181
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001182static void
1183printoldstat(tcp, addr)
1184struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001185long addr;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001186{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001187 struct __old_kernel_stat statbuf;
1188 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001189
1190#ifdef LINUXSPARC
1191 if (current_personality == 1) {
1192 printstatsol(tcp, addr);
1193 return;
1194 }
1195#endif /* LINUXSPARC */
1196
1197 if (!addr) {
1198 tprintf("NULL");
1199 return;
1200 }
1201 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001202 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001203 return;
1204 }
1205 if (umove(tcp, addr, &statbuf) < 0) {
1206 tprintf("{...}");
1207 return;
1208 }
1209
1210 convertoldstat(&statbuf, &newstatbuf);
1211 realprintstat(tcp, &newstatbuf);
1212}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001213#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001214
John Hughes70623be2001-03-08 13:59:00 +00001215#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001216int
1217sys_stat(tcp)
1218struct tcb *tcp;
1219{
1220 if (entering(tcp)) {
1221 printpath(tcp, tcp->u_arg[0]);
1222 tprintf(", ");
1223 } else {
1224 printstat(tcp, tcp->u_arg[1]);
1225 }
1226 return 0;
1227}
John Hughesb8c9f772001-03-07 16:53:07 +00001228#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001229
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001230int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001231sys_stat64(tcp)
1232struct tcb *tcp;
1233{
1234#ifdef HAVE_STAT64
1235 if (entering(tcp)) {
1236 printpath(tcp, tcp->u_arg[0]);
1237 tprintf(", ");
1238 } else {
1239 printstat64(tcp, tcp->u_arg[1]);
1240 }
1241 return 0;
1242#else
1243 return printargs(tcp);
1244#endif
1245}
1246
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001247#ifdef LINUX
1248static const struct xlat fstatatflags[] = {
1249#ifndef AT_SYMLINK_NOFOLLOW
1250# define AT_SYMLINK_NOFOLLOW 0x100
1251#endif
1252 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1253 { 0, NULL },
1254};
Roland McGrath6afc5652007-07-24 01:57:11 +00001255#define utimensatflags fstatatflags
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001256
1257int
1258sys_newfstatat(struct tcb *tcp)
1259{
1260 if (entering(tcp)) {
1261 print_dirfd(tcp->u_arg[0]);
1262 printpath(tcp, tcp->u_arg[1]);
1263 tprintf(", ");
1264 } else {
Roland McGrath359c8ed2007-07-05 19:01:17 +00001265#if defined HAVE_STAT64 && !(defined POWERPC && defined __powerpc64__)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001266 printstat64(tcp, tcp->u_arg[2]);
1267#else
1268 printstat(tcp, tcp->u_arg[2]);
1269#endif
1270 tprintf(", ");
1271 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1272 }
1273 return 0;
1274}
1275#endif
1276
Roland McGrath79db8af2003-06-27 21:20:09 +00001277#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001278int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001279sys_oldstat(tcp)
1280struct tcb *tcp;
1281{
1282 if (entering(tcp)) {
1283 printpath(tcp, tcp->u_arg[0]);
1284 tprintf(", ");
1285 } else {
1286 printoldstat(tcp, tcp->u_arg[1]);
1287 }
1288 return 0;
1289}
Roland McGrath79db8af2003-06-27 21:20:09 +00001290#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001291
John Hughes70623be2001-03-08 13:59:00 +00001292#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001293int
1294sys_fstat(tcp)
1295struct tcb *tcp;
1296{
1297 if (entering(tcp))
1298 tprintf("%ld, ", tcp->u_arg[0]);
1299 else {
1300 printstat(tcp, tcp->u_arg[1]);
1301 }
1302 return 0;
1303}
John Hughesb8c9f772001-03-07 16:53:07 +00001304#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001305
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001306int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001307sys_fstat64(tcp)
1308struct tcb *tcp;
1309{
1310#ifdef HAVE_STAT64
1311 if (entering(tcp))
1312 tprintf("%ld, ", tcp->u_arg[0]);
1313 else {
1314 printstat64(tcp, tcp->u_arg[1]);
1315 }
1316 return 0;
1317#else
1318 return printargs(tcp);
1319#endif
1320}
1321
Roland McGrath79db8af2003-06-27 21:20:09 +00001322#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001323int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001324sys_oldfstat(tcp)
1325struct tcb *tcp;
1326{
1327 if (entering(tcp))
1328 tprintf("%ld, ", tcp->u_arg[0]);
1329 else {
1330 printoldstat(tcp, tcp->u_arg[1]);
1331 }
1332 return 0;
1333}
Roland McGrath79db8af2003-06-27 21:20:09 +00001334#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001335
John Hughes70623be2001-03-08 13:59:00 +00001336#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001337int
1338sys_lstat(tcp)
1339struct tcb *tcp;
1340{
1341 if (entering(tcp)) {
1342 printpath(tcp, tcp->u_arg[0]);
1343 tprintf(", ");
1344 } else {
1345 printstat(tcp, tcp->u_arg[1]);
1346 }
1347 return 0;
1348}
John Hughesb8c9f772001-03-07 16:53:07 +00001349#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001350
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001351int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001352sys_lstat64(tcp)
1353struct tcb *tcp;
1354{
1355#ifdef HAVE_STAT64
1356 if (entering(tcp)) {
1357 printpath(tcp, tcp->u_arg[0]);
1358 tprintf(", ");
1359 } else {
1360 printstat64(tcp, tcp->u_arg[1]);
1361 }
1362 return 0;
1363#else
1364 return printargs(tcp);
1365#endif
1366}
1367
Roland McGrath79db8af2003-06-27 21:20:09 +00001368#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001369int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001370sys_oldlstat(tcp)
1371struct tcb *tcp;
1372{
1373 if (entering(tcp)) {
1374 printpath(tcp, tcp->u_arg[0]);
1375 tprintf(", ");
1376 } else {
1377 printoldstat(tcp, tcp->u_arg[1]);
1378 }
1379 return 0;
1380}
Roland McGrath79db8af2003-06-27 21:20:09 +00001381#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001382
1383
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001384#if defined(SVR4) || defined(LINUXSPARC)
1385
1386int
1387sys_xstat(tcp)
1388struct tcb *tcp;
1389{
1390 if (entering(tcp)) {
1391 tprintf("%ld, ", tcp->u_arg[0]);
1392 printpath(tcp, tcp->u_arg[1]);
1393 tprintf(", ");
1394 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001395#ifdef _STAT64_VER
1396 if (tcp->u_arg[0] == _STAT64_VER)
1397 printstat64 (tcp, tcp->u_arg[2]);
1398 else
1399#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001400 printstat(tcp, tcp->u_arg[2]);
1401 }
1402 return 0;
1403}
1404
1405int
1406sys_fxstat(tcp)
1407struct tcb *tcp;
1408{
1409 if (entering(tcp))
1410 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1411 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001412#ifdef _STAT64_VER
1413 if (tcp->u_arg[0] == _STAT64_VER)
1414 printstat64 (tcp, tcp->u_arg[2]);
1415 else
1416#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001417 printstat(tcp, tcp->u_arg[2]);
1418 }
1419 return 0;
1420}
1421
1422int
1423sys_lxstat(tcp)
1424struct tcb *tcp;
1425{
1426 if (entering(tcp)) {
1427 tprintf("%ld, ", tcp->u_arg[0]);
1428 printpath(tcp, tcp->u_arg[1]);
1429 tprintf(", ");
1430 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001431#ifdef _STAT64_VER
1432 if (tcp->u_arg[0] == _STAT64_VER)
1433 printstat64 (tcp, tcp->u_arg[2]);
1434 else
1435#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001436 printstat(tcp, tcp->u_arg[2]);
1437 }
1438 return 0;
1439}
1440
1441int
1442sys_xmknod(tcp)
1443struct tcb *tcp;
1444{
1445 int mode = tcp->u_arg[2];
1446
1447 if (entering(tcp)) {
1448 tprintf("%ld, ", tcp->u_arg[0]);
1449 printpath(tcp, tcp->u_arg[1]);
1450 tprintf(", %s", sprintmode(mode));
1451 switch (mode & S_IFMT) {
1452 case S_IFCHR: case S_IFBLK:
1453#ifdef LINUXSPARC
1454 tprintf(", makedev(%lu, %lu)",
1455 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1456 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001457#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001458 tprintf(", makedev(%lu, %lu)",
1459 (unsigned long) major(tcp->u_arg[3]),
1460 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001461#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001462 break;
1463 default:
1464 break;
1465 }
1466 }
1467 return 0;
1468}
1469
Wichert Akkerman8829a551999-06-11 13:18:40 +00001470#ifdef HAVE_SYS_ACL_H
1471
1472#include <sys/acl.h>
1473
Roland McGratha4d48532005-06-08 20:45:28 +00001474static const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001475#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001476 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001477#endif
1478#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001479 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001480#endif
1481#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001482 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001483#endif
1484#ifdef ACL_GET
1485 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001486#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001487#ifdef ACL_SET
1488 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001489#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001490#ifdef ACL_CNT
1491 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001492#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001493 { 0, NULL },
1494};
1495
1496int
1497sys_acl(tcp)
1498struct tcb *tcp;
1499{
1500 if (entering(tcp)) {
1501 printpath(tcp, tcp->u_arg[0]);
1502 tprintf(", ");
1503 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1504 tprintf(", %ld", tcp->u_arg[2]);
1505 /*
1506 * FIXME - dump out the list of aclent_t's pointed to
1507 * by "tcp->u_arg[3]" if it's not NULL.
1508 */
1509 if (tcp->u_arg[3])
1510 tprintf(", %#lx", tcp->u_arg[3]);
1511 else
1512 tprintf(", NULL");
1513 }
1514 return 0;
1515}
1516
1517
1518int
1519sys_facl(tcp)
1520struct tcb *tcp;
1521{
1522 if (entering(tcp)) {
1523 tprintf("%ld, ", tcp->u_arg[0]);
1524 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1525 tprintf(", %ld", tcp->u_arg[2]);
1526 /*
1527 * FIXME - dump out the list of aclent_t's pointed to
1528 * by "tcp->u_arg[3]" if it's not NULL.
1529 */
1530 if (tcp->u_arg[3])
1531 tprintf(", %#lx", tcp->u_arg[3]);
1532 else
1533 tprintf(", NULL");
1534 }
1535 return 0;
1536}
1537
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001538
Roland McGratha4d48532005-06-08 20:45:28 +00001539static const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001540#ifdef IPC_SHM
1541 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001542#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001543#ifdef IPC_SEM
1544 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001545#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001546#ifdef IPC_MSG
1547 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001548#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001549 { 0, NULL },
1550};
1551
1552
1553int
1554sys_aclipc(tcp)
1555struct tcb *tcp;
1556{
1557 if (entering(tcp)) {
1558 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1559 tprintf(", %#lx, ", tcp->u_arg[1]);
1560 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1561 tprintf(", %ld", tcp->u_arg[3]);
1562 /*
1563 * FIXME - dump out the list of aclent_t's pointed to
1564 * by "tcp->u_arg[4]" if it's not NULL.
1565 */
1566 if (tcp->u_arg[4])
1567 tprintf(", %#lx", tcp->u_arg[4]);
1568 else
1569 tprintf(", NULL");
1570 }
1571 return 0;
1572}
1573
1574
1575
Wichert Akkerman8829a551999-06-11 13:18:40 +00001576#endif /* HAVE_SYS_ACL_H */
1577
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001578#endif /* SVR4 || LINUXSPARC */
1579
Michal Ludvig53b320f2002-09-23 13:30:09 +00001580#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001581
Roland McGrathd9f816f2004-09-04 03:39:20 +00001582static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001583 { 0x73757245, "CODA_SUPER_MAGIC" },
1584 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1585 { 0x1373, "DEVFS_SUPER_MAGIC" },
1586 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1587 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001588 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1589 { 0xef53, "EXT2_SUPER_MAGIC" },
1590 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001591 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001592 { 0x9660, "ISOFS_SUPER_MAGIC" },
1593 { 0x137f, "MINIX_SUPER_MAGIC" },
1594 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001595 { 0x2468, "MINIX2_SUPER_MAGIC" },
1596 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001597 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001598 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001599 { 0x6969, "NFS_SUPER_MAGIC" },
1600 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001601 { 0x002f, "QNX4_SUPER_MAGIC" },
1602 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1603 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1604 { 0x517b, "SMB_SUPER_MAGIC" },
1605 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1606 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1607 { 0x00011954, "UFS_MAGIC" },
1608 { 0x54190100, "UFS_CIGAM" },
1609 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001610 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001611 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001612 { 0, NULL },
1613};
1614
Michal Ludvig53b320f2002-09-23 13:30:09 +00001615#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001616
1617#ifndef SVR4
1618
Roland McGrathf9c49b22004-10-06 22:11:54 +00001619static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001620sprintfstype(magic)
1621int magic;
1622{
1623 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001624#ifdef LINUX
Roland McGrathf9c49b22004-10-06 22:11:54 +00001625 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001626
1627 s = xlookup(fsmagic, magic);
1628 if (s) {
1629 sprintf(buf, "\"%s\"", s);
1630 return buf;
1631 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001632#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001633 sprintf(buf, "%#x", magic);
1634 return buf;
1635}
1636
1637static void
1638printstatfs(tcp, addr)
1639struct tcb *tcp;
1640long addr;
1641{
1642 struct statfs statbuf;
1643
1644 if (syserror(tcp) || !verbose(tcp)) {
1645 tprintf("%#lx", addr);
1646 return;
1647 }
1648 if (umove(tcp, addr, &statbuf) < 0) {
1649 tprintf("{...}");
1650 return;
1651 }
1652#ifdef ALPHA
1653
1654 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1655 sprintfstype(statbuf.f_type),
1656 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001657 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1658 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1659 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1660 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001661#else /* !ALPHA */
1662 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1663 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001664 (unsigned long)statbuf.f_bsize,
1665 (unsigned long)statbuf.f_blocks,
1666 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001667 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1668 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001669 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001670 (unsigned long)statbuf.f_ffree,
1671 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001672#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001673 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001674#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001675#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001676#ifdef _STATFS_F_FRSIZE
1677 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1678#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001679 tprintf("}");
1680}
1681
1682int
1683sys_statfs(tcp)
1684struct tcb *tcp;
1685{
1686 if (entering(tcp)) {
1687 printpath(tcp, tcp->u_arg[0]);
1688 tprintf(", ");
1689 } else {
1690 printstatfs(tcp, tcp->u_arg[1]);
1691 }
1692 return 0;
1693}
1694
1695int
1696sys_fstatfs(tcp)
1697struct tcb *tcp;
1698{
1699 if (entering(tcp)) {
1700 tprintf("%lu, ", tcp->u_arg[0]);
1701 } else {
1702 printstatfs(tcp, tcp->u_arg[1]);
1703 }
1704 return 0;
1705}
1706
Roland McGrathab147c52003-07-17 09:03:02 +00001707#ifdef LINUX
1708static void
1709printstatfs64(tcp, addr)
1710struct tcb *tcp;
1711long addr;
1712{
1713 struct statfs64 statbuf;
1714
1715 if (syserror(tcp) || !verbose(tcp)) {
1716 tprintf("%#lx", addr);
1717 return;
1718 }
1719 if (umove(tcp, addr, &statbuf) < 0) {
1720 tprintf("{...}");
1721 return;
1722 }
Roland McGrath08738432005-06-03 02:40:39 +00001723 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001724 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001725 (unsigned long long)statbuf.f_bsize,
1726 (unsigned long long)statbuf.f_blocks,
1727 (unsigned long long)statbuf.f_bfree);
1728 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1729 (unsigned long long)statbuf.f_bavail,
1730 (unsigned long long)statbuf.f_files,
1731 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001732 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1733 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001734#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001735 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001736#endif
1737 tprintf("}");
1738}
1739
1740int
1741sys_statfs64(tcp)
1742struct tcb *tcp;
1743{
1744 if (entering(tcp)) {
1745 printpath(tcp, tcp->u_arg[0]);
1746 tprintf(", %lu, ", tcp->u_arg[1]);
1747 } else {
1748 if (tcp->u_arg[1] == sizeof (struct statfs64))
1749 printstatfs64(tcp, tcp->u_arg[2]);
1750 else
1751 tprintf("{???}");
1752 }
1753 return 0;
1754}
1755
1756int
1757sys_fstatfs64(tcp)
1758struct tcb *tcp;
1759{
1760 if (entering(tcp)) {
1761 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1762 } else {
1763 if (tcp->u_arg[1] == sizeof (struct statfs64))
1764 printstatfs64(tcp, tcp->u_arg[2]);
1765 else
1766 tprintf("{???}");
1767 }
1768 return 0;
1769}
1770#endif
1771
Michal Ludvig53b320f2002-09-23 13:30:09 +00001772#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001773
1774int
1775osf_statfs(tcp)
1776struct tcb *tcp;
1777{
1778 if (entering(tcp)) {
1779 printpath(tcp, tcp->u_arg[0]);
1780 tprintf(", ");
1781 } else {
1782 printstatfs(tcp, tcp->u_arg[1]);
1783 tprintf(", %lu", tcp->u_arg[2]);
1784 }
1785 return 0;
1786}
1787
1788int
1789osf_fstatfs(tcp)
1790struct tcb *tcp;
1791{
1792 if (entering(tcp)) {
1793 tprintf("%lu, ", tcp->u_arg[0]);
1794 } else {
1795 printstatfs(tcp, tcp->u_arg[1]);
1796 tprintf(", %lu", tcp->u_arg[2]);
1797 }
1798 return 0;
1799}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001800#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001801
1802#endif /* !SVR4 */
1803
1804#ifdef SUNOS4
1805
1806int
1807sys_ustat(tcp)
1808struct tcb *tcp;
1809{
1810 struct ustat statbuf;
1811
1812 if (entering(tcp)) {
1813 tprintf("makedev(%lu, %lu), ",
1814 (long) major(tcp->u_arg[0]),
1815 (long) minor(tcp->u_arg[0]));
1816 }
1817 else {
1818 if (syserror(tcp) || !verbose(tcp))
1819 tprintf("%#lx", tcp->u_arg[1]);
1820 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1821 tprintf("{...}");
1822 else {
1823 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1824 statbuf.f_tfree, statbuf.f_tinode);
1825 tprintf("f_fname=\"%.*s\", ",
1826 (int) sizeof(statbuf.f_fname),
1827 statbuf.f_fname);
1828 tprintf("f_fpack=\"%.*s\"}",
1829 (int) sizeof(statbuf.f_fpack),
1830 statbuf.f_fpack);
1831 }
1832 }
1833 return 0;
1834}
1835
1836#endif /* SUNOS4 */
1837
Wichert Akkermanc7926982000-04-10 22:22:31 +00001838int
1839sys_pivotroot(tcp)
1840struct tcb *tcp;
1841{
1842 if (entering(tcp)) {
1843 printpath(tcp, tcp->u_arg[0]);
1844 tprintf(", ");
1845 printpath(tcp, tcp->u_arg[1]);
1846 }
1847 return 0;
1848}
1849
1850
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001851/* directory */
1852int
1853sys_chdir(tcp)
1854struct tcb *tcp;
1855{
1856 if (entering(tcp)) {
1857 printpath(tcp, tcp->u_arg[0]);
1858 }
1859 return 0;
1860}
1861
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001862static int
1863decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001864{
1865 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001866 printpath(tcp, tcp->u_arg[offset]);
1867 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001868 }
1869 return 0;
1870}
1871
1872int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001873sys_mkdir(struct tcb *tcp)
1874{
1875 return decode_mkdir(tcp, 0);
1876}
1877
1878#ifdef LINUX
1879int
1880sys_mkdirat(struct tcb *tcp)
1881{
1882 if (entering(tcp))
1883 print_dirfd(tcp->u_arg[0]);
1884 return decode_mkdir(tcp, 1);
1885}
1886#endif
1887
1888int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001889sys_rmdir(tcp)
1890struct tcb *tcp;
1891{
1892 if (entering(tcp)) {
1893 printpath(tcp, tcp->u_arg[0]);
1894 }
1895 return 0;
1896}
1897
1898int
1899sys_fchdir(tcp)
1900struct tcb *tcp;
1901{
1902 if (entering(tcp)) {
1903 tprintf("%ld", tcp->u_arg[0]);
1904 }
1905 return 0;
1906}
1907
1908int
1909sys_chroot(tcp)
1910struct tcb *tcp;
1911{
1912 if (entering(tcp)) {
1913 printpath(tcp, tcp->u_arg[0]);
1914 }
1915 return 0;
1916}
1917
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001918#if defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001919int
1920sys_fchroot(tcp)
1921struct tcb *tcp;
1922{
1923 if (entering(tcp)) {
1924 tprintf("%ld", tcp->u_arg[0]);
1925 }
1926 return 0;
1927}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001928#endif /* SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001929
1930int
1931sys_link(tcp)
1932struct tcb *tcp;
1933{
1934 if (entering(tcp)) {
1935 printpath(tcp, tcp->u_arg[0]);
1936 tprintf(", ");
1937 printpath(tcp, tcp->u_arg[1]);
1938 }
1939 return 0;
1940}
1941
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001942#ifdef LINUX
1943int
1944sys_linkat(struct tcb *tcp)
1945{
1946 if (entering(tcp)) {
1947 print_dirfd(tcp->u_arg[0]);
1948 printpath(tcp, tcp->u_arg[1]);
1949 tprintf(", ");
1950 print_dirfd(tcp->u_arg[2]);
1951 printpath(tcp, tcp->u_arg[3]);
1952 tprintf(", %ld", tcp->u_arg[4]);
1953 }
1954 return 0;
1955}
1956#endif
1957
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001958int
1959sys_unlink(tcp)
1960struct tcb *tcp;
1961{
1962 if (entering(tcp)) {
1963 printpath(tcp, tcp->u_arg[0]);
1964 }
1965 return 0;
1966}
1967
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001968#ifdef LINUX
1969static const struct xlat unlinkatflags[] = {
1970#ifndef AT_REMOVEDIR
1971# define AT_REMOVEDIR 0x200
1972#endif
1973 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1974 { 0, NULL },
1975};
1976
1977int
1978sys_unlinkat(struct tcb *tcp)
1979{
1980 if (entering(tcp)) {
1981 print_dirfd(tcp->u_arg[0]);
1982 printpath(tcp, tcp->u_arg[1]);
1983 tprintf(", ");
1984 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1985 }
1986 return 0;
1987}
1988#endif
1989
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001990int
1991sys_symlink(tcp)
1992struct tcb *tcp;
1993{
1994 if (entering(tcp)) {
1995 printpath(tcp, tcp->u_arg[0]);
1996 tprintf(", ");
1997 printpath(tcp, tcp->u_arg[1]);
1998 }
1999 return 0;
2000}
2001
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002002#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002003int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002004sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002005{
2006 if (entering(tcp)) {
2007 printpath(tcp, tcp->u_arg[0]);
2008 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002009 print_dirfd(tcp->u_arg[1]);
2010 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002011 }
2012 return 0;
2013}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002014#endif
2015
2016static int
2017decode_readlink(struct tcb *tcp, int offset)
2018{
2019 if (entering(tcp)) {
2020 printpath(tcp, tcp->u_arg[offset]);
2021 tprintf(", ");
2022 } else {
2023 if (syserror(tcp))
2024 tprintf("%#lx", tcp->u_arg[offset + 1]);
2025 else
2026 printpathn(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
2027 tprintf(", %lu", tcp->u_arg[offset + 2]);
2028 }
2029 return 0;
2030}
2031
2032int
2033sys_readlink(struct tcb *tcp)
2034{
2035 return decode_readlink(tcp, 0);
2036}
2037
2038#ifdef LINUX
2039int
2040sys_readlinkat(struct tcb *tcp)
2041{
2042 if (entering(tcp))
2043 print_dirfd(tcp->u_arg[0]);
2044 return decode_readlink(tcp, 1);
2045}
2046#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002047
2048int
2049sys_rename(tcp)
2050struct tcb *tcp;
2051{
2052 if (entering(tcp)) {
2053 printpath(tcp, tcp->u_arg[0]);
2054 tprintf(", ");
2055 printpath(tcp, tcp->u_arg[1]);
2056 }
2057 return 0;
2058}
2059
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002060#ifdef LINUX
2061int
2062sys_renameat(struct tcb *tcp)
2063{
2064 if (entering(tcp)) {
2065 print_dirfd(tcp->u_arg[0]);
2066 printpath(tcp, tcp->u_arg[1]);
2067 tprintf(", ");
2068 print_dirfd(tcp->u_arg[2]);
2069 printpath(tcp, tcp->u_arg[3]);
2070 }
2071 return 0;
2072}
2073#endif
2074
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002075int
2076sys_chown(tcp)
2077struct tcb *tcp;
2078{
2079 if (entering(tcp)) {
2080 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002081 printuid(", ", tcp->u_arg[1]);
2082 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002083 }
2084 return 0;
2085}
2086
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002087#ifdef LINUX
2088int
2089sys_fchownat(struct tcb *tcp)
2090{
2091 if (entering(tcp)) {
2092 print_dirfd(tcp->u_arg[0]);
2093 printpath(tcp, tcp->u_arg[1]);
2094 printuid(", ", tcp->u_arg[2]);
2095 printuid(", ", tcp->u_arg[3]);
2096 tprintf(", ");
2097 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
2098 }
2099 return 0;
2100}
2101#endif
2102
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002103int
2104sys_fchown(tcp)
2105struct tcb *tcp;
2106{
2107 if (entering(tcp)) {
Roland McGrath6bc12202003-11-13 22:32:27 +00002108 tprintf("%ld", tcp->u_arg[0]);
2109 printuid(", ", tcp->u_arg[1]);
2110 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002111 }
2112 return 0;
2113}
2114
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002115static int
2116decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002117{
2118 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002119 printpath(tcp, tcp->u_arg[offset]);
2120 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002121 }
2122 return 0;
2123}
2124
2125int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002126sys_chmod(struct tcb *tcp)
2127{
2128 return decode_chmod(tcp, 0);
2129}
2130
2131#ifdef LINUX
2132int
2133sys_fchmodat(struct tcb *tcp)
2134{
2135 if (entering(tcp))
2136 print_dirfd(tcp->u_arg[0]);
2137 return decode_chmod(tcp, 1);
2138}
2139#endif
2140
2141int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002142sys_fchmod(tcp)
2143struct tcb *tcp;
2144{
2145 if (entering(tcp)) {
2146 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
2147 }
2148 return 0;
2149}
2150
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002151#ifdef ALPHA
2152int
2153sys_osf_utimes(tcp)
2154struct tcb *tcp;
2155{
2156 if (entering(tcp)) {
2157 printpath(tcp, tcp->u_arg[0]);
2158 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002159 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002160 }
2161 return 0;
2162}
2163#endif
2164
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002165static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002166decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002167{
2168 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002169 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002170 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002171 if (tcp->u_arg[offset + 1] == 0)
2172 tprintf("NULL");
2173 else {
2174 tprintf("{");
2175 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2176 BITNESS_CURRENT, special);
2177 tprintf(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002178 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Roland McGrath6afc5652007-07-24 01:57:11 +00002179 + sizeof (struct timeval),
2180 BITNESS_CURRENT, special);
2181 tprintf("}");
2182 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002183 }
2184 return 0;
2185}
2186
2187int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002188sys_utimes(struct tcb *tcp)
2189{
Roland McGrath6afc5652007-07-24 01:57:11 +00002190 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002191}
2192
2193#ifdef LINUX
2194int
2195sys_futimesat(struct tcb *tcp)
2196{
2197 if (entering(tcp))
2198 print_dirfd(tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002199 return decode_utimes(tcp, 1, 0);
2200}
2201
2202int
2203sys_utimensat(struct tcb *tcp)
2204{
2205 if (entering(tcp)) {
2206 print_dirfd(tcp->u_arg[0]);
2207 decode_utimes(tcp, 1, 1);
2208 tprintf(", ");
2209 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2210 }
2211 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002212}
2213#endif
2214
2215int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002216sys_utime(tcp)
2217struct tcb *tcp;
2218{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002219 union {
2220 long utl[2];
2221 int uti[2];
2222 } u;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002223
2224 if (entering(tcp)) {
2225 printpath(tcp, tcp->u_arg[0]);
2226 tprintf(", ");
2227 if (!tcp->u_arg[1])
2228 tprintf("NULL");
2229 else if (!verbose(tcp))
2230 tprintf("%#lx", tcp->u_arg[1]);
Roland McGrath7e9817c2007-07-05 20:31:58 +00002231 else if (umoven(tcp, tcp->u_arg[1],
2232 2 * personality_wordsize[current_personality],
2233 (char *) &u) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002234 tprintf("[?, ?]");
Roland McGrath7e9817c2007-07-05 20:31:58 +00002235 else if (personality_wordsize[current_personality]
2236 == sizeof u.utl[0]) {
2237 tprintf("[%s,", sprinttime(u.utl[0]));
2238 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002239 }
Roland McGrath7e9817c2007-07-05 20:31:58 +00002240 else if (personality_wordsize[current_personality]
2241 == sizeof u.uti[0]) {
2242 tprintf("[%s,", sprinttime(u.uti[0]));
2243 tprintf(" %s]", sprinttime(u.uti[1]));
2244 }
2245 else
2246 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002247 }
2248 return 0;
2249}
2250
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002251static int
2252decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002253{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002254 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002255
2256 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002257 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002258 tprintf(", %s", sprintmode(mode));
2259 switch (mode & S_IFMT) {
2260 case S_IFCHR: case S_IFBLK:
2261#ifdef LINUXSPARC
2262 if (current_personality == 1)
2263 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002264 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2265 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002266 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002267#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002268 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002269 (unsigned long) major(tcp->u_arg[offset + 2]),
2270 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002271 break;
2272 default:
2273 break;
2274 }
2275 }
2276 return 0;
2277}
2278
2279int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002280sys_mknod(struct tcb *tcp)
2281{
2282 return decode_mknod(tcp, 0);
2283}
2284
2285#ifdef LINUX
2286int
2287sys_mknodat(struct tcb *tcp)
2288{
2289 if (entering(tcp))
2290 print_dirfd(tcp->u_arg[0]);
2291 return decode_mknod(tcp, 1);
2292}
2293#endif
2294
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002295#ifdef FREEBSD
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002296int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002297sys_mkfifo(tcp)
2298struct tcb *tcp;
2299{
2300 if (entering(tcp)) {
2301 printpath(tcp, tcp->u_arg[0]);
2302 tprintf(", %#lo", tcp->u_arg[1]);
2303 }
2304 return 0;
2305}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002306#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002307
2308int
2309sys_fsync(tcp)
2310struct tcb *tcp;
2311{
2312 if (entering(tcp)) {
2313 tprintf("%ld", tcp->u_arg[0]);
2314 }
2315 return 0;
2316}
2317
Michal Ludvig53b320f2002-09-23 13:30:09 +00002318#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002319
2320static void
2321printdir(tcp, addr)
2322struct tcb *tcp;
2323long addr;
2324{
2325 struct dirent d;
2326
2327 if (!verbose(tcp)) {
2328 tprintf("%#lx", addr);
2329 return;
2330 }
2331 if (umove(tcp, addr, &d) < 0) {
2332 tprintf("{...}");
2333 return;
2334 }
2335 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002336 tprintf("d_name=");
2337 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2338 tprintf("}");
2339}
2340
2341int
2342sys_readdir(tcp)
2343struct tcb *tcp;
2344{
2345 if (entering(tcp)) {
2346 tprintf("%lu, ", tcp->u_arg[0]);
2347 } else {
2348 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2349 tprintf("%#lx", tcp->u_arg[1]);
2350 else
2351 printdir(tcp, tcp->u_arg[1]);
2352 /* Not much point in printing this out, it is always 1. */
2353 if (tcp->u_arg[2] != 1)
2354 tprintf(", %lu", tcp->u_arg[2]);
2355 }
2356 return 0;
2357}
2358
Michal Ludvig53b320f2002-09-23 13:30:09 +00002359#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002360
Roland McGrath40542842004-01-13 09:47:49 +00002361#if defined FREEBSD || defined LINUX
Roland McGratha4d48532005-06-08 20:45:28 +00002362static const struct xlat direnttypes[] = {
Roland McGrath40542842004-01-13 09:47:49 +00002363 { DT_UNKNOWN, "DT_UNKNOWN" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002364 { DT_FIFO, "DT_FIFO" },
2365 { DT_CHR, "DT_CHR" },
2366 { DT_DIR, "DT_DIR" },
2367 { DT_BLK, "DT_BLK" },
2368 { DT_REG, "DT_REG" },
2369 { DT_LNK, "DT_LNK" },
2370 { DT_SOCK, "DT_SOCK" },
2371 { DT_WHT, "DT_WHT" },
2372 { 0, NULL },
2373};
2374
2375#endif
2376
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002377int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002378sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002379{
2380 int i, len, dents = 0;
2381 char *buf;
2382
2383 if (entering(tcp)) {
2384 tprintf("%lu, ", tcp->u_arg[0]);
2385 return 0;
2386 }
2387 if (syserror(tcp) || !verbose(tcp)) {
2388 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2389 return 0;
2390 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002391 len = tcp->u_rval;
2392 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002393 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2394 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002395 return 0;
2396 }
2397 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002398 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002399 free(buf);
2400 return 0;
2401 }
2402 if (!abbrev(tcp))
2403 tprintf("{");
2404 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002405 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002406#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002407 if (!abbrev(tcp)) {
2408 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2409 i ? " " : "", d->d_ino, d->d_off);
2410 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 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002414#ifdef SVR4
2415 if (!abbrev(tcp)) {
2416 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002417 i ? " " : "",
2418 (unsigned long) d->d_ino,
2419 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002420 tprintf("d_reclen=%u, d_name=\"%s\"}",
2421 d->d_reclen, d->d_name);
2422 }
2423#endif /* SVR4 */
2424#ifdef SUNOS4
2425 if (!abbrev(tcp)) {
2426 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2427 i ? " " : "", d->d_off, d->d_fileno,
2428 d->d_reclen);
2429 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2430 d->d_namlen, d->d_namlen, d->d_name);
2431 }
2432#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002433#ifdef FREEBSD
2434 if (!abbrev(tcp)) {
2435 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2436 i ? " " : "", d->d_fileno, d->d_reclen);
2437 printxval(direnttypes, d->d_type, "DT_???");
2438 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2439 d->d_namlen, d->d_namlen, d->d_name);
2440 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002441#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002442 if (!d->d_reclen) {
2443 tprintf("/* d_reclen == 0, problem here */");
2444 break;
2445 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002446 i += d->d_reclen;
2447 dents++;
2448 }
2449 if (!abbrev(tcp))
2450 tprintf("}");
2451 else
2452 tprintf("/* %u entries */", dents);
2453 tprintf(", %lu", tcp->u_arg[2]);
2454 free(buf);
2455 return 0;
2456}
2457
John Hughesbdf48f52001-03-06 15:08:09 +00002458
2459#if _LFS64_LARGEFILE
2460int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002461sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002462{
2463 int i, len, dents = 0;
2464 char *buf;
2465
2466 if (entering(tcp)) {
2467 tprintf("%lu, ", tcp->u_arg[0]);
2468 return 0;
2469 }
2470 if (syserror(tcp) || !verbose(tcp)) {
2471 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2472 return 0;
2473 }
2474 len = tcp->u_rval;
2475 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002476 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2477 fprintf(stderr, "out of memory\n");
John Hughesbdf48f52001-03-06 15:08:09 +00002478 return 0;
2479 }
2480 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002481 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002482 free(buf);
2483 return 0;
2484 }
2485 if (!abbrev(tcp))
2486 tprintf("{");
2487 for (i = 0; i < len;) {
2488 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002489#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002490 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002491 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002492 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002493 d->d_ino,
2494 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002495#ifdef LINUX
2496 tprintf("d_type=");
2497 printxval(direnttypes, d->d_type, "DT_???");
2498 tprintf(", ");
2499#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002500 tprintf("d_reclen=%u, d_name=\"%s\"}",
2501 d->d_reclen, d->d_name);
2502 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002503#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002504#ifdef SUNOS4
2505 if (!abbrev(tcp)) {
2506 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2507 i ? " " : "", d->d_off, d->d_fileno,
2508 d->d_reclen);
2509 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2510 d->d_namlen, d->d_namlen, d->d_name);
2511 }
2512#endif /* SUNOS4 */
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002513 if (!d->d_reclen) {
2514 tprintf("/* d_reclen == 0, problem here */");
2515 break;
2516 }
John Hughesbdf48f52001-03-06 15:08:09 +00002517 i += d->d_reclen;
2518 dents++;
2519 }
2520 if (!abbrev(tcp))
2521 tprintf("}");
2522 else
2523 tprintf("/* %u entries */", dents);
2524 tprintf(", %lu", tcp->u_arg[2]);
2525 free(buf);
2526 return 0;
2527}
2528#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002529
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002530#ifdef FREEBSD
2531int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002532sys_getdirentries(struct tcb *tcp)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002533{
2534 int i, len, dents = 0;
2535 long basep;
2536 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002537
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002538 if (entering(tcp)) {
2539 tprintf("%lu, ", tcp->u_arg[0]);
2540 return 0;
2541 }
2542 if (syserror(tcp) || !verbose(tcp)) {
2543 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2544 return 0;
2545 }
2546 len = tcp->u_rval;
2547 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002548 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2549 fprintf(stderr, "out of memory\n");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002550 return 0;
2551 }
2552 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002553 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002554 free(buf);
2555 return 0;
2556 }
2557 if (!abbrev(tcp))
2558 tprintf("{");
2559 for (i = 0; i < len;) {
2560 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2561 if (!abbrev(tcp)) {
2562 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2563 i ? " " : "", d->d_fileno, d->d_reclen);
2564 printxval(direnttypes, d->d_type, "DT_???");
2565 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2566 d->d_namlen, d->d_namlen, d->d_name);
2567 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002568 if (!d->d_reclen) {
2569 tprintf("/* d_reclen == 0, problem here */");
2570 break;
2571 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002572 i += d->d_reclen;
2573 dents++;
2574 }
2575 if (!abbrev(tcp))
2576 tprintf("}");
2577 else
2578 tprintf("/* %u entries */", dents);
2579 free(buf);
2580 tprintf(", %lu", tcp->u_arg[2]);
2581 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2582 tprintf(", %#lx", tcp->u_arg[3]);
2583 else
2584 tprintf(", [%lu]", basep);
2585 return 0;
2586}
2587#endif
2588
Michal Ludvig53b320f2002-09-23 13:30:09 +00002589#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002590int
2591sys_getcwd(tcp)
2592struct tcb *tcp;
2593{
2594 if (exiting(tcp)) {
2595 if (syserror(tcp))
2596 tprintf("%#lx", tcp->u_arg[0]);
2597 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002598 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002599 tprintf(", %lu", tcp->u_arg[1]);
2600 }
2601 return 0;
2602}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002603#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002604
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002605#ifdef FREEBSD
2606int
2607sys___getcwd(tcp)
2608struct tcb *tcp;
2609{
2610 if (exiting(tcp)) {
2611 if (syserror(tcp))
2612 tprintf("%#lx", tcp->u_arg[0]);
2613 else
2614 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2615 tprintf(", %lu", tcp->u_arg[1]);
2616 }
2617 return 0;
2618}
2619#endif
2620
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002621#ifdef HAVE_SYS_ASYNCH_H
2622
2623int
2624sys_aioread(tcp)
2625struct tcb *tcp;
2626{
2627 struct aio_result_t res;
2628
2629 if (entering(tcp)) {
2630 tprintf("%lu, ", tcp->u_arg[0]);
2631 } else {
2632 if (syserror(tcp))
2633 tprintf("%#lx", tcp->u_arg[1]);
2634 else
2635 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2636 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2637 printxval(whence, tcp->u_arg[4], "L_???");
2638 if (syserror(tcp) || tcp->u_arg[5] == 0
2639 || umove(tcp, tcp->u_arg[5], &res) < 0)
2640 tprintf(", %#lx", tcp->u_arg[5]);
2641 else
2642 tprintf(", {aio_return %d aio_errno %d}",
2643 res.aio_return, res.aio_errno);
2644 }
2645 return 0;
2646}
2647
2648int
2649sys_aiowrite(tcp)
2650struct tcb *tcp;
2651{
2652 struct aio_result_t res;
2653
2654 if (entering(tcp)) {
2655 tprintf("%lu, ", tcp->u_arg[0]);
2656 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2657 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2658 printxval(whence, tcp->u_arg[4], "L_???");
2659 }
2660 else {
2661 if (tcp->u_arg[5] == 0)
2662 tprintf(", NULL");
2663 else if (syserror(tcp)
2664 || umove(tcp, tcp->u_arg[5], &res) < 0)
2665 tprintf(", %#lx", tcp->u_arg[5]);
2666 else
2667 tprintf(", {aio_return %d aio_errno %d}",
2668 res.aio_return, res.aio_errno);
2669 }
2670 return 0;
2671}
2672
2673int
2674sys_aiowait(tcp)
2675struct tcb *tcp;
2676{
2677 if (entering(tcp))
2678 printtv(tcp, tcp->u_arg[0]);
2679 return 0;
2680}
2681
2682int
2683sys_aiocancel(tcp)
2684struct tcb *tcp;
2685{
2686 struct aio_result_t res;
2687
2688 if (exiting(tcp)) {
2689 if (tcp->u_arg[0] == 0)
2690 tprintf("NULL");
2691 else if (syserror(tcp)
2692 || umove(tcp, tcp->u_arg[0], &res) < 0)
2693 tprintf("%#lx", tcp->u_arg[0]);
2694 else
2695 tprintf("{aio_return %d aio_errno %d}",
2696 res.aio_return, res.aio_errno);
2697 }
2698 return 0;
2699}
2700
2701#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002702
Roland McGratha4d48532005-06-08 20:45:28 +00002703static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002704#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002705 { XATTR_CREATE, "XATTR_CREATE" },
2706 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002707#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002708 { 0, NULL }
2709};
2710
Roland McGrath3292e222004-08-31 06:30:48 +00002711static void
2712print_xattr_val(tcp, failed, arg, insize, size)
2713struct tcb *tcp;
2714int failed;
2715unsigned long arg;
Roland McGrathaa524c82005-06-01 19:22:06 +00002716unsigned long insize, size;
Roland McGrath3292e222004-08-31 06:30:48 +00002717{
Roland McGrath883567c2005-02-02 03:38:32 +00002718 if (!failed) {
Roland McGrathaa524c82005-06-01 19:22:06 +00002719 unsigned long capacity = 4 * size + 1;
2720 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
Roland McGrath883567c2005-02-02 03:38:32 +00002721 if (buf == NULL || /* probably a bogus size argument */
Roland McGrathf7746422005-03-01 23:02:32 +00002722 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
Roland McGrath883567c2005-02-02 03:38:32 +00002723 failed = 1;
2724 }
2725 else {
2726 unsigned char *out = buf;
2727 unsigned char *in = &buf[3 * size];
2728 size_t i;
2729 for (i = 0; i < size; ++i)
2730 if (isprint(in[i]))
2731 *out++ = in[i];
2732 else {
Roland McGrath3292e222004-08-31 06:30:48 +00002733#define tohex(n) "0123456789abcdef"[n]
Roland McGrath883567c2005-02-02 03:38:32 +00002734 *out++ = '\\';
2735 *out++ = 'x';
2736 *out++ = tohex(in[i] / 16);
2737 *out++ = tohex(in[i] % 16);
2738 }
2739 /* Don't print terminating NUL if there is one. */
Dmitry V. Levin504eb0b2006-10-11 22:58:31 +00002740 if (i > 0 && in[i - 1] == '\0')
Roland McGrath883567c2005-02-02 03:38:32 +00002741 out -= 4;
2742 *out = '\0';
2743 tprintf(", \"%s\", %ld", buf, insize);
2744 }
2745 free(buf);
2746 }
2747 if (failed)
2748 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002749}
2750
Roland McGrath186c5ac2002-12-15 23:58:23 +00002751int
2752sys_setxattr(tcp)
2753struct tcb *tcp;
2754{
2755 if (entering(tcp)) {
2756 printpath(tcp, tcp->u_arg[0]);
2757 tprintf(", ");
2758 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002759 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2760 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002761 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002762 }
2763 return 0;
2764}
2765
2766int
2767sys_fsetxattr(tcp)
2768struct tcb *tcp;
2769{
2770 if (entering(tcp)) {
2771 tprintf("%ld, ", tcp->u_arg[0]);
2772 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002773 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2774 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002775 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002776 }
2777 return 0;
2778}
2779
2780int
2781sys_getxattr(tcp)
2782struct tcb *tcp;
2783{
2784 if (entering(tcp)) {
2785 printpath(tcp, tcp->u_arg[0]);
2786 tprintf(", ");
2787 printstr(tcp, tcp->u_arg[1], -1);
2788 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002789 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2790 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002791 }
2792 return 0;
2793}
2794
2795int
2796sys_fgetxattr(tcp)
2797struct tcb *tcp;
2798{
2799 if (entering(tcp)) {
2800 tprintf("%ld, ", tcp->u_arg[0]);
2801 printstr(tcp, tcp->u_arg[1], -1);
2802 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002803 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2804 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002805 }
2806 return 0;
2807}
2808
2809int
2810sys_listxattr(tcp)
2811struct tcb *tcp;
2812{
2813 if (entering(tcp)) {
2814 printpath(tcp, tcp->u_arg[0]);
2815 } else {
2816 /* XXX Print value in format */
2817 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2818 }
2819 return 0;
2820}
2821
2822int
2823sys_flistxattr(tcp)
2824struct tcb *tcp;
2825{
2826 if (entering(tcp)) {
2827 tprintf("%ld", tcp->u_arg[0]);
2828 } else {
2829 /* XXX Print value in format */
2830 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2831 }
2832 return 0;
2833}
2834
2835int
2836sys_removexattr(tcp)
2837struct tcb *tcp;
2838{
2839 if (entering(tcp)) {
2840 printpath(tcp, tcp->u_arg[0]);
2841 tprintf(", ");
2842 printstr(tcp, tcp->u_arg[1], -1);
2843 }
2844 return 0;
2845}
2846
2847int
2848sys_fremovexattr(tcp)
2849struct tcb *tcp;
2850{
2851 if (entering(tcp)) {
2852 tprintf("%ld, ", tcp->u_arg[0]);
2853 printstr(tcp, tcp->u_arg[1], -1);
2854 }
2855 return 0;
2856}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002857
2858
2859static const struct xlat advise[] = {
2860 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2861 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2862 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2863 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2864 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2865 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2866 { 0, NULL }
2867};
2868
2869
Roland McGrathe27ed342004-10-20 02:24:19 +00002870#ifdef LINUX
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002871int
2872sys_fadvise64(tcp)
2873struct tcb *tcp;
2874{
2875 if (entering(tcp)) {
2876 tprintf("%ld, %lld, %ld, ",
2877 tcp->u_arg[0],
2878# if defined IA64 || defined X86_64 || defined ALPHA
2879 (long long int) tcp->u_arg[1], tcp->u_arg[2]);
2880 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2881#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002882 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
2883 printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002884#endif
2885 }
2886 return 0;
2887}
2888#endif
2889
2890
2891int
2892sys_fadvise64_64(tcp)
2893struct tcb *tcp;
2894{
2895 if (entering(tcp)) {
2896 tprintf("%ld, %lld, %lld, ",
2897 tcp->u_arg[0],
Roland McGrath542c2c62008-05-20 01:11:56 +00002898#if defined LINUX_MIPSN32
2899 tcp->ext_arg[1], tcp->ext_arg[2]);
2900 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2901#elif defined IA64 || defined X86_64 || defined ALPHA || defined LINUX_MIPSN64
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002902 (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
2903 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2904#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002905 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
2906 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002907 printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
2908#endif
2909 }
2910 return 0;
2911}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002912
2913#ifdef LINUX
2914static const struct xlat inotify_modes[] = {
2915 { 0x00000001, "IN_ACCESS" },
2916 { 0x00000002, "IN_MODIFY" },
2917 { 0x00000004, "IN_ATTRIB" },
2918 { 0x00000008, "IN_CLOSE_WRITE" },
2919 { 0x00000010, "IN_CLOSE_NOWRITE" },
2920 { 0x00000020, "IN_OPEN" },
2921 { 0x00000040, "IN_MOVED_FROM" },
2922 { 0x00000080, "IN_MOVED_TO" },
2923 { 0x00000100, "IN_CREATE" },
2924 { 0x00000200, "IN_DELETE" },
2925 { 0x00000400, "IN_DELETE_SELF" },
2926 { 0x00000800, "IN_MOVE_SELF" },
2927 { 0x00002000, "IN_UNMOUNT" },
2928 { 0x00004000, "IN_Q_OVERFLOW" },
2929 { 0x00008000, "IN_IGNORED" },
2930 { 0x01000000, "IN_ONLYDIR" },
2931 { 0x02000000, "IN_DONT_FOLLOW" },
2932 { 0x20000000, "IN_MASK_ADD" },
2933 { 0x40000000, "IN_ISDIR" },
2934 { 0x80000000, "IN_ONESHOT" }
2935};
2936
2937int
2938sys_inotify_add_watch(struct tcb *tcp)
2939{
2940 if (entering(tcp)) {
2941 tprintf("%ld, ", tcp->u_arg[0]);
2942 printpath(tcp, tcp->u_arg[1]);
2943 tprintf(", ");
2944 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2945 }
2946 return 0;
2947}
2948
2949int
2950sys_inotify_rm_watch(struct tcb *tcp)
2951{
2952 if (entering(tcp)) {
2953 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
2954 }
2955 return 0;
2956}
Roland McGrath96a96612008-05-20 04:56:18 +00002957
2958int
2959sys_fallocate(struct tcb *tcp)
2960{
2961 if (entering(tcp)) {
2962 tprintf("%ld, ", tcp->u_arg[0]); /* fd */
2963 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
2964 tprintf("%llu, ", LONG_LONG(tcp->u_arg[2],
2965 tcp->u_arg[3])); /* offset */
2966 tprintf("%llu", LONG_LONG(tcp->u_arg[4],
2967 tcp->u_arg[5])); /* len */
2968 }
2969 return 0;
2970}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002971#endif