blob: 7e3e3fbd6b38a6e7b66b5ed2df8caa2b82079417 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * $Id$
31 */
32
33#include "defs.h"
34
35#include <dirent.h>
Roland McGrathc531e572008-08-01 01:13:10 +000036
Roland McGrathc531e572008-08-01 01:13:10 +000037struct kernel_dirent {
38 unsigned long d_ino;
39 unsigned long d_off;
40 unsigned short d_reclen;
41 char d_name[1];
42};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000043
Denys Vlasenko84703742012-02-25 02:38:52 +010044#ifdef LINUXSPARC
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000045struct stat {
46 unsigned short st_dev;
47 unsigned int st_ino;
48 unsigned short st_mode;
49 short st_nlink;
50 unsigned short st_uid;
51 unsigned short st_gid;
52 unsigned short st_rdev;
53 unsigned int st_size;
54 int st_atime;
55 unsigned int __unused1;
56 int st_mtime;
57 unsigned int __unused2;
58 int st_ctime;
59 unsigned int __unused3;
60 int st_blksize;
61 int st_blocks;
62 unsigned int __unused4[2];
63};
Denys Vlasenko84703742012-02-25 02:38:52 +010064# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +000065struct stat_sparc64 {
66 unsigned int st_dev;
67 unsigned long st_ino;
68 unsigned int st_mode;
69 unsigned int st_nlink;
70 unsigned int st_uid;
71 unsigned int st_gid;
72 unsigned int st_rdev;
73 long st_size;
74 long st_atime;
75 long st_mtime;
76 long st_ctime;
77 long st_blksize;
78 long st_blocks;
79 unsigned long __unused4[2];
80};
Denys Vlasenko84703742012-02-25 02:38:52 +010081# endif /* SPARC64 */
82# define stat kernel_stat
83# include <asm/stat.h>
84# undef stat
85#else
86# undef dev_t
87# undef ino_t
88# undef mode_t
89# undef nlink_t
90# undef uid_t
91# undef gid_t
92# undef off_t
93# undef loff_t
Wichert Akkerman5b4d1281999-07-09 00:32:54 +000094
Denys Vlasenko84703742012-02-25 02:38:52 +010095# define dev_t __kernel_dev_t
96# define ino_t __kernel_ino_t
97# define mode_t __kernel_mode_t
98# define nlink_t __kernel_nlink_t
99# define uid_t __kernel_uid_t
100# define gid_t __kernel_gid_t
101# define off_t __kernel_off_t
102# define loff_t __kernel_loff_t
Wichert Akkermana6013701999-07-08 14:00:58 +0000103
Denys Vlasenko84703742012-02-25 02:38:52 +0100104# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +0000105
Denys Vlasenko84703742012-02-25 02:38:52 +0100106# undef dev_t
107# undef ino_t
108# undef mode_t
109# undef nlink_t
110# undef uid_t
111# undef gid_t
112# undef off_t
113# undef loff_t
Wichert Akkerman5b4d1281999-07-09 00:32:54 +0000114
Denys Vlasenko84703742012-02-25 02:38:52 +0100115# define dev_t dev_t
116# define ino_t ino_t
117# define mode_t mode_t
118# define nlink_t nlink_t
119# define uid_t uid_t
120# define gid_t gid_t
121# define off_t off_t
122# define loff_t loff_t
123#endif
124
125#ifdef HPPA /* asm-parisc/stat.h defines stat64 */
126# undef stat64
127#endif
128#define stat libc_stat
129#define stat64 libc_stat64
130#include <sys/stat.h>
131#undef stat
132#undef stat64
133 /* These might be macros. */
134#undef st_atime
135#undef st_mtime
136#undef st_ctime
137#ifdef HPPA
138# define stat64 hpux_stat64
139#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000140
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000141#include <fcntl.h>
142
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000143
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000144#ifdef HAVE_SYS_VFS_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100145# include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000146#endif
147
Roland McGrath186c5ac2002-12-15 23:58:23 +0000148#ifdef HAVE_LINUX_XATTR_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100149# include <linux/xattr.h>
Denys Vlasenkoed720fd2012-02-25 02:24:03 +0100150#else
Denys Vlasenko84703742012-02-25 02:38:52 +0100151# define XATTR_CREATE 1
152# define XATTR_REPLACE 2
Roland McGrath186c5ac2002-12-15 23:58:23 +0000153#endif
154
John Hughes70623be2001-03-08 13:59:00 +0000155
Denys Vlasenko84703742012-02-25 02:38:52 +0100156#if _LFS64_LARGEFILE
Dmitry V. Levin1f336e52006-10-14 20:20:46 +0000157# ifdef HAVE_INTTYPES_H
158# include <inttypes.h>
159# else
160# define PRId64 "lld"
161# define PRIu64 "llu"
162# endif
163#endif
164
John Hughes70623be2001-03-08 13:59:00 +0000165#if HAVE_LONG_LONG_OFF_T
166/*
167 * Ugly hacks for systems that have typedef long long off_t
168 */
John Hughesb8c9f772001-03-07 16:53:07 +0000169
Denys Vlasenko84703742012-02-25 02:38:52 +0100170# define stat64 stat
171# define HAVE_STAT64 1 /* Ugly hack */
John Hughes70623be2001-03-08 13:59:00 +0000172
Denys Vlasenko84703742012-02-25 02:38:52 +0100173# define sys_stat64 sys_stat
174# define sys_fstat64 sys_fstat
175# define sys_lstat64 sys_lstat
176# define sys_lseek64 sys_lseek
177# define sys_truncate64 sys_truncate
178# define sys_ftruncate64 sys_ftruncate
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000179#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000180
181#ifdef MAJOR_IN_SYSMACROS
Denys Vlasenko84703742012-02-25 02:38:52 +0100182# include <sys/sysmacros.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000183#endif
184
185#ifdef MAJOR_IN_MKDEV
Denys Vlasenko84703742012-02-25 02:38:52 +0100186# include <sys/mkdev.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000187#endif
188
189#ifdef HAVE_SYS_ASYNCH_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100190# include <sys/asynch.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000191#endif
192
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000193
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000194const struct xlat open_access_modes[] = {
195 { O_RDONLY, "O_RDONLY" },
196 { O_WRONLY, "O_WRONLY" },
197 { O_RDWR, "O_RDWR" },
198#ifdef O_ACCMODE
199 { O_ACCMODE, "O_ACCMODE" },
200#endif
201 { 0, NULL },
202};
203
204const struct xlat open_mode_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205 { O_CREAT, "O_CREAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000206 { O_EXCL, "O_EXCL" },
207 { O_NOCTTY, "O_NOCTTY" },
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000208 { O_TRUNC, "O_TRUNC" },
209 { O_APPEND, "O_APPEND" },
210 { O_NONBLOCK, "O_NONBLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000211#ifdef O_SYNC
212 { O_SYNC, "O_SYNC" },
213#endif
214#ifdef O_ASYNC
215 { O_ASYNC, "O_ASYNC" },
216#endif
217#ifdef O_DSYNC
218 { O_DSYNC, "O_DSYNC" },
219#endif
220#ifdef O_RSYNC
221 { O_RSYNC, "O_RSYNC" },
222#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000223#if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000224 { O_NDELAY, "O_NDELAY" },
225#endif
226#ifdef O_PRIV
227 { O_PRIV, "O_PRIV" },
228#endif
229#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000230 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000231#endif
232#ifdef O_LARGEFILE
Roland McGrathfee836e2005-02-02 22:11:32 +0000233# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
234# undef O_LARGEFILE
235# ifdef SPARC64
236# define O_LARGEFILE 0x40000
237# elif defined X86_64 || defined S390X
238# define O_LARGEFILE 0100000
239# endif
240# endif
Roland McGrath663a8a02005-02-04 09:49:56 +0000241# ifdef O_LARGEFILE
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200242 { O_LARGEFILE, "O_LARGEFILE" },
Roland McGrath663a8a02005-02-04 09:49:56 +0000243# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000244#endif
245#ifdef O_DIRECTORY
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200246 { O_DIRECTORY, "O_DIRECTORY" },
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000247#endif
248#ifdef O_NOFOLLOW
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200249 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000250#endif
Roland McGrath1025c3e2005-05-09 07:40:35 +0000251#ifdef O_NOATIME
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200252 { O_NOATIME, "O_NOATIME" },
Roland McGrath1025c3e2005-05-09 07:40:35 +0000253#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000254#ifdef O_CLOEXEC
255 { O_CLOEXEC, "O_CLOEXEC" },
256#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000257#ifdef FNDELAY
258 { FNDELAY, "FNDELAY" },
259#endif
260#ifdef FAPPEND
261 { FAPPEND, "FAPPEND" },
262#endif
263#ifdef FMARK
264 { FMARK, "FMARK" },
265#endif
266#ifdef FDEFER
267 { FDEFER, "FDEFER" },
268#endif
269#ifdef FASYNC
270 { FASYNC, "FASYNC" },
271#endif
272#ifdef FSHLOCK
273 { FSHLOCK, "FSHLOCK" },
274#endif
275#ifdef FEXLOCK
276 { FEXLOCK, "FEXLOCK" },
277#endif
278#ifdef FCREAT
279 { FCREAT, "FCREAT" },
280#endif
281#ifdef FTRUNC
282 { FTRUNC, "FTRUNC" },
283#endif
284#ifdef FEXCL
285 { FEXCL, "FEXCL" },
286#endif
287#ifdef FNBIO
288 { FNBIO, "FNBIO" },
289#endif
290#ifdef FSYNC
291 { FSYNC, "FSYNC" },
292#endif
293#ifdef FNOCTTY
294 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000295#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000296#ifdef O_SHLOCK
297 { O_SHLOCK, "O_SHLOCK" },
298#endif
299#ifdef O_EXLOCK
300 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000301#endif
302 { 0, NULL },
303};
304
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000305
306#ifndef AT_FDCWD
307# define AT_FDCWD -100
308#endif
309
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000310/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
311 * extension to get the right value. We do this by declaring fd as int here.
312 */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000313static void
Dmitry V. Levin31382132011-03-04 05:08:02 +0300314print_dirfd(struct tcb *tcp, int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000315{
316 if (fd == AT_FDCWD)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200317 tprints("AT_FDCWD, ");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200318 else {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300319 printfd(tcp, fd);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200320 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300321 }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000322}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000323
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000324/*
325 * low bits of the open(2) flags define access mode,
326 * other bits are real flags.
327 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000328const char *
329sprint_open_modes(mode_t flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000330{
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100331 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000332 char *p;
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100333 char sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000334 const char *str;
335 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000336
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100337 sep = ' ';
338 p = stpcpy(outstr, "flags");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000339 str = xlookup(open_access_modes, flags & 3);
340 if (str) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100341 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200342 p = stpcpy(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000343 flags &= ~3;
344 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000345 return outstr;
346 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000347 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000348
349 for (x = open_mode_flags; x->str; x++) {
350 if ((flags & x->val) == x->val) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100351 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200352 p = stpcpy(p, x->str);
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000353 flags &= ~x->val;
354 if (!flags)
355 return outstr;
356 sep = '|';
357 }
358 }
359 /* flags is still nonzero */
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100360 *p++ = sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000361 sprintf(p, "%#x", flags);
362 return outstr;
363}
364
365void
366tprint_open_modes(mode_t flags)
367{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200368 tprints(sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000369}
370
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000371static int
372decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000373{
374 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000375 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200376 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000377 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000378 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000379 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000380 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000381 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000382 }
383 }
384 return 0;
385}
386
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000387int
388sys_open(struct tcb *tcp)
389{
390 return decode_open(tcp, 0);
391}
392
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000393int
394sys_openat(struct tcb *tcp)
395{
396 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300397 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000398 return decode_open(tcp, 1);
399}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000400
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000401#ifdef LINUXSPARC
Roland McGratha4d48532005-06-08 20:45:28 +0000402static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000403 { 0, "O_RDWR" },
404 { 1, "O_RDONLY" },
405 { 2, "O_WRONLY" },
406 { 0x80, "O_NONBLOCK" },
407 { 8, "O_APPEND" },
408 { 0x100, "O_CREAT" },
409 { 0x200, "O_TRUNC" },
410 { 0x400, "O_EXCL" },
411 { 0x800, "O_NOCTTY" },
412 { 0x10, "O_SYNC" },
413 { 0x40, "O_DSYNC" },
414 { 0x8000, "O_RSYNC" },
415 { 4, "O_NDELAY" },
416 { 0x1000, "O_PRIV" },
417 { 0, NULL },
418};
419
420int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000421solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000422{
423 if (entering(tcp)) {
424 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200425 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000426 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000427 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000428 if (tcp->u_arg[1] & 0x100) {
429 /* mode */
430 tprintf(", %#lo", tcp->u_arg[2]);
431 }
432 }
433 return 0;
434}
435
436#endif
437
438int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000439sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000440{
441 if (entering(tcp)) {
442 printpath(tcp, tcp->u_arg[0]);
443 tprintf(", %#lo", tcp->u_arg[1]);
444 }
445 return 0;
446}
447
Roland McGrathd9f816f2004-09-04 03:39:20 +0000448static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000449 { F_OK, "F_OK", },
450 { R_OK, "R_OK" },
451 { W_OK, "W_OK" },
452 { X_OK, "X_OK" },
453#ifdef EFF_ONLY_OK
454 { EFF_ONLY_OK, "EFF_ONLY_OK" },
455#endif
456#ifdef EX_OK
457 { EX_OK, "EX_OK" },
458#endif
459 { 0, NULL },
460};
461
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000462static int
463decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000464{
465 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000466 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200467 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000468 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000469 }
470 return 0;
471}
472
473int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000474sys_access(struct tcb *tcp)
475{
476 return decode_access(tcp, 0);
477}
478
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000479int
480sys_faccessat(struct tcb *tcp)
481{
482 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300483 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000484 return decode_access(tcp, 1);
485}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000486
487int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000488sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000489{
490 if (entering(tcp)) {
491 tprintf("%#lo", tcp->u_arg[0]);
492 }
493 return RVAL_OCTAL;
494}
495
Roland McGrathd9f816f2004-09-04 03:39:20 +0000496static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000497 { SEEK_SET, "SEEK_SET" },
498 { SEEK_CUR, "SEEK_CUR" },
499 { SEEK_END, "SEEK_END" },
500 { 0, NULL },
501};
502
John Hughes70623be2001-03-08 13:59:00 +0000503#ifndef HAVE_LONG_LONG_OFF_T
Roland McGrath542c2c62008-05-20 01:11:56 +0000504#if defined (LINUX_MIPSN32)
505int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000506sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000507{
508 long long offset;
509 int _whence;
510
511 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300512 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200513 tprints(", ");
Roland McGrath542c2c62008-05-20 01:11:56 +0000514 offset = tcp->ext_arg[1];
515 _whence = tcp->u_arg[2];
516 if (_whence == SEEK_SET)
517 tprintf("%llu, ", offset);
518 else
519 tprintf("%lld, ", offset);
520 printxval(whence, _whence, "SEEK_???");
521 }
522 return RVAL_UDECIMAL;
523}
524#else /* !LINUX_MIPSN32 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000526sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000527{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000528 off_t offset;
529 int _whence;
530
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000531 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300532 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200533 tprints(", ");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000534 offset = tcp->u_arg[1];
535 _whence = tcp->u_arg[2];
536 if (_whence == SEEK_SET)
537 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000538 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000539 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000540 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000541 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000542 return RVAL_UDECIMAL;
543}
Roland McGrath542c2c62008-05-20 01:11:56 +0000544#endif /* LINUX_MIPSN32 */
John Hughes5a826b82001-03-07 13:21:24 +0000545#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000546
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000548sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000549{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000550 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300551 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000552 /*
553 * This one call takes explicitly two 32-bit arguments hi, lo,
554 * rather than one 64-bit argument for which LONG_LONG works
555 * appropriate for the native byte order.
556 */
557 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300558 tprintf(", %llu, ",
559 ((long long int) tcp->u_arg[1]) << 32 |
560 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000561 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300562 tprintf(", %lld, ",
563 ((long long int) tcp->u_arg[1]) << 32 |
564 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000565 }
566 else {
567 long long int off;
568 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
569 tprintf("%#lx, ", tcp->u_arg[3]);
570 else
571 tprintf("[%llu], ", off);
572 printxval(whence, tcp->u_arg[4], "SEEK_???");
573 }
574 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000575}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000576
577int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000578sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000579{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000580 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100581 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300582 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200583 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100584 argn = printllval(tcp, "%lld", 1);
585 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000586 }
587 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000588}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000589
John Hughes70623be2001-03-08 13:59:00 +0000590#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000591int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000592sys_lseek64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +0000593{
594 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100595 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300596 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200597 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000598 if (tcp->u_arg[3] == SEEK_SET)
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100599 argn = printllval(tcp, "%llu, ", 1);
John Hughesbdf48f52001-03-06 15:08:09 +0000600 else
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100601 argn = printllval(tcp, "%lld, ", 1);
602 printxval(whence, tcp->u_arg[argn], "SEEK_???");
John Hughesbdf48f52001-03-06 15:08:09 +0000603 }
604 return RVAL_LUDECIMAL;
605}
606#endif
607
John Hughes70623be2001-03-08 13:59:00 +0000608#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000609int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000610sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000611{
612 if (entering(tcp)) {
613 printpath(tcp, tcp->u_arg[0]);
614 tprintf(", %lu", tcp->u_arg[1]);
615 }
616 return 0;
617}
John Hughes5a826b82001-03-07 13:21:24 +0000618#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000619
John Hughes70623be2001-03-08 13:59:00 +0000620#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000621int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000622sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000623{
624 if (entering(tcp)) {
625 printpath(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100626 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000627 }
628 return 0;
629}
630#endif
631
John Hughes70623be2001-03-08 13:59:00 +0000632#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000633int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000634sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000635{
636 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300637 printfd(tcp, tcp->u_arg[0]);
638 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000639 }
640 return 0;
641}
John Hughes5a826b82001-03-07 13:21:24 +0000642#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000643
John Hughes70623be2001-03-08 13:59:00 +0000644#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000645int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000646sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000647{
648 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300649 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200650 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100651 printllval(tcp, "%llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000652 }
653 return 0;
654}
655#endif
656
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000657/* several stats */
658
Roland McGrathd9f816f2004-09-04 03:39:20 +0000659static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000660 { S_IFREG, "S_IFREG" },
661 { S_IFSOCK, "S_IFSOCK" },
662 { S_IFIFO, "S_IFIFO" },
663 { S_IFLNK, "S_IFLNK" },
664 { S_IFDIR, "S_IFDIR" },
665 { S_IFBLK, "S_IFBLK" },
666 { S_IFCHR, "S_IFCHR" },
667 { 0, NULL },
668};
669
Roland McGrathf9c49b22004-10-06 22:11:54 +0000670static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000671sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000672{
673 static char buf[64];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000674 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000675
676 if ((mode & S_IFMT) == 0)
677 s = "";
678 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
679 sprintf(buf, "%#o", mode);
680 return buf;
681 }
682 sprintf(buf, "%s%s%s%s", s,
683 (mode & S_ISUID) ? "|S_ISUID" : "",
684 (mode & S_ISGID) ? "|S_ISGID" : "",
685 (mode & S_ISVTX) ? "|S_ISVTX" : "");
686 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
687 if (mode)
688 sprintf(buf + strlen(buf), "|%#o", mode);
689 s = (*buf == '|') ? buf + 1 : buf;
690 return *s ? s : "0";
691}
692
693static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000694sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000695{
696 struct tm *tmp;
697 static char buf[32];
698
699 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000700 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000701 return buf;
702 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200703 tmp = localtime(&t);
704 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000705 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
706 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
707 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
708 else
709 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
710
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000711 return buf;
712}
713
714#ifdef LINUXSPARC
715typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000716 int tv_sec;
717 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000718} timestruct_t;
719
720struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000721 unsigned st_dev;
722 int st_pad1[3]; /* network id */
723 unsigned st_ino;
724 unsigned st_mode;
725 unsigned st_nlink;
726 unsigned st_uid;
727 unsigned st_gid;
728 unsigned st_rdev;
729 int st_pad2[2];
730 int st_size;
731 int st_pad3; /* st_size, off_t expansion */
732 timestruct_t st_atime;
733 timestruct_t st_mtime;
734 timestruct_t st_ctime;
735 int st_blksize;
736 int st_blocks;
737 char st_fstype[16];
738 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000739};
740
741static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000742printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000743{
744 struct solstat statbuf;
745
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000746 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200747 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000748 return;
749 }
750 if (!abbrev(tcp)) {
751 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
752 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
753 (unsigned long) (statbuf.st_dev & 0x3ffff),
754 (unsigned long) statbuf.st_ino,
755 sprintmode(statbuf.st_mode));
756 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
757 (unsigned long) statbuf.st_nlink,
758 (unsigned long) statbuf.st_uid,
759 (unsigned long) statbuf.st_gid);
760 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
761 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
762 }
763 else
764 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
765 switch (statbuf.st_mode & S_IFMT) {
766 case S_IFCHR: case S_IFBLK:
767 tprintf("st_rdev=makedev(%lu, %lu), ",
768 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
769 (unsigned long) (statbuf.st_rdev & 0x3ffff));
770 break;
771 default:
772 tprintf("st_size=%u, ", statbuf.st_size);
773 break;
774 }
775 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000776 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
777 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
778 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000779 }
780 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200781 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000782}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000783
784#if defined (SPARC64)
785static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000786printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000787{
788 struct stat_sparc64 statbuf;
789
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000790 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200791 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000792 return;
793 }
794
795 if (!abbrev(tcp)) {
796 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
797 (unsigned long) major(statbuf.st_dev),
798 (unsigned long) minor(statbuf.st_dev),
799 (unsigned long) statbuf.st_ino,
800 sprintmode(statbuf.st_mode));
801 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
802 (unsigned long) statbuf.st_nlink,
803 (unsigned long) statbuf.st_uid,
804 (unsigned long) statbuf.st_gid);
805 tprintf("st_blksize=%lu, ",
806 (unsigned long) statbuf.st_blksize);
807 tprintf("st_blocks=%lu, ",
808 (unsigned long) statbuf.st_blocks);
809 }
810 else
811 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
812 switch (statbuf.st_mode & S_IFMT) {
813 case S_IFCHR: case S_IFBLK:
814 tprintf("st_rdev=makedev(%lu, %lu), ",
815 (unsigned long) major(statbuf.st_rdev),
816 (unsigned long) minor(statbuf.st_rdev));
817 break;
818 default:
819 tprintf("st_size=%lu, ", statbuf.st_size);
820 break;
821 }
822 if (!abbrev(tcp)) {
823 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
824 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
825 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200826 tprints("}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000827 }
828 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200829 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000830}
831#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000832#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000833
Denys Vlasenko84703742012-02-25 02:38:52 +0100834#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200835struct stat_powerpc32 {
836 unsigned int st_dev;
837 unsigned int st_ino;
838 unsigned int st_mode;
839 unsigned short st_nlink;
840 unsigned int st_uid;
841 unsigned int st_gid;
842 unsigned int st_rdev;
843 unsigned int st_size;
844 unsigned int st_blksize;
845 unsigned int st_blocks;
846 unsigned int st_atime;
847 unsigned int st_atime_nsec;
848 unsigned int st_mtime;
849 unsigned int st_mtime_nsec;
850 unsigned int st_ctime;
851 unsigned int st_ctime_nsec;
852 unsigned int __unused4;
853 unsigned int __unused5;
854};
855
856static void
857printstat_powerpc32(struct tcb *tcp, long addr)
858{
859 struct stat_powerpc32 statbuf;
860
861 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200862 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200863 return;
864 }
865
866 if (!abbrev(tcp)) {
867 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
868 major(statbuf.st_dev), minor(statbuf.st_dev),
869 statbuf.st_ino,
870 sprintmode(statbuf.st_mode));
871 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
872 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
873 tprintf("st_blksize=%u, ", statbuf.st_blksize);
874 tprintf("st_blocks=%u, ", statbuf.st_blocks);
875 }
876 else
877 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
878 switch (statbuf.st_mode & S_IFMT) {
879 case S_IFCHR: case S_IFBLK:
880 tprintf("st_rdev=makedev(%lu, %lu), ",
881 (unsigned long) major(statbuf.st_rdev),
882 (unsigned long) minor(statbuf.st_rdev));
883 break;
884 default:
885 tprintf("st_size=%u, ", statbuf.st_size);
886 break;
887 }
888 if (!abbrev(tcp)) {
889 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
890 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
891 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200892 tprints("}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200893 }
894 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200895 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200896}
Denys Vlasenko84703742012-02-25 02:38:52 +0100897#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200898
Roland McGratha4d48532005-06-08 20:45:28 +0000899static const struct xlat fileflags[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000900 { 0, NULL },
901};
902
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000903
John Hughes70623be2001-03-08 13:59:00 +0000904#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000905static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000906realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000907{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000908 if (!abbrev(tcp)) {
909 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
910 (unsigned long) major(statbuf->st_dev),
911 (unsigned long) minor(statbuf->st_dev),
912 (unsigned long) statbuf->st_ino,
913 sprintmode(statbuf->st_mode));
914 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
915 (unsigned long) statbuf->st_nlink,
916 (unsigned long) statbuf->st_uid,
917 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000918#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000919 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
920#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000921#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000922 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
923#endif
924 }
925 else
926 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
927 switch (statbuf->st_mode & S_IFMT) {
928 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000929#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000930 tprintf("st_rdev=makedev(%lu, %lu), ",
931 (unsigned long) major(statbuf->st_rdev),
932 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000933#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000934 tprintf("st_size=makedev(%lu, %lu), ",
935 (unsigned long) major(statbuf->st_size),
936 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000937#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000938 break;
939 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000940 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000941 break;
942 }
943 if (!abbrev(tcp)) {
944 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
945 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
946 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000947#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200948 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000949 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000950#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000951#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000952 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
953#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000954#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000955 tprintf(", st_level=%ld", statbuf->st_level);
956#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000957#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000958 tprintf(", st_fstype=%.*s",
959 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
960#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000961#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000962 tprintf(", st_gen=%u", statbuf->st_gen);
963#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200964 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000965 }
966 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200967 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000968}
969
Nate Sammons771a6ff1999-04-05 22:39:31 +0000970
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000971static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000972printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000973{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000974 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000975
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000976 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200977 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000978 return;
979 }
980 if (syserror(tcp) || !verbose(tcp)) {
981 tprintf("%#lx", addr);
982 return;
983 }
984
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000985#ifdef LINUXSPARC
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000986 if (current_personality == 1) {
987 printstatsol(tcp, addr);
988 return;
989 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000990#ifdef SPARC64
991 else if (current_personality == 2) {
992 printstat_sparc64(tcp, addr);
993 return;
994 }
995#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000996#endif /* LINUXSPARC */
997
Denys Vlasenko84703742012-02-25 02:38:52 +0100998#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200999 if (current_personality == 1) {
1000 printstat_powerpc32(tcp, addr);
1001 return;
1002 }
1003#endif
1004
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001005 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001006 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001007 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
Denys Vlasenko84703742012-02-25 02:38:52 +01001014#if !defined HAVE_STAT64 && defined X86_64
Roland McGrathe6d0f712007-08-07 01:22:49 +00001015/*
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
Denys Vlasenko1d632462009-04-14 12:51:00 +00001048printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001049{
1050 struct stat64 statbuf;
1051
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001052#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001053 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1054#endif
1055
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001056 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001057 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001058 return;
1059 }
1060 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001061 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001062 return;
1063 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001064
1065#ifdef LINUXSPARC
1066 if (current_personality == 1) {
1067 printstatsol(tcp, addr);
1068 return;
1069 }
1070# ifdef SPARC64
1071 else if (current_personality == 2) {
1072 printstat_sparc64(tcp, addr);
1073 return;
1074 }
1075# endif
1076#endif /* LINUXSPARC */
1077
Denys Vlasenko84703742012-02-25 02:38:52 +01001078#if defined X86_64
Andreas Schwab61b74352009-10-16 11:37:13 +02001079 if (current_personality == 0) {
1080 printstat(tcp, addr);
1081 return;
1082 }
1083#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +00001084
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001085 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001086 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001087 return;
1088 }
1089
1090 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001091#ifdef HAVE_LONG_LONG
1092 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1093#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001094 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001095#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001096 (unsigned long) major(statbuf.st_dev),
1097 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001098#ifdef HAVE_LONG_LONG
1099 (unsigned long long) statbuf.st_ino,
1100#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001101 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001102#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001103 sprintmode(statbuf.st_mode));
1104 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1105 (unsigned long) statbuf.st_nlink,
1106 (unsigned long) statbuf.st_uid,
1107 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001108#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001109 tprintf("st_blksize=%lu, ",
1110 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001111#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1112#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001113 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001114#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001115 }
1116 else
1117 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1118 switch (statbuf.st_mode & S_IFMT) {
1119 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001120#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001121 tprintf("st_rdev=makedev(%lu, %lu), ",
1122 (unsigned long) major(statbuf.st_rdev),
1123 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001124#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001125 tprintf("st_size=makedev(%lu, %lu), ",
1126 (unsigned long) major(statbuf.st_size),
1127 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001128#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001129 break;
1130 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001131#ifdef HAVE_LONG_LONG
1132 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1133#else
1134 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1135#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001136 break;
1137 }
1138 if (!abbrev(tcp)) {
1139 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1140 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001141 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001142#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001143 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001144 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001145#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001146#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001147 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1148#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001149#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001150 tprintf(", st_level=%ld", statbuf.st_level);
1151#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001152#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001153 tprintf(", st_fstype=%.*s",
1154 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1155#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001156#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001157 tprintf(", st_gen=%u", statbuf.st_gen);
1158#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001159 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001160 }
1161 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001162 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001163}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001164#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001165
Denys Vlasenko84703742012-02-25 02:38:52 +01001166#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001167static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001168convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001169{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001170 newbuf->st_dev = oldbuf->st_dev;
1171 newbuf->st_ino = oldbuf->st_ino;
1172 newbuf->st_mode = oldbuf->st_mode;
1173 newbuf->st_nlink = oldbuf->st_nlink;
1174 newbuf->st_uid = oldbuf->st_uid;
1175 newbuf->st_gid = oldbuf->st_gid;
1176 newbuf->st_rdev = oldbuf->st_rdev;
1177 newbuf->st_size = oldbuf->st_size;
1178 newbuf->st_atime = oldbuf->st_atime;
1179 newbuf->st_mtime = oldbuf->st_mtime;
1180 newbuf->st_ctime = oldbuf->st_ctime;
1181 newbuf->st_blksize = 0; /* not supported in old_stat */
1182 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001183}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001184
1185
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001186static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001187printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001188{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001189 struct __old_kernel_stat statbuf;
1190 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001191
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001192 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001193 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001194 return;
1195 }
1196 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001197 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001198 return;
1199 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001200
Denys Vlasenko84703742012-02-25 02:38:52 +01001201# ifdef LINUXSPARC
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001202 if (current_personality == 1) {
1203 printstatsol(tcp, addr);
1204 return;
1205 }
Denys Vlasenko84703742012-02-25 02:38:52 +01001206# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001207
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001208 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001209 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001210 return;
1211 }
1212
1213 convertoldstat(&statbuf, &newstatbuf);
1214 realprintstat(tcp, &newstatbuf);
1215}
Denys Vlasenko84703742012-02-25 02:38:52 +01001216#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001217
John Hughes70623be2001-03-08 13:59:00 +00001218#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001219int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001220sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001221{
1222 if (entering(tcp)) {
1223 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001224 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001225 } else {
1226 printstat(tcp, tcp->u_arg[1]);
1227 }
1228 return 0;
1229}
John Hughesb8c9f772001-03-07 16:53:07 +00001230#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001231
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001232int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001233sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001234{
1235#ifdef HAVE_STAT64
1236 if (entering(tcp)) {
1237 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001238 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001239 } else {
1240 printstat64(tcp, tcp->u_arg[1]);
1241 }
1242 return 0;
1243#else
1244 return printargs(tcp);
1245#endif
1246}
1247
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001248static 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)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001261 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001262 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001263 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001264 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001265#ifdef POWERPC64
1266 if (current_personality == 0)
1267 printstat(tcp, tcp->u_arg[2]);
1268 else
1269 printstat64(tcp, tcp->u_arg[2]);
1270#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001271 printstat64(tcp, tcp->u_arg[2]);
1272#else
1273 printstat(tcp, tcp->u_arg[2]);
1274#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001275 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001276 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1277 }
1278 return 0;
1279}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001280
Denys Vlasenko84703742012-02-25 02:38:52 +01001281#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001282int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001283sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001284{
1285 if (entering(tcp)) {
1286 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001287 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001288 } else {
1289 printoldstat(tcp, tcp->u_arg[1]);
1290 }
1291 return 0;
1292}
Denys Vlasenko84703742012-02-25 02:38:52 +01001293#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001294
John Hughes70623be2001-03-08 13:59:00 +00001295#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001296int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001297sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001298{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001299 if (entering(tcp)) {
1300 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001301 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001302 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001303 printstat(tcp, tcp->u_arg[1]);
1304 }
1305 return 0;
1306}
John Hughesb8c9f772001-03-07 16:53:07 +00001307#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001308
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001309int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001310sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001311{
1312#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001313 if (entering(tcp)) {
1314 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001315 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001316 } else {
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001317 printstat64(tcp, tcp->u_arg[1]);
1318 }
1319 return 0;
1320#else
1321 return printargs(tcp);
1322#endif
1323}
1324
Denys Vlasenko84703742012-02-25 02:38:52 +01001325#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001326int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001327sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001328{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001329 if (entering(tcp)) {
1330 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001331 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001332 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001333 printoldstat(tcp, tcp->u_arg[1]);
1334 }
1335 return 0;
1336}
Denys Vlasenko84703742012-02-25 02:38:52 +01001337#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001338
John Hughes70623be2001-03-08 13:59:00 +00001339#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001340int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001341sys_lstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001342{
1343 if (entering(tcp)) {
1344 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001345 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001346 } else {
1347 printstat(tcp, tcp->u_arg[1]);
1348 }
1349 return 0;
1350}
John Hughesb8c9f772001-03-07 16:53:07 +00001351#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001352
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001353int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001354sys_lstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001355{
1356#ifdef HAVE_STAT64
1357 if (entering(tcp)) {
1358 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001359 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001360 } else {
1361 printstat64(tcp, tcp->u_arg[1]);
1362 }
1363 return 0;
1364#else
1365 return printargs(tcp);
1366#endif
1367}
1368
Denys Vlasenko84703742012-02-25 02:38:52 +01001369#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001370int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001371sys_oldlstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001372{
1373 if (entering(tcp)) {
1374 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001375 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001376 } else {
1377 printoldstat(tcp, tcp->u_arg[1]);
1378 }
1379 return 0;
1380}
Denys Vlasenko84703742012-02-25 02:38:52 +01001381#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001382
1383
Denys Vlasenko84703742012-02-25 02:38:52 +01001384#if defined(LINUXSPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001385
1386int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001387sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001388{
1389 if (entering(tcp)) {
1390 tprintf("%ld, ", tcp->u_arg[0]);
1391 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001392 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001393 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001394# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001395 if (tcp->u_arg[0] == _STAT64_VER)
1396 printstat64 (tcp, tcp->u_arg[2]);
1397 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001398# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001399 printstat(tcp, tcp->u_arg[2]);
1400 }
1401 return 0;
1402}
1403
1404int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001405sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001406{
1407 if (entering(tcp))
1408 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1409 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001410# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001411 if (tcp->u_arg[0] == _STAT64_VER)
1412 printstat64 (tcp, tcp->u_arg[2]);
1413 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001414# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001415 printstat(tcp, tcp->u_arg[2]);
1416 }
1417 return 0;
1418}
1419
1420int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001421sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001422{
1423 if (entering(tcp)) {
1424 tprintf("%ld, ", tcp->u_arg[0]);
1425 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001426 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001427 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001428# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001429 if (tcp->u_arg[0] == _STAT64_VER)
1430 printstat64 (tcp, tcp->u_arg[2]);
1431 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001432# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001433 printstat(tcp, tcp->u_arg[2]);
1434 }
1435 return 0;
1436}
1437
1438int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001439sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001440{
1441 int mode = tcp->u_arg[2];
1442
1443 if (entering(tcp)) {
1444 tprintf("%ld, ", tcp->u_arg[0]);
1445 printpath(tcp, tcp->u_arg[1]);
1446 tprintf(", %s", sprintmode(mode));
1447 switch (mode & S_IFMT) {
1448 case S_IFCHR: case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001449 tprintf(", makedev(%lu, %lu)",
1450 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1451 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001452 break;
1453 default:
1454 break;
1455 }
1456 }
1457 return 0;
1458}
1459
Denys Vlasenko84703742012-02-25 02:38:52 +01001460# ifdef HAVE_SYS_ACL_H
Wichert Akkerman8829a551999-06-11 13:18:40 +00001461
Denys Vlasenko84703742012-02-25 02:38:52 +01001462# include <sys/acl.h>
Wichert Akkerman8829a551999-06-11 13:18:40 +00001463
Roland McGratha4d48532005-06-08 20:45:28 +00001464static const struct xlat aclcmds[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001465# ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001466 { SETACL, "SETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001467# endif
1468# ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001469 { GETACL, "GETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001470# endif
1471# ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001472 { GETACLCNT, "GETACLCNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001473# endif
1474# ifdef ACL_GET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001475 { ACL_GET, "ACL_GET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001476# endif
1477# ifdef ACL_SET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001478 { ACL_SET, "ACL_SET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001479# endif
1480# ifdef ACL_CNT
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001481 { ACL_CNT, "ACL_CNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001482# endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001483 { 0, NULL },
1484};
1485
1486int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001487sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001488{
1489 if (entering(tcp)) {
1490 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001491 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001492 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1493 tprintf(", %ld", tcp->u_arg[2]);
1494 /*
1495 * FIXME - dump out the list of aclent_t's pointed to
1496 * by "tcp->u_arg[3]" if it's not NULL.
1497 */
1498 if (tcp->u_arg[3])
1499 tprintf(", %#lx", tcp->u_arg[3]);
1500 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001501 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001502 }
1503 return 0;
1504}
1505
1506
1507int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001508sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001509{
1510 if (entering(tcp)) {
1511 tprintf("%ld, ", tcp->u_arg[0]);
1512 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1513 tprintf(", %ld", tcp->u_arg[2]);
1514 /*
1515 * FIXME - dump out the list of aclent_t's pointed to
1516 * by "tcp->u_arg[3]" if it's not NULL.
1517 */
1518 if (tcp->u_arg[3])
1519 tprintf(", %#lx", tcp->u_arg[3]);
1520 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001521 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001522 }
1523 return 0;
1524}
1525
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001526
Roland McGratha4d48532005-06-08 20:45:28 +00001527static const struct xlat aclipc[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001528# ifdef IPC_SHM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001529 { IPC_SHM, "IPC_SHM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001530# endif
1531# ifdef IPC_SEM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001532 { IPC_SEM, "IPC_SEM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001533# endif
1534# ifdef IPC_MSG
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001535 { IPC_MSG, "IPC_MSG" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001536# endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001537 { 0, NULL },
1538};
1539
1540
1541int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001542sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001543{
1544 if (entering(tcp)) {
1545 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1546 tprintf(", %#lx, ", tcp->u_arg[1]);
1547 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1548 tprintf(", %ld", tcp->u_arg[3]);
1549 /*
1550 * FIXME - dump out the list of aclent_t's pointed to
1551 * by "tcp->u_arg[4]" if it's not NULL.
1552 */
1553 if (tcp->u_arg[4])
1554 tprintf(", %#lx", tcp->u_arg[4]);
1555 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001556 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001557 }
1558 return 0;
1559}
1560
Denys Vlasenko84703742012-02-25 02:38:52 +01001561# endif /* HAVE_SYS_ACL_H */
Wichert Akkerman8829a551999-06-11 13:18:40 +00001562
Denys Vlasenko84703742012-02-25 02:38:52 +01001563#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001564
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001565
Roland McGrathd9f816f2004-09-04 03:39:20 +00001566static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001567 { 0x73757245, "CODA_SUPER_MAGIC" },
1568 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1569 { 0x1373, "DEVFS_SUPER_MAGIC" },
1570 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1571 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001572 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1573 { 0xef53, "EXT2_SUPER_MAGIC" },
1574 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001575 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001576 { 0x9660, "ISOFS_SUPER_MAGIC" },
1577 { 0x137f, "MINIX_SUPER_MAGIC" },
1578 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001579 { 0x2468, "MINIX2_SUPER_MAGIC" },
1580 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001581 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001582 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001583 { 0x6969, "NFS_SUPER_MAGIC" },
1584 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001585 { 0x002f, "QNX4_SUPER_MAGIC" },
1586 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1587 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1588 { 0x517b, "SMB_SUPER_MAGIC" },
1589 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1590 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1591 { 0x00011954, "UFS_MAGIC" },
1592 { 0x54190100, "UFS_CIGAM" },
1593 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001594 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001595 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001596 { 0, NULL },
1597};
1598
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001599
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001600
Roland McGrathf9c49b22004-10-06 22:11:54 +00001601static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001602sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001603{
1604 static char buf[32];
Roland McGrathf9c49b22004-10-06 22:11:54 +00001605 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001606
1607 s = xlookup(fsmagic, magic);
1608 if (s) {
1609 sprintf(buf, "\"%s\"", s);
1610 return buf;
1611 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001612 sprintf(buf, "%#x", magic);
1613 return buf;
1614}
1615
1616static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001617printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001618{
1619 struct statfs statbuf;
1620
1621 if (syserror(tcp) || !verbose(tcp)) {
1622 tprintf("%#lx", addr);
1623 return;
1624 }
1625 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001626 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001627 return;
1628 }
1629#ifdef ALPHA
1630
1631 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1632 sprintfstype(statbuf.f_type),
1633 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001634 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001635 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001636 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1637 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001638#else /* !ALPHA */
1639 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1640 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001641 (unsigned long)statbuf.f_bsize,
1642 (unsigned long)statbuf.f_blocks,
1643 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001644 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1645 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001646 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001647 (unsigned long)statbuf.f_ffree,
1648 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001649 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001650#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001651#ifdef _STATFS_F_FRSIZE
1652 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1653#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001654 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001655}
1656
1657int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001658sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001659{
1660 if (entering(tcp)) {
1661 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001662 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001663 } else {
1664 printstatfs(tcp, tcp->u_arg[1]);
1665 }
1666 return 0;
1667}
1668
1669int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001670sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001671{
1672 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001673 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001674 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001675 } else {
1676 printstatfs(tcp, tcp->u_arg[1]);
1677 }
1678 return 0;
1679}
1680
Denys Vlasenko84703742012-02-25 02:38:52 +01001681#if defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001682static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001683printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001684{
1685 struct statfs64 statbuf;
1686
1687 if (syserror(tcp) || !verbose(tcp)) {
1688 tprintf("%#lx", addr);
1689 return;
1690 }
1691 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001692 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001693 return;
1694 }
Roland McGrath08738432005-06-03 02:40:39 +00001695 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001696 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001697 (unsigned long long)statbuf.f_bsize,
1698 (unsigned long long)statbuf.f_blocks,
1699 (unsigned long long)statbuf.f_bfree);
1700 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1701 (unsigned long long)statbuf.f_bavail,
1702 (unsigned long long)statbuf.f_files,
1703 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001704 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1705 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001706#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001707 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001708#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001709#ifdef _STATFS_F_FLAGS
1710 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1711#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001712 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001713}
1714
Andreas Schwab7d558012012-01-17 18:14:22 +01001715struct compat_statfs64 {
1716 uint32_t f_type;
1717 uint32_t f_bsize;
1718 uint64_t f_blocks;
1719 uint64_t f_bfree;
1720 uint64_t f_bavail;
1721 uint64_t f_files;
1722 uint64_t f_ffree;
1723 fsid_t f_fsid;
1724 uint32_t f_namelen;
1725 uint32_t f_frsize;
1726 uint32_t f_flags;
1727 uint32_t f_spare[4];
1728}
1729#if defined(X86_64) || defined(IA64)
1730 __attribute__ ((packed, aligned(4)))
1731#endif
1732;
1733
1734static void
1735printcompat_statfs64(struct tcb *tcp, long addr)
1736{
1737 struct compat_statfs64 statbuf;
1738
1739 if (syserror(tcp) || !verbose(tcp)) {
1740 tprintf("%#lx", addr);
1741 return;
1742 }
1743 if (umove(tcp, addr, &statbuf) < 0) {
1744 tprints("{...}");
1745 return;
1746 }
1747 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1748 sprintfstype(statbuf.f_type),
1749 (unsigned long)statbuf.f_bsize,
1750 (unsigned long long)statbuf.f_blocks,
1751 (unsigned long long)statbuf.f_bfree);
1752 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1753 (unsigned long long)statbuf.f_bavail,
1754 (unsigned long long)statbuf.f_files,
1755 (unsigned long long)statbuf.f_ffree,
1756 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1757 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1758 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1759 tprintf(", f_flags=%lu", (unsigned long)statbuf.f_frsize);
1760 tprints("}");
1761}
1762
Roland McGrathab147c52003-07-17 09:03:02 +00001763int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001764sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001765{
1766 if (entering(tcp)) {
1767 printpath(tcp, tcp->u_arg[0]);
1768 tprintf(", %lu, ", tcp->u_arg[1]);
1769 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001770 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001771 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001772 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1773 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001774 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001775 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001776 }
1777 return 0;
1778}
1779
1780int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001781sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001782{
1783 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001784 printfd(tcp, tcp->u_arg[0]);
1785 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001786 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001787 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001788 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001789 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1790 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001791 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001792 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001793 }
1794 return 0;
1795}
1796#endif
1797
Denys Vlasenko84703742012-02-25 02:38:52 +01001798#if defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001799int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001800osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001801{
1802 if (entering(tcp)) {
1803 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001804 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001805 } else {
1806 printstatfs(tcp, tcp->u_arg[1]);
1807 tprintf(", %lu", tcp->u_arg[2]);
1808 }
1809 return 0;
1810}
1811
1812int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001813osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001814{
1815 if (entering(tcp)) {
1816 tprintf("%lu, ", tcp->u_arg[0]);
1817 } else {
1818 printstatfs(tcp, tcp->u_arg[1]);
1819 tprintf(", %lu", tcp->u_arg[2]);
1820 }
1821 return 0;
1822}
Denys Vlasenko84703742012-02-25 02:38:52 +01001823#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001824
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001825
1826/* directory */
1827int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001828sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001829{
1830 if (entering(tcp)) {
1831 printpath(tcp, tcp->u_arg[0]);
1832 }
1833 return 0;
1834}
1835
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001836static int
1837decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001838{
1839 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001840 printpath(tcp, tcp->u_arg[offset]);
1841 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001842 }
1843 return 0;
1844}
1845
1846int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001847sys_mkdir(struct tcb *tcp)
1848{
1849 return decode_mkdir(tcp, 0);
1850}
1851
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001852int
1853sys_mkdirat(struct tcb *tcp)
1854{
1855 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001856 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001857 return decode_mkdir(tcp, 1);
1858}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001859
1860int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001861sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001862{
1863 if (entering(tcp)) {
1864 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001865 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001866 printpath(tcp, tcp->u_arg[1]);
1867 }
1868 return 0;
1869}
1870
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001871int
1872sys_linkat(struct tcb *tcp)
1873{
1874 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001875 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001876 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001877 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001878 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001879 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001880 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001881 printfd(tcp, tcp->u_arg[4]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001882 }
1883 return 0;
1884}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001885
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001886static const struct xlat unlinkatflags[] = {
1887#ifndef AT_REMOVEDIR
1888# define AT_REMOVEDIR 0x200
1889#endif
1890 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1891 { 0, NULL },
1892};
1893
1894int
1895sys_unlinkat(struct tcb *tcp)
1896{
1897 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001898 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001899 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001900 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001901 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1902 }
1903 return 0;
1904}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001905
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001906int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001907sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001908{
1909 if (entering(tcp)) {
1910 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001911 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001912 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001913 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001914 }
1915 return 0;
1916}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001917
1918static int
1919decode_readlink(struct tcb *tcp, int offset)
1920{
1921 if (entering(tcp)) {
1922 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001923 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001924 } else {
1925 if (syserror(tcp))
1926 tprintf("%#lx", tcp->u_arg[offset + 1]);
1927 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001928 /* Used to use printpathn(), but readlink
1929 * neither includes NUL in the returned count,
1930 * nor actually writes it into memory.
1931 * printpathn() would decide on printing
1932 * "..." continuation based on garbage
1933 * past return buffer's end.
1934 */
1935 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001936 tprintf(", %lu", tcp->u_arg[offset + 2]);
1937 }
1938 return 0;
1939}
1940
1941int
1942sys_readlink(struct tcb *tcp)
1943{
1944 return decode_readlink(tcp, 0);
1945}
1946
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001947int
1948sys_readlinkat(struct tcb *tcp)
1949{
1950 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001951 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001952 return decode_readlink(tcp, 1);
1953}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001954
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001955int
1956sys_renameat(struct tcb *tcp)
1957{
1958 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001959 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001960 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001961 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001962 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001963 printpath(tcp, tcp->u_arg[3]);
1964 }
1965 return 0;
1966}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001967
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001968int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001969sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001970{
1971 if (entering(tcp)) {
1972 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001973 printuid(", ", tcp->u_arg[1]);
1974 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001975 }
1976 return 0;
1977}
1978
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001979int
1980sys_fchownat(struct tcb *tcp)
1981{
1982 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001983 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001984 printpath(tcp, tcp->u_arg[1]);
1985 printuid(", ", tcp->u_arg[2]);
1986 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001987 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001988 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
1989 }
1990 return 0;
1991}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001992
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001993int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001994sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001995{
1996 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001997 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001998 printuid(", ", tcp->u_arg[1]);
1999 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002000 }
2001 return 0;
2002}
2003
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002004static int
2005decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002006{
2007 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002008 printpath(tcp, tcp->u_arg[offset]);
2009 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002010 }
2011 return 0;
2012}
2013
2014int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002015sys_chmod(struct tcb *tcp)
2016{
2017 return decode_chmod(tcp, 0);
2018}
2019
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002020int
2021sys_fchmodat(struct tcb *tcp)
2022{
2023 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002024 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002025 return decode_chmod(tcp, 1);
2026}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002027
2028int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002029sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002030{
2031 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002032 printfd(tcp, tcp->u_arg[0]);
2033 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002034 }
2035 return 0;
2036}
2037
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002038#ifdef ALPHA
2039int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002040sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002041{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002042 if (entering(tcp)) {
2043 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002044 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002045 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2046 }
2047 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002048}
2049#endif
2050
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002051static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002052decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002053{
2054 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002055 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002056 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002057 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002058 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00002059 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002060 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00002061 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2062 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002063 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002064 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002065 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00002066 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002067 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00002068 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002069 }
2070 return 0;
2071}
2072
2073int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002074sys_utimes(struct tcb *tcp)
2075{
Roland McGrath6afc5652007-07-24 01:57:11 +00002076 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002077}
2078
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002079int
2080sys_futimesat(struct tcb *tcp)
2081{
2082 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002083 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002084 return decode_utimes(tcp, 1, 0);
2085}
2086
2087int
2088sys_utimensat(struct tcb *tcp)
2089{
2090 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002091 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002092 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002093 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002094 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2095 }
2096 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002097}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002098
2099int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002100sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002101{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002102 union {
2103 long utl[2];
2104 int uti[2];
2105 } u;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002106
2107 if (entering(tcp)) {
2108 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002109 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002110 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002111 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002112 else if (!verbose(tcp))
2113 tprintf("%#lx", tcp->u_arg[1]);
Roland McGrath7e9817c2007-07-05 20:31:58 +00002114 else if (umoven(tcp, tcp->u_arg[1],
2115 2 * personality_wordsize[current_personality],
2116 (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002117 tprints("[?, ?]");
Roland McGrath7e9817c2007-07-05 20:31:58 +00002118 else if (personality_wordsize[current_personality]
2119 == sizeof u.utl[0]) {
2120 tprintf("[%s,", sprinttime(u.utl[0]));
2121 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002122 }
Roland McGrath7e9817c2007-07-05 20:31:58 +00002123 else if (personality_wordsize[current_personality]
2124 == sizeof u.uti[0]) {
2125 tprintf("[%s,", sprinttime(u.uti[0]));
2126 tprintf(" %s]", sprinttime(u.uti[1]));
2127 }
2128 else
2129 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002130 }
2131 return 0;
2132}
2133
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002134static int
2135decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002136{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002137 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002138
2139 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002140 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002141 tprintf(", %s", sprintmode(mode));
2142 switch (mode & S_IFMT) {
2143 case S_IFCHR: case S_IFBLK:
2144#ifdef LINUXSPARC
2145 if (current_personality == 1)
2146 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002147 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2148 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002149 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002150#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002151 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002152 (unsigned long) major(tcp->u_arg[offset + 2]),
2153 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002154 break;
2155 default:
2156 break;
2157 }
2158 }
2159 return 0;
2160}
2161
2162int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002163sys_mknod(struct tcb *tcp)
2164{
2165 return decode_mknod(tcp, 0);
2166}
2167
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002168int
2169sys_mknodat(struct tcb *tcp)
2170{
2171 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002172 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002173 return decode_mknod(tcp, 1);
2174}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002175
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002176
2177int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002178sys_fsync(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002179{
2180 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002181 printfd(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002182 }
2183 return 0;
2184}
2185
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002186
2187static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002188printdir(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002189{
2190 struct dirent d;
2191
2192 if (!verbose(tcp)) {
2193 tprintf("%#lx", addr);
2194 return;
2195 }
2196 if (umove(tcp, addr, &d) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002197 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002198 return;
2199 }
2200 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002201 tprints("d_name=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002202 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002203 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002204}
2205
2206int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002207sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002208{
2209 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002210 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002211 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002212 } else {
2213 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2214 tprintf("%#lx", tcp->u_arg[1]);
2215 else
2216 printdir(tcp, tcp->u_arg[1]);
2217 /* Not much point in printing this out, it is always 1. */
2218 if (tcp->u_arg[2] != 1)
2219 tprintf(", %lu", tcp->u_arg[2]);
2220 }
2221 return 0;
2222}
2223
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002224
Roland McGratha4d48532005-06-08 20:45:28 +00002225static const struct xlat direnttypes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002226 { DT_UNKNOWN, "DT_UNKNOWN" },
2227 { DT_FIFO, "DT_FIFO" },
2228 { DT_CHR, "DT_CHR" },
2229 { DT_DIR, "DT_DIR" },
2230 { DT_BLK, "DT_BLK" },
2231 { DT_REG, "DT_REG" },
2232 { DT_LNK, "DT_LNK" },
2233 { DT_SOCK, "DT_SOCK" },
2234 { DT_WHT, "DT_WHT" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002235 { 0, NULL },
2236};
2237
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002238
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002239int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002240sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002241{
2242 int i, len, dents = 0;
2243 char *buf;
2244
2245 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002246 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002247 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002248 return 0;
2249 }
2250 if (syserror(tcp) || !verbose(tcp)) {
2251 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2252 return 0;
2253 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002254 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002255 /* Beware of insanely large or negative values in tcp->u_rval */
2256 if (tcp->u_rval > 1024*1024)
2257 len = 1024*1024;
2258 if (tcp->u_rval < 0)
2259 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002260 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002261 if (len && !buf)
2262 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002263 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002264 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002265 free(buf);
2266 return 0;
2267 }
2268 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002269 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002270 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002271 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002272 if (!abbrev(tcp)) {
2273 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2274 i ? " " : "", d->d_ino, d->d_off);
2275 tprintf("d_reclen=%u, d_name=\"%s\"}",
2276 d->d_reclen, d->d_name);
2277 }
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002278 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002279 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002280 break;
2281 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002282 i += d->d_reclen;
2283 dents++;
2284 }
2285 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002286 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002287 else
2288 tprintf("/* %u entries */", dents);
2289 tprintf(", %lu", tcp->u_arg[2]);
2290 free(buf);
2291 return 0;
2292}
2293
John Hughesbdf48f52001-03-06 15:08:09 +00002294
2295#if _LFS64_LARGEFILE
2296int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002297sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002298{
2299 int i, len, dents = 0;
2300 char *buf;
2301
2302 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002303 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002304 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002305 return 0;
2306 }
2307 if (syserror(tcp) || !verbose(tcp)) {
2308 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2309 return 0;
2310 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002311
John Hughesbdf48f52001-03-06 15:08:09 +00002312 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002313 /* Beware of insanely large or negative tcp->u_rval */
2314 if (tcp->u_rval > 1024*1024)
2315 len = 1024*1024;
2316 if (tcp->u_rval < 0)
2317 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002318 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002319 if (len && !buf)
2320 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002321
John Hughesbdf48f52001-03-06 15:08:09 +00002322 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002323 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002324 free(buf);
2325 return 0;
2326 }
2327 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002328 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002329 for (i = 0; i < len;) {
2330 struct dirent64 *d = (struct dirent64 *) &buf[i];
John Hughesbdf48f52001-03-06 15:08:09 +00002331 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002332 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002333 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002334 d->d_ino,
2335 d->d_off);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002336 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002337 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002338 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002339 tprintf("d_reclen=%u, d_name=\"%s\"}",
2340 d->d_reclen, d->d_name);
2341 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002342 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002343 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002344 break;
2345 }
John Hughesbdf48f52001-03-06 15:08:09 +00002346 i += d->d_reclen;
2347 dents++;
2348 }
2349 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002350 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002351 else
2352 tprintf("/* %u entries */", dents);
2353 tprintf(", %lu", tcp->u_arg[2]);
2354 free(buf);
2355 return 0;
2356}
2357#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002358
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002359
2360int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002361sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002362{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002363 if (exiting(tcp)) {
2364 if (syserror(tcp))
2365 tprintf("%#lx", tcp->u_arg[0]);
2366 else
2367 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2368 tprintf(", %lu", tcp->u_arg[1]);
2369 }
2370 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002371}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002372
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002373
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002374#ifdef HAVE_SYS_ASYNCH_H
2375
2376int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002377sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002378{
2379 struct aio_result_t res;
2380
2381 if (entering(tcp)) {
2382 tprintf("%lu, ", tcp->u_arg[0]);
2383 } else {
2384 if (syserror(tcp))
2385 tprintf("%#lx", tcp->u_arg[1]);
2386 else
2387 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2388 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2389 printxval(whence, tcp->u_arg[4], "L_???");
2390 if (syserror(tcp) || tcp->u_arg[5] == 0
2391 || umove(tcp, tcp->u_arg[5], &res) < 0)
2392 tprintf(", %#lx", tcp->u_arg[5]);
2393 else
2394 tprintf(", {aio_return %d aio_errno %d}",
2395 res.aio_return, res.aio_errno);
2396 }
2397 return 0;
2398}
2399
2400int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002401sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002402{
2403 struct aio_result_t res;
2404
2405 if (entering(tcp)) {
2406 tprintf("%lu, ", tcp->u_arg[0]);
2407 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2408 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2409 printxval(whence, tcp->u_arg[4], "L_???");
2410 }
2411 else {
2412 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002413 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002414 else if (syserror(tcp)
2415 || umove(tcp, tcp->u_arg[5], &res) < 0)
2416 tprintf(", %#lx", tcp->u_arg[5]);
2417 else
2418 tprintf(", {aio_return %d aio_errno %d}",
2419 res.aio_return, res.aio_errno);
2420 }
2421 return 0;
2422}
2423
2424int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002425sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002426{
2427 if (entering(tcp))
2428 printtv(tcp, tcp->u_arg[0]);
2429 return 0;
2430}
2431
2432int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002433sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002434{
2435 struct aio_result_t res;
2436
2437 if (exiting(tcp)) {
2438 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002439 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002440 else if (syserror(tcp)
2441 || umove(tcp, tcp->u_arg[0], &res) < 0)
2442 tprintf("%#lx", tcp->u_arg[0]);
2443 else
2444 tprintf("{aio_return %d aio_errno %d}",
2445 res.aio_return, res.aio_errno);
2446 }
2447 return 0;
2448}
2449
2450#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002451
Roland McGratha4d48532005-06-08 20:45:28 +00002452static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002453#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002454 { XATTR_CREATE, "XATTR_CREATE" },
2455 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002456#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002457 { 0, NULL }
2458};
2459
Roland McGrath3292e222004-08-31 06:30:48 +00002460static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002461print_xattr_val(struct tcb *tcp, int failed,
2462 unsigned long arg,
2463 unsigned long insize,
2464 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002465{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002466 if (!failed) {
2467 unsigned long capacity = 4 * size + 1;
2468 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2469 if (buf == NULL || /* probably a bogus size argument */
2470 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2471 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002472 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002473 else {
2474 unsigned char *out = buf;
2475 unsigned char *in = &buf[3 * size];
2476 size_t i;
2477 for (i = 0; i < size; ++i) {
2478 if (isprint(in[i]))
2479 *out++ = in[i];
2480 else {
2481#define tohex(n) "0123456789abcdef"[n]
2482 *out++ = '\\';
2483 *out++ = 'x';
2484 *out++ = tohex(in[i] / 16);
2485 *out++ = tohex(in[i] % 16);
2486 }
2487 }
2488 /* Don't print terminating NUL if there is one. */
2489 if (i > 0 && in[i - 1] == '\0')
2490 out -= 4;
2491 *out = '\0';
2492 tprintf(", \"%s\", %ld", buf, insize);
2493 }
2494 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002495 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002496 if (failed)
2497 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002498}
2499
Roland McGrath186c5ac2002-12-15 23:58:23 +00002500int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002501sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002502{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002503 if (entering(tcp)) {
2504 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002505 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002506 printstr(tcp, tcp->u_arg[1], -1);
2507 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002508 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002509 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2510 }
2511 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002512}
2513
2514int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002515sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002516{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002517 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002518 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002519 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002520 printstr(tcp, tcp->u_arg[1], -1);
2521 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002522 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002523 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2524 }
2525 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002526}
2527
2528int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002529sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002530{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002531 if (entering(tcp)) {
2532 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002533 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002534 printstr(tcp, tcp->u_arg[1], -1);
2535 } else {
2536 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2537 tcp->u_rval);
2538 }
2539 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002540}
2541
2542int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002543sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002544{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002545 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002546 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002547 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002548 printstr(tcp, tcp->u_arg[1], -1);
2549 } else {
2550 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2551 tcp->u_rval);
2552 }
2553 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002554}
2555
2556int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002557sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002558{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002559 if (entering(tcp)) {
2560 printpath(tcp, tcp->u_arg[0]);
2561 } else {
2562 /* XXX Print value in format */
2563 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2564 }
2565 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002566}
2567
2568int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002569sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002570{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002571 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002572 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002573 } else {
2574 /* XXX Print value in format */
2575 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2576 }
2577 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002578}
2579
2580int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002581sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002582{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002583 if (entering(tcp)) {
2584 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002585 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002586 printstr(tcp, tcp->u_arg[1], -1);
2587 }
2588 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002589}
2590
2591int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002592sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002593{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002594 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002595 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002596 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002597 printstr(tcp, tcp->u_arg[1], -1);
2598 }
2599 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002600}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002601
2602
2603static const struct xlat advise[] = {
2604 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2605 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2606 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2607 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2608 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2609 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2610 { 0, NULL }
2611};
2612
2613
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002614int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002615sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002616{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002617 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002618 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002619 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002620 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002621 argn = printllval(tcp, "%lld", 1);
2622 tprintf(", %ld, ", tcp->u_arg[argn++]);
2623 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002624 }
2625 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002626}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002627
2628
2629int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002630sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002631{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002632 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002633 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002634 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002635 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002636#if defined ARM || defined POWERPC
2637 argn = printllval(tcp, "%lld, ", 2);
2638#else
2639 argn = printllval(tcp, "%lld, ", 1);
2640#endif
2641 argn = printllval(tcp, "%lld, ", argn);
2642#if defined ARM || defined POWERPC
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002643 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002644#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002645 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002646#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002647 }
2648 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002649}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002650
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002651static const struct xlat inotify_modes[] = {
Dmitry V. Levind475c062011-03-03 01:02:41 +00002652 { 0x00000001, "IN_ACCESS" },
2653 { 0x00000002, "IN_MODIFY" },
2654 { 0x00000004, "IN_ATTRIB" },
2655 { 0x00000008, "IN_CLOSE_WRITE"},
2656 { 0x00000010, "IN_CLOSE_NOWRITE"},
2657 { 0x00000020, "IN_OPEN" },
2658 { 0x00000040, "IN_MOVED_FROM" },
2659 { 0x00000080, "IN_MOVED_TO" },
2660 { 0x00000100, "IN_CREATE" },
2661 { 0x00000200, "IN_DELETE" },
2662 { 0x00000400, "IN_DELETE_SELF"},
2663 { 0x00000800, "IN_MOVE_SELF" },
2664 { 0x00002000, "IN_UNMOUNT" },
2665 { 0x00004000, "IN_Q_OVERFLOW" },
2666 { 0x00008000, "IN_IGNORED" },
2667 { 0x01000000, "IN_ONLYDIR" },
2668 { 0x02000000, "IN_DONT_FOLLOW"},
2669 { 0x20000000, "IN_MASK_ADD" },
2670 { 0x40000000, "IN_ISDIR" },
2671 { 0x80000000, "IN_ONESHOT" },
2672 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002673};
2674
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002675static const struct xlat inotify_init_flags[] = {
2676 { 0x00000800, "IN_NONBLOCK" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002677 { 0x00080000, "IN_CLOEXEC" },
2678 { 0, NULL }
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002679};
2680
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002681int
2682sys_inotify_add_watch(struct tcb *tcp)
2683{
2684 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002685 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002686 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002687 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002688 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002689 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2690 }
2691 return 0;
2692}
2693
2694int
2695sys_inotify_rm_watch(struct tcb *tcp)
2696{
2697 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002698 printfd(tcp, tcp->u_arg[0]);
2699 tprintf(", %ld", tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002700 }
2701 return 0;
2702}
Roland McGrath96a96612008-05-20 04:56:18 +00002703
2704int
Mark Wielaardbab89402010-03-21 14:41:26 +01002705sys_inotify_init1(struct tcb *tcp)
2706{
2707 if (entering(tcp))
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002708 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
Mark Wielaardbab89402010-03-21 14:41:26 +01002709 return 0;
2710}
2711
2712int
Roland McGrath96a96612008-05-20 04:56:18 +00002713sys_fallocate(struct tcb *tcp)
2714{
2715 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002716 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002717 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002718 tprints(", ");
Roland McGrath96a96612008-05-20 04:56:18 +00002719 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002720 argn = printllval(tcp, "%llu, ", 2); /* offset */
2721 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002722 }
2723 return 0;
2724}