blob: bac28d889ac34dd33726bea98b2dd9ec6ab8a59f [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.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include <dirent.h>
Dmitry V. Levin88293652012-03-09 21:02:19 +000033#include <sys/swap.h>
Roland McGrathc531e572008-08-01 01:13:10 +000034
Denys Vlasenko84703742012-02-25 02:38:52 +010035#ifdef LINUXSPARC
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000036struct stat {
37 unsigned short st_dev;
38 unsigned int st_ino;
39 unsigned short st_mode;
40 short st_nlink;
41 unsigned short st_uid;
42 unsigned short st_gid;
43 unsigned short st_rdev;
44 unsigned int st_size;
45 int st_atime;
46 unsigned int __unused1;
47 int st_mtime;
48 unsigned int __unused2;
49 int st_ctime;
50 unsigned int __unused3;
51 int st_blksize;
52 int st_blocks;
53 unsigned int __unused4[2];
54};
Denys Vlasenko84703742012-02-25 02:38:52 +010055# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +000056struct stat_sparc64 {
57 unsigned int st_dev;
58 unsigned long st_ino;
59 unsigned int st_mode;
60 unsigned int st_nlink;
61 unsigned int st_uid;
62 unsigned int st_gid;
63 unsigned int st_rdev;
64 long st_size;
65 long st_atime;
66 long st_mtime;
67 long st_ctime;
68 long st_blksize;
69 long st_blocks;
70 unsigned long __unused4[2];
71};
Denys Vlasenko84703742012-02-25 02:38:52 +010072# endif /* SPARC64 */
73# define stat kernel_stat
74# include <asm/stat.h>
75# undef stat
76#else
77# undef dev_t
78# undef ino_t
79# undef mode_t
80# undef nlink_t
81# undef uid_t
82# undef gid_t
83# undef off_t
84# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +010085# define dev_t __kernel_dev_t
86# define ino_t __kernel_ino_t
87# define mode_t __kernel_mode_t
88# define nlink_t __kernel_nlink_t
89# define uid_t __kernel_uid_t
90# define gid_t __kernel_gid_t
91# define off_t __kernel_off_t
92# define loff_t __kernel_loff_t
Wichert Akkermana6013701999-07-08 14:00:58 +000093
Denys Vlasenko84703742012-02-25 02:38:52 +010094# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +000095
Denys Vlasenko84703742012-02-25 02:38:52 +010096# undef dev_t
97# undef ino_t
98# undef mode_t
99# undef nlink_t
100# undef uid_t
101# undef gid_t
102# undef off_t
103# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100104# define dev_t dev_t
105# define ino_t ino_t
106# define mode_t mode_t
107# define nlink_t nlink_t
108# define uid_t uid_t
109# define gid_t gid_t
110# define off_t off_t
111# define loff_t loff_t
112#endif
113
114#ifdef HPPA /* asm-parisc/stat.h defines stat64 */
115# undef stat64
116#endif
117#define stat libc_stat
118#define stat64 libc_stat64
119#include <sys/stat.h>
120#undef stat
121#undef stat64
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100122/* These might be macros. */
Denys Vlasenko84703742012-02-25 02:38:52 +0100123#undef st_atime
124#undef st_mtime
125#undef st_ctime
126#ifdef HPPA
127# define stat64 hpux_stat64
128#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000129
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000130#include <fcntl.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000131#ifdef HAVE_SYS_VFS_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100132# include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000133#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +0000134#ifdef HAVE_LINUX_XATTR_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100135# include <linux/xattr.h>
Denys Vlasenkoed720fd2012-02-25 02:24:03 +0100136#else
Denys Vlasenko84703742012-02-25 02:38:52 +0100137# define XATTR_CREATE 1
138# define XATTR_REPLACE 2
Roland McGrath186c5ac2002-12-15 23:58:23 +0000139#endif
140
John Hughes70623be2001-03-08 13:59:00 +0000141#if HAVE_LONG_LONG_OFF_T
142/*
143 * Ugly hacks for systems that have typedef long long off_t
144 */
Denys Vlasenko84703742012-02-25 02:38:52 +0100145# define stat64 stat
146# define HAVE_STAT64 1 /* Ugly hack */
Denys Vlasenko84703742012-02-25 02:38:52 +0100147# define sys_stat64 sys_stat
148# define sys_fstat64 sys_fstat
149# define sys_lstat64 sys_lstat
150# define sys_lseek64 sys_lseek
151# define sys_truncate64 sys_truncate
152# define sys_ftruncate64 sys_ftruncate
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000153#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000154
155#ifdef MAJOR_IN_SYSMACROS
Denys Vlasenko84703742012-02-25 02:38:52 +0100156# include <sys/sysmacros.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000157#endif
158
159#ifdef MAJOR_IN_MKDEV
Denys Vlasenko84703742012-02-25 02:38:52 +0100160# include <sys/mkdev.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000161#endif
162
163#ifdef HAVE_SYS_ASYNCH_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100164# include <sys/asynch.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000165#endif
166
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100167struct kernel_dirent {
168 unsigned long d_ino;
169 unsigned long d_off;
170 unsigned short d_reclen;
171 char d_name[1];
172};
173
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000174const struct xlat open_access_modes[] = {
175 { O_RDONLY, "O_RDONLY" },
176 { O_WRONLY, "O_WRONLY" },
177 { O_RDWR, "O_RDWR" },
178#ifdef O_ACCMODE
179 { O_ACCMODE, "O_ACCMODE" },
180#endif
181 { 0, NULL },
182};
183
184const struct xlat open_mode_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000185 { O_CREAT, "O_CREAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186 { O_EXCL, "O_EXCL" },
187 { O_NOCTTY, "O_NOCTTY" },
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000188 { O_TRUNC, "O_TRUNC" },
189 { O_APPEND, "O_APPEND" },
190 { O_NONBLOCK, "O_NONBLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000191#ifdef O_SYNC
192 { O_SYNC, "O_SYNC" },
193#endif
194#ifdef O_ASYNC
195 { O_ASYNC, "O_ASYNC" },
196#endif
197#ifdef O_DSYNC
198 { O_DSYNC, "O_DSYNC" },
199#endif
200#ifdef O_RSYNC
201 { O_RSYNC, "O_RSYNC" },
202#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000203#if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000204 { O_NDELAY, "O_NDELAY" },
205#endif
206#ifdef O_PRIV
207 { O_PRIV, "O_PRIV" },
208#endif
209#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000210 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000211#endif
212#ifdef O_LARGEFILE
Roland McGrathfee836e2005-02-02 22:11:32 +0000213# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
214# undef O_LARGEFILE
215# ifdef SPARC64
216# define O_LARGEFILE 0x40000
217# elif defined X86_64 || defined S390X
218# define O_LARGEFILE 0100000
219# endif
220# endif
Roland McGrath663a8a02005-02-04 09:49:56 +0000221# ifdef O_LARGEFILE
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200222 { O_LARGEFILE, "O_LARGEFILE" },
Roland McGrath663a8a02005-02-04 09:49:56 +0000223# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000224#endif
225#ifdef O_DIRECTORY
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200226 { O_DIRECTORY, "O_DIRECTORY" },
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000227#endif
228#ifdef O_NOFOLLOW
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200229 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000230#endif
Roland McGrath1025c3e2005-05-09 07:40:35 +0000231#ifdef O_NOATIME
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200232 { O_NOATIME, "O_NOATIME" },
Roland McGrath1025c3e2005-05-09 07:40:35 +0000233#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000234#ifdef O_CLOEXEC
235 { O_CLOEXEC, "O_CLOEXEC" },
236#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000237#ifdef FNDELAY
238 { FNDELAY, "FNDELAY" },
239#endif
240#ifdef FAPPEND
241 { FAPPEND, "FAPPEND" },
242#endif
243#ifdef FMARK
244 { FMARK, "FMARK" },
245#endif
246#ifdef FDEFER
247 { FDEFER, "FDEFER" },
248#endif
249#ifdef FASYNC
250 { FASYNC, "FASYNC" },
251#endif
252#ifdef FSHLOCK
253 { FSHLOCK, "FSHLOCK" },
254#endif
255#ifdef FEXLOCK
256 { FEXLOCK, "FEXLOCK" },
257#endif
258#ifdef FCREAT
259 { FCREAT, "FCREAT" },
260#endif
261#ifdef FTRUNC
262 { FTRUNC, "FTRUNC" },
263#endif
264#ifdef FEXCL
265 { FEXCL, "FEXCL" },
266#endif
267#ifdef FNBIO
268 { FNBIO, "FNBIO" },
269#endif
270#ifdef FSYNC
271 { FSYNC, "FSYNC" },
272#endif
273#ifdef FNOCTTY
274 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000275#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000276#ifdef O_SHLOCK
277 { O_SHLOCK, "O_SHLOCK" },
278#endif
279#ifdef O_EXLOCK
280 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000281#endif
282 { 0, NULL },
283};
284
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000285#ifndef AT_FDCWD
286# define AT_FDCWD -100
287#endif
288
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000289/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
290 * extension to get the right value. We do this by declaring fd as int here.
291 */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000292static void
Dmitry V. Levin31382132011-03-04 05:08:02 +0300293print_dirfd(struct tcb *tcp, int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000294{
295 if (fd == AT_FDCWD)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200296 tprints("AT_FDCWD, ");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200297 else {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300298 printfd(tcp, fd);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200299 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300300 }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000301}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000302
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000303/*
304 * low bits of the open(2) flags define access mode,
305 * other bits are real flags.
306 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000307const char *
308sprint_open_modes(mode_t flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000309{
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100310 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000311 char *p;
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100312 char sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000313 const char *str;
314 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000315
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100316 sep = ' ';
317 p = stpcpy(outstr, "flags");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000318 str = xlookup(open_access_modes, flags & 3);
319 if (str) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100320 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200321 p = stpcpy(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000322 flags &= ~3;
323 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000324 return outstr;
325 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000326 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000327
328 for (x = open_mode_flags; x->str; x++) {
329 if ((flags & x->val) == x->val) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100330 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200331 p = stpcpy(p, x->str);
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000332 flags &= ~x->val;
333 if (!flags)
334 return outstr;
335 sep = '|';
336 }
337 }
338 /* flags is still nonzero */
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100339 *p++ = sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000340 sprintf(p, "%#x", flags);
341 return outstr;
342}
343
344void
345tprint_open_modes(mode_t flags)
346{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200347 tprints(sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000348}
349
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000350static int
351decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000352{
353 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000354 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200355 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000356 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000357 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000358 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000359 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000360 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000361 }
362 }
363 return 0;
364}
365
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000366int
367sys_open(struct tcb *tcp)
368{
369 return decode_open(tcp, 0);
370}
371
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000372int
373sys_openat(struct tcb *tcp)
374{
375 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300376 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000377 return decode_open(tcp, 1);
378}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000379
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000380#ifdef LINUXSPARC
Roland McGratha4d48532005-06-08 20:45:28 +0000381static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000382 { 0, "O_RDWR" },
383 { 1, "O_RDONLY" },
384 { 2, "O_WRONLY" },
385 { 0x80, "O_NONBLOCK" },
386 { 8, "O_APPEND" },
387 { 0x100, "O_CREAT" },
388 { 0x200, "O_TRUNC" },
389 { 0x400, "O_EXCL" },
390 { 0x800, "O_NOCTTY" },
391 { 0x10, "O_SYNC" },
392 { 0x40, "O_DSYNC" },
393 { 0x8000, "O_RSYNC" },
394 { 4, "O_NDELAY" },
395 { 0x1000, "O_PRIV" },
396 { 0, NULL },
397};
398
399int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000400solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000401{
402 if (entering(tcp)) {
403 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200404 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000405 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000406 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000407 if (tcp->u_arg[1] & 0x100) {
408 /* mode */
409 tprintf(", %#lo", tcp->u_arg[2]);
410 }
411 }
412 return 0;
413}
414
415#endif
416
417int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000418sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000419{
420 if (entering(tcp)) {
421 printpath(tcp, tcp->u_arg[0]);
422 tprintf(", %#lo", tcp->u_arg[1]);
423 }
424 return 0;
425}
426
Roland McGrathd9f816f2004-09-04 03:39:20 +0000427static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000428 { F_OK, "F_OK", },
429 { R_OK, "R_OK" },
430 { W_OK, "W_OK" },
431 { X_OK, "X_OK" },
432#ifdef EFF_ONLY_OK
433 { EFF_ONLY_OK, "EFF_ONLY_OK" },
434#endif
435#ifdef EX_OK
436 { EX_OK, "EX_OK" },
437#endif
438 { 0, NULL },
439};
440
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000441static int
442decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000443{
444 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000445 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200446 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000447 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000448 }
449 return 0;
450}
451
452int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000453sys_access(struct tcb *tcp)
454{
455 return decode_access(tcp, 0);
456}
457
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000458int
459sys_faccessat(struct tcb *tcp)
460{
461 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300462 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000463 return decode_access(tcp, 1);
464}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000465
466int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000467sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000468{
469 if (entering(tcp)) {
470 tprintf("%#lo", tcp->u_arg[0]);
471 }
472 return RVAL_OCTAL;
473}
474
Roland McGrathd9f816f2004-09-04 03:39:20 +0000475static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000476 { SEEK_SET, "SEEK_SET" },
477 { SEEK_CUR, "SEEK_CUR" },
478 { SEEK_END, "SEEK_END" },
479 { 0, NULL },
480};
481
John Hughes70623be2001-03-08 13:59:00 +0000482#ifndef HAVE_LONG_LONG_OFF_T
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100483#if defined(LINUX_MIPSN32)
Roland McGrath542c2c62008-05-20 01:11:56 +0000484int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000485sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000486{
487 long long offset;
488 int _whence;
489
490 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300491 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200492 tprints(", ");
Roland McGrath542c2c62008-05-20 01:11:56 +0000493 offset = tcp->ext_arg[1];
494 _whence = tcp->u_arg[2];
495 if (_whence == SEEK_SET)
496 tprintf("%llu, ", offset);
497 else
498 tprintf("%lld, ", offset);
499 printxval(whence, _whence, "SEEK_???");
500 }
501 return RVAL_UDECIMAL;
502}
503#else /* !LINUX_MIPSN32 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000504int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000505sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000506{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000507 off_t offset;
508 int _whence;
509
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000510 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300511 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200512 tprints(", ");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000513 offset = tcp->u_arg[1];
514 _whence = tcp->u_arg[2];
515 if (_whence == SEEK_SET)
516 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000518 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000519 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000520 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000521 return RVAL_UDECIMAL;
522}
Roland McGrath542c2c62008-05-20 01:11:56 +0000523#endif /* LINUX_MIPSN32 */
John Hughes5a826b82001-03-07 13:21:24 +0000524#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000526int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000527sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000528{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000529 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300530 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000531 /*
532 * This one call takes explicitly two 32-bit arguments hi, lo,
533 * rather than one 64-bit argument for which LONG_LONG works
534 * appropriate for the native byte order.
535 */
536 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300537 tprintf(", %llu, ",
538 ((long long int) tcp->u_arg[1]) << 32 |
539 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000540 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300541 tprintf(", %lld, ",
542 ((long long int) tcp->u_arg[1]) << 32 |
543 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000544 }
545 else {
546 long long int off;
547 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
548 tprintf("%#lx, ", tcp->u_arg[3]);
549 else
550 tprintf("[%llu], ", off);
551 printxval(whence, tcp->u_arg[4], "SEEK_???");
552 }
553 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000554}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000555
556int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000557sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000558{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000559 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100560 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300561 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200562 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100563 argn = printllval(tcp, "%lld", 1);
564 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000565 }
566 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000567}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000568
John Hughes70623be2001-03-08 13:59:00 +0000569#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000570int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000571sys_lseek64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +0000572{
573 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100574 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300575 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200576 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000577 if (tcp->u_arg[3] == SEEK_SET)
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100578 argn = printllval(tcp, "%llu, ", 1);
John Hughesbdf48f52001-03-06 15:08:09 +0000579 else
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100580 argn = printllval(tcp, "%lld, ", 1);
581 printxval(whence, tcp->u_arg[argn], "SEEK_???");
John Hughesbdf48f52001-03-06 15:08:09 +0000582 }
583 return RVAL_LUDECIMAL;
584}
585#endif
586
John Hughes70623be2001-03-08 13:59:00 +0000587#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000588int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000589sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000590{
591 if (entering(tcp)) {
592 printpath(tcp, tcp->u_arg[0]);
593 tprintf(", %lu", tcp->u_arg[1]);
594 }
595 return 0;
596}
John Hughes5a826b82001-03-07 13:21:24 +0000597#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000598
John Hughes70623be2001-03-08 13:59:00 +0000599#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000600int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000601sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000602{
603 if (entering(tcp)) {
604 printpath(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100605 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000606 }
607 return 0;
608}
609#endif
610
John Hughes70623be2001-03-08 13:59:00 +0000611#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000612int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000613sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000614{
615 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300616 printfd(tcp, tcp->u_arg[0]);
617 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000618 }
619 return 0;
620}
John Hughes5a826b82001-03-07 13:21:24 +0000621#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000622
John Hughes70623be2001-03-08 13:59:00 +0000623#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000624int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000625sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000626{
627 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300628 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200629 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100630 printllval(tcp, "%llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000631 }
632 return 0;
633}
634#endif
635
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000636/* several stats */
637
Roland McGrathd9f816f2004-09-04 03:39:20 +0000638static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000639 { S_IFREG, "S_IFREG" },
640 { S_IFSOCK, "S_IFSOCK" },
641 { S_IFIFO, "S_IFIFO" },
642 { S_IFLNK, "S_IFLNK" },
643 { S_IFDIR, "S_IFDIR" },
644 { S_IFBLK, "S_IFBLK" },
645 { S_IFCHR, "S_IFCHR" },
646 { 0, NULL },
647};
648
Roland McGrathf9c49b22004-10-06 22:11:54 +0000649static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000650sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000651{
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100652 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
653 + sizeof(int)*3
654 + /*paranoia:*/ 8];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000655 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000656
657 if ((mode & S_IFMT) == 0)
658 s = "";
659 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
660 sprintf(buf, "%#o", mode);
661 return buf;
662 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100663 s = buf + sprintf(buf, "%s%s%s%s", s,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000664 (mode & S_ISUID) ? "|S_ISUID" : "",
665 (mode & S_ISGID) ? "|S_ISGID" : "",
666 (mode & S_ISVTX) ? "|S_ISVTX" : "");
667 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
668 if (mode)
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100669 sprintf((char*)s, "|%#o", mode);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000670 s = (*buf == '|') ? buf + 1 : buf;
671 return *s ? s : "0";
672}
673
674static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000675sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000676{
677 struct tm *tmp;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100678 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000679
680 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000681 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000682 return buf;
683 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200684 tmp = localtime(&t);
685 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000686 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
687 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
688 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
689 else
690 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
691
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000692 return buf;
693}
694
695#ifdef LINUXSPARC
696typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000697 int tv_sec;
698 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000699} timestruct_t;
700
701struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000702 unsigned st_dev;
703 int st_pad1[3]; /* network id */
704 unsigned st_ino;
705 unsigned st_mode;
706 unsigned st_nlink;
707 unsigned st_uid;
708 unsigned st_gid;
709 unsigned st_rdev;
710 int st_pad2[2];
711 int st_size;
712 int st_pad3; /* st_size, off_t expansion */
713 timestruct_t st_atime;
714 timestruct_t st_mtime;
715 timestruct_t st_ctime;
716 int st_blksize;
717 int st_blocks;
718 char st_fstype[16];
719 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000720};
721
722static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000723printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000724{
725 struct solstat statbuf;
726
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000727 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200728 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000729 return;
730 }
731 if (!abbrev(tcp)) {
732 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
733 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
734 (unsigned long) (statbuf.st_dev & 0x3ffff),
735 (unsigned long) statbuf.st_ino,
736 sprintmode(statbuf.st_mode));
737 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
738 (unsigned long) statbuf.st_nlink,
739 (unsigned long) statbuf.st_uid,
740 (unsigned long) statbuf.st_gid);
741 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
742 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
743 }
744 else
745 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
746 switch (statbuf.st_mode & S_IFMT) {
747 case S_IFCHR: case S_IFBLK:
748 tprintf("st_rdev=makedev(%lu, %lu), ",
749 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
750 (unsigned long) (statbuf.st_rdev & 0x3ffff));
751 break;
752 default:
753 tprintf("st_size=%u, ", statbuf.st_size);
754 break;
755 }
756 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000757 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
758 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
759 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000760 }
761 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200762 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000763}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000764
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100765#if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000766static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000767printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000768{
769 struct stat_sparc64 statbuf;
770
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000771 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200772 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000773 return;
774 }
775
776 if (!abbrev(tcp)) {
777 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
778 (unsigned long) major(statbuf.st_dev),
779 (unsigned long) minor(statbuf.st_dev),
780 (unsigned long) statbuf.st_ino,
781 sprintmode(statbuf.st_mode));
782 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
783 (unsigned long) statbuf.st_nlink,
784 (unsigned long) statbuf.st_uid,
785 (unsigned long) statbuf.st_gid);
786 tprintf("st_blksize=%lu, ",
787 (unsigned long) statbuf.st_blksize);
788 tprintf("st_blocks=%lu, ",
789 (unsigned long) statbuf.st_blocks);
790 }
791 else
792 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
793 switch (statbuf.st_mode & S_IFMT) {
794 case S_IFCHR: case S_IFBLK:
795 tprintf("st_rdev=makedev(%lu, %lu), ",
796 (unsigned long) major(statbuf.st_rdev),
797 (unsigned long) minor(statbuf.st_rdev));
798 break;
799 default:
800 tprintf("st_size=%lu, ", statbuf.st_size);
801 break;
802 }
803 if (!abbrev(tcp)) {
804 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
805 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100806 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000807 }
808 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200809 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000810}
811#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000812#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000813
Denys Vlasenko84703742012-02-25 02:38:52 +0100814#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200815struct stat_powerpc32 {
816 unsigned int st_dev;
817 unsigned int st_ino;
818 unsigned int st_mode;
819 unsigned short st_nlink;
820 unsigned int st_uid;
821 unsigned int st_gid;
822 unsigned int st_rdev;
823 unsigned int st_size;
824 unsigned int st_blksize;
825 unsigned int st_blocks;
826 unsigned int st_atime;
827 unsigned int st_atime_nsec;
828 unsigned int st_mtime;
829 unsigned int st_mtime_nsec;
830 unsigned int st_ctime;
831 unsigned int st_ctime_nsec;
832 unsigned int __unused4;
833 unsigned int __unused5;
834};
835
836static void
837printstat_powerpc32(struct tcb *tcp, long addr)
838{
839 struct stat_powerpc32 statbuf;
840
841 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200842 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200843 return;
844 }
845
846 if (!abbrev(tcp)) {
847 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
848 major(statbuf.st_dev), minor(statbuf.st_dev),
849 statbuf.st_ino,
850 sprintmode(statbuf.st_mode));
851 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
852 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
853 tprintf("st_blksize=%u, ", statbuf.st_blksize);
854 tprintf("st_blocks=%u, ", statbuf.st_blocks);
855 }
856 else
857 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
858 switch (statbuf.st_mode & S_IFMT) {
859 case S_IFCHR: case S_IFBLK:
860 tprintf("st_rdev=makedev(%lu, %lu), ",
861 (unsigned long) major(statbuf.st_rdev),
862 (unsigned long) minor(statbuf.st_rdev));
863 break;
864 default:
865 tprintf("st_size=%u, ", statbuf.st_size);
866 break;
867 }
868 if (!abbrev(tcp)) {
869 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
870 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100871 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200872 }
873 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200874 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200875}
Denys Vlasenko84703742012-02-25 02:38:52 +0100876#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200877
Roland McGratha4d48532005-06-08 20:45:28 +0000878static const struct xlat fileflags[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000879 { 0, NULL },
880};
881
John Hughes70623be2001-03-08 13:59:00 +0000882#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000883static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000884realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000885{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000886 if (!abbrev(tcp)) {
887 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
888 (unsigned long) major(statbuf->st_dev),
889 (unsigned long) minor(statbuf->st_dev),
890 (unsigned long) statbuf->st_ino,
891 sprintmode(statbuf->st_mode));
892 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
893 (unsigned long) statbuf->st_nlink,
894 (unsigned long) statbuf->st_uid,
895 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000896#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000897 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
898#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000899#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000900 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
901#endif
902 }
903 else
904 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
905 switch (statbuf->st_mode & S_IFMT) {
906 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000907#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000908 tprintf("st_rdev=makedev(%lu, %lu), ",
909 (unsigned long) major(statbuf->st_rdev),
910 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000911#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000912 tprintf("st_size=makedev(%lu, %lu), ",
913 (unsigned long) major(statbuf->st_size),
914 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000915#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000916 break;
917 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000918 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000919 break;
920 }
921 if (!abbrev(tcp)) {
922 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
923 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
924 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000925#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200926 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000927 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000928#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000929#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000930 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
931#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000932#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000933 tprintf(", st_level=%ld", statbuf->st_level);
934#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000935#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000936 tprintf(", st_fstype=%.*s",
937 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
938#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000939#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000940 tprintf(", st_gen=%u", statbuf->st_gen);
941#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200942 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000943 }
944 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200945 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000946}
947
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000948static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000949printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000950{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000951 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000952
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000953 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200954 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000955 return;
956 }
957 if (syserror(tcp) || !verbose(tcp)) {
958 tprintf("%#lx", addr);
959 return;
960 }
961
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000962#ifdef LINUXSPARC
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000963 if (current_personality == 1) {
964 printstatsol(tcp, addr);
965 return;
966 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000967#ifdef SPARC64
968 else if (current_personality == 2) {
969 printstat_sparc64(tcp, addr);
970 return;
971 }
972#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000973#endif /* LINUXSPARC */
974
Denys Vlasenko84703742012-02-25 02:38:52 +0100975#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200976 if (current_personality == 1) {
977 printstat_powerpc32(tcp, addr);
978 return;
979 }
980#endif
981
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000982 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200983 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000984 return;
985 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000986
987 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000988}
John Hughes70623be2001-03-08 13:59:00 +0000989#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000990
Denys Vlasenko84703742012-02-25 02:38:52 +0100991#if !defined HAVE_STAT64 && defined X86_64
Roland McGrathe6d0f712007-08-07 01:22:49 +0000992/*
993 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
994 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
995 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
996 * __GNUC__ is needed for the required __attribute__ below.
997 */
998struct stat64 {
999 unsigned long long st_dev;
1000 unsigned char __pad0[4];
1001 unsigned int __st_ino;
1002 unsigned int st_mode;
1003 unsigned int st_nlink;
1004 unsigned int st_uid;
1005 unsigned int st_gid;
1006 unsigned long long st_rdev;
1007 unsigned char __pad3[4];
1008 long long st_size;
1009 unsigned int st_blksize;
1010 unsigned long long st_blocks;
1011 unsigned int st_atime;
1012 unsigned int st_atime_nsec;
1013 unsigned int st_mtime;
1014 unsigned int st_mtime_nsec;
1015 unsigned int st_ctime;
1016 unsigned int st_ctime_nsec;
1017 unsigned long long st_ino;
1018} __attribute__((packed));
1019# define HAVE_STAT64 1
1020# define STAT64_SIZE 96
1021#endif
1022
Wichert Akkermanc7926982000-04-10 22:22:31 +00001023#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001024static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001025printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001026{
1027 struct stat64 statbuf;
1028
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001029#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001030 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1031#endif
1032
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001033 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001034 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001035 return;
1036 }
1037 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001038 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001039 return;
1040 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001041
1042#ifdef LINUXSPARC
1043 if (current_personality == 1) {
1044 printstatsol(tcp, addr);
1045 return;
1046 }
1047# ifdef SPARC64
1048 else if (current_personality == 2) {
1049 printstat_sparc64(tcp, addr);
1050 return;
1051 }
1052# endif
1053#endif /* LINUXSPARC */
1054
Denys Vlasenko84703742012-02-25 02:38:52 +01001055#if defined X86_64
Andreas Schwab61b74352009-10-16 11:37:13 +02001056 if (current_personality == 0) {
1057 printstat(tcp, addr);
1058 return;
1059 }
1060#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +00001061
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001062 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001063 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001064 return;
1065 }
1066
1067 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001068#ifdef HAVE_LONG_LONG
1069 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1070#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001071 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001072#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001073 (unsigned long) major(statbuf.st_dev),
1074 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001075#ifdef HAVE_LONG_LONG
1076 (unsigned long long) statbuf.st_ino,
1077#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001078 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001079#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001080 sprintmode(statbuf.st_mode));
1081 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1082 (unsigned long) statbuf.st_nlink,
1083 (unsigned long) statbuf.st_uid,
1084 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001085#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001086 tprintf("st_blksize=%lu, ",
1087 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001088#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1089#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001090 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001091#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001092 }
1093 else
1094 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1095 switch (statbuf.st_mode & S_IFMT) {
1096 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001097#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001098 tprintf("st_rdev=makedev(%lu, %lu), ",
1099 (unsigned long) major(statbuf.st_rdev),
1100 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001101#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001102 tprintf("st_size=makedev(%lu, %lu), ",
1103 (unsigned long) major(statbuf.st_size),
1104 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001105#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001106 break;
1107 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001108#ifdef HAVE_LONG_LONG
1109 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1110#else
1111 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1112#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001113 break;
1114 }
1115 if (!abbrev(tcp)) {
1116 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1117 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001118 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001119#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001120 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001121 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001122#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001123#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001124 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1125#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001126#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001127 tprintf(", st_level=%ld", statbuf.st_level);
1128#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001129#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001130 tprintf(", st_fstype=%.*s",
1131 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1132#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001133#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001134 tprintf(", st_gen=%u", statbuf.st_gen);
1135#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001136 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001137 }
1138 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001139 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001140}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001141#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001142
Denys Vlasenko84703742012-02-25 02:38:52 +01001143#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001144static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001145convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001146{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001147 newbuf->st_dev = oldbuf->st_dev;
1148 newbuf->st_ino = oldbuf->st_ino;
1149 newbuf->st_mode = oldbuf->st_mode;
1150 newbuf->st_nlink = oldbuf->st_nlink;
1151 newbuf->st_uid = oldbuf->st_uid;
1152 newbuf->st_gid = oldbuf->st_gid;
1153 newbuf->st_rdev = oldbuf->st_rdev;
1154 newbuf->st_size = oldbuf->st_size;
1155 newbuf->st_atime = oldbuf->st_atime;
1156 newbuf->st_mtime = oldbuf->st_mtime;
1157 newbuf->st_ctime = oldbuf->st_ctime;
1158 newbuf->st_blksize = 0; /* not supported in old_stat */
1159 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001160}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001161
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001162static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001163printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001164{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001165 struct __old_kernel_stat statbuf;
1166 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001167
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001168 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001169 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001170 return;
1171 }
1172 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001173 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001174 return;
1175 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001176
Denys Vlasenko84703742012-02-25 02:38:52 +01001177# ifdef LINUXSPARC
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001178 if (current_personality == 1) {
1179 printstatsol(tcp, addr);
1180 return;
1181 }
Denys Vlasenko84703742012-02-25 02:38:52 +01001182# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001183
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001184 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001185 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001186 return;
1187 }
1188
1189 convertoldstat(&statbuf, &newstatbuf);
1190 realprintstat(tcp, &newstatbuf);
1191}
Denys Vlasenko84703742012-02-25 02:38:52 +01001192#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001193
John Hughes70623be2001-03-08 13:59:00 +00001194#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001195int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001196sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001197{
1198 if (entering(tcp)) {
1199 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001200 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001201 } else {
1202 printstat(tcp, tcp->u_arg[1]);
1203 }
1204 return 0;
1205}
John Hughesb8c9f772001-03-07 16:53:07 +00001206#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001207
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001208int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001209sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001210{
1211#ifdef HAVE_STAT64
1212 if (entering(tcp)) {
1213 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001214 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001215 } else {
1216 printstat64(tcp, tcp->u_arg[1]);
1217 }
1218 return 0;
1219#else
1220 return printargs(tcp);
1221#endif
1222}
1223
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001224#ifndef AT_SYMLINK_NOFOLLOW
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001225# define AT_SYMLINK_NOFOLLOW 0x100
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001226#endif
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001227#ifndef AT_REMOVEDIR
1228# define AT_REMOVEDIR 0x200
1229#endif
1230#ifndef AT_SYMLINK_FOLLOW
1231# define AT_SYMLINK_FOLLOW 0x400
1232#endif
1233#ifndef AT_NO_AUTOMOUNT
1234# define AT_NO_AUTOMOUNT 0x800
1235#endif
1236#ifndef AT_EMPTY_PATH
1237# define AT_EMPTY_PATH 0x1000
1238#endif
1239
1240static const struct xlat at_flags[] = {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001241 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001242 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1243 { AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" },
1244 { AT_NO_AUTOMOUNT, "AT_NO_AUTOMOUNT" },
1245 { AT_EMPTY_PATH, "AT_EMPTY_PATH" },
1246 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001247};
1248
1249int
1250sys_newfstatat(struct tcb *tcp)
1251{
1252 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001253 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001254 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001255 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001256 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001257#ifdef POWERPC64
1258 if (current_personality == 0)
1259 printstat(tcp, tcp->u_arg[2]);
1260 else
1261 printstat64(tcp, tcp->u_arg[2]);
1262#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001263 printstat64(tcp, tcp->u_arg[2]);
1264#else
1265 printstat(tcp, tcp->u_arg[2]);
1266#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001267 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001268 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001269 }
1270 return 0;
1271}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001272
Denys Vlasenko84703742012-02-25 02:38:52 +01001273#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001274int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001275sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001276{
1277 if (entering(tcp)) {
1278 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001279 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001280 } else {
1281 printoldstat(tcp, tcp->u_arg[1]);
1282 }
1283 return 0;
1284}
Denys Vlasenko84703742012-02-25 02:38:52 +01001285#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001286
John Hughes70623be2001-03-08 13:59:00 +00001287#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001288int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001289sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001290{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001291 if (entering(tcp)) {
1292 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001293 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001294 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001295 printstat(tcp, tcp->u_arg[1]);
1296 }
1297 return 0;
1298}
John Hughesb8c9f772001-03-07 16:53:07 +00001299#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001300
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001301int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001302sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001303{
1304#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001305 if (entering(tcp)) {
1306 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001307 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001308 } else {
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001309 printstat64(tcp, tcp->u_arg[1]);
1310 }
1311 return 0;
1312#else
1313 return printargs(tcp);
1314#endif
1315}
1316
Denys Vlasenko84703742012-02-25 02:38:52 +01001317#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001318int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001319sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001320{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001321 if (entering(tcp)) {
1322 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001323 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001324 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001325 printoldstat(tcp, tcp->u_arg[1]);
1326 }
1327 return 0;
1328}
Denys Vlasenko84703742012-02-25 02:38:52 +01001329#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001330
John Hughes70623be2001-03-08 13:59:00 +00001331#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001332int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001333sys_lstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001334{
1335 if (entering(tcp)) {
1336 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001337 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001338 } else {
1339 printstat(tcp, tcp->u_arg[1]);
1340 }
1341 return 0;
1342}
John Hughesb8c9f772001-03-07 16:53:07 +00001343#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001344
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001345int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001346sys_lstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001347{
1348#ifdef HAVE_STAT64
1349 if (entering(tcp)) {
1350 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001351 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001352 } else {
1353 printstat64(tcp, tcp->u_arg[1]);
1354 }
1355 return 0;
1356#else
1357 return printargs(tcp);
1358#endif
1359}
1360
Denys Vlasenko84703742012-02-25 02:38:52 +01001361#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001362int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001363sys_oldlstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001364{
1365 if (entering(tcp)) {
1366 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001367 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001368 } else {
1369 printoldstat(tcp, tcp->u_arg[1]);
1370 }
1371 return 0;
1372}
Denys Vlasenko84703742012-02-25 02:38:52 +01001373#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001374
Denys Vlasenko84703742012-02-25 02:38:52 +01001375#if defined(LINUXSPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001376
1377int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001378sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001379{
1380 if (entering(tcp)) {
1381 tprintf("%ld, ", tcp->u_arg[0]);
1382 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001383 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001384 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001385# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001386 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001387 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001388 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001389# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001390 printstat(tcp, tcp->u_arg[2]);
1391 }
1392 return 0;
1393}
1394
1395int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001396sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001397{
1398 if (entering(tcp))
1399 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1400 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001401# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001402 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001403 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001404 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001405# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001406 printstat(tcp, tcp->u_arg[2]);
1407 }
1408 return 0;
1409}
1410
1411int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001412sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413{
1414 if (entering(tcp)) {
1415 tprintf("%ld, ", tcp->u_arg[0]);
1416 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001417 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001418 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001419# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001420 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001421 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001422 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001423# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001424 printstat(tcp, tcp->u_arg[2]);
1425 }
1426 return 0;
1427}
1428
1429int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001430sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001431{
1432 int mode = tcp->u_arg[2];
1433
1434 if (entering(tcp)) {
1435 tprintf("%ld, ", tcp->u_arg[0]);
1436 printpath(tcp, tcp->u_arg[1]);
1437 tprintf(", %s", sprintmode(mode));
1438 switch (mode & S_IFMT) {
1439 case S_IFCHR: case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001440 tprintf(", makedev(%lu, %lu)",
1441 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1442 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001443 break;
1444 default:
1445 break;
1446 }
1447 }
1448 return 0;
1449}
1450
Denys Vlasenko84703742012-02-25 02:38:52 +01001451# ifdef HAVE_SYS_ACL_H
Wichert Akkerman8829a551999-06-11 13:18:40 +00001452
Denys Vlasenko84703742012-02-25 02:38:52 +01001453# include <sys/acl.h>
Wichert Akkerman8829a551999-06-11 13:18:40 +00001454
Roland McGratha4d48532005-06-08 20:45:28 +00001455static const struct xlat aclcmds[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001456# ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001457 { SETACL, "SETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001458# endif
1459# ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001460 { GETACL, "GETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001461# endif
1462# ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001463 { GETACLCNT, "GETACLCNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001464# endif
1465# ifdef ACL_GET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001466 { ACL_GET, "ACL_GET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001467# endif
1468# ifdef ACL_SET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001469 { ACL_SET, "ACL_SET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001470# endif
1471# ifdef ACL_CNT
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001472 { ACL_CNT, "ACL_CNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001473# endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001474 { 0, NULL },
1475};
1476
1477int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001478sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001479{
1480 if (entering(tcp)) {
1481 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001482 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001483 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1484 tprintf(", %ld", tcp->u_arg[2]);
1485 /*
1486 * FIXME - dump out the list of aclent_t's pointed to
1487 * by "tcp->u_arg[3]" if it's not NULL.
1488 */
1489 if (tcp->u_arg[3])
1490 tprintf(", %#lx", tcp->u_arg[3]);
1491 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001492 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001493 }
1494 return 0;
1495}
1496
Wichert Akkerman8829a551999-06-11 13:18:40 +00001497int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001498sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001499{
1500 if (entering(tcp)) {
1501 tprintf("%ld, ", tcp->u_arg[0]);
1502 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1503 tprintf(", %ld", tcp->u_arg[2]);
1504 /*
1505 * FIXME - dump out the list of aclent_t's pointed to
1506 * by "tcp->u_arg[3]" if it's not NULL.
1507 */
1508 if (tcp->u_arg[3])
1509 tprintf(", %#lx", tcp->u_arg[3]);
1510 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001511 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001512 }
1513 return 0;
1514}
1515
Roland McGratha4d48532005-06-08 20:45:28 +00001516static const struct xlat aclipc[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001517# ifdef IPC_SHM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001518 { IPC_SHM, "IPC_SHM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001519# endif
1520# ifdef IPC_SEM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001521 { IPC_SEM, "IPC_SEM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001522# endif
1523# ifdef IPC_MSG
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001524 { IPC_MSG, "IPC_MSG" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001525# endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001526 { 0, NULL },
1527};
1528
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001529int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001530sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001531{
1532 if (entering(tcp)) {
1533 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1534 tprintf(", %#lx, ", tcp->u_arg[1]);
1535 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1536 tprintf(", %ld", tcp->u_arg[3]);
1537 /*
1538 * FIXME - dump out the list of aclent_t's pointed to
1539 * by "tcp->u_arg[4]" if it's not NULL.
1540 */
1541 if (tcp->u_arg[4])
1542 tprintf(", %#lx", tcp->u_arg[4]);
1543 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001544 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001545 }
1546 return 0;
1547}
1548
Denys Vlasenko84703742012-02-25 02:38:52 +01001549# endif /* HAVE_SYS_ACL_H */
Wichert Akkerman8829a551999-06-11 13:18:40 +00001550
Denys Vlasenko84703742012-02-25 02:38:52 +01001551#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001552
Roland McGrathd9f816f2004-09-04 03:39:20 +00001553static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001554 { 0x73757245, "CODA_SUPER_MAGIC" },
1555 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1556 { 0x1373, "DEVFS_SUPER_MAGIC" },
1557 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1558 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001559 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1560 { 0xef53, "EXT2_SUPER_MAGIC" },
1561 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001562 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001563 { 0x9660, "ISOFS_SUPER_MAGIC" },
1564 { 0x137f, "MINIX_SUPER_MAGIC" },
1565 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001566 { 0x2468, "MINIX2_SUPER_MAGIC" },
1567 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001568 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001569 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001570 { 0x6969, "NFS_SUPER_MAGIC" },
1571 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001572 { 0x002f, "QNX4_SUPER_MAGIC" },
1573 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1574 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1575 { 0x517b, "SMB_SUPER_MAGIC" },
1576 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1577 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1578 { 0x00011954, "UFS_MAGIC" },
1579 { 0x54190100, "UFS_CIGAM" },
1580 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001581 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001582 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001583 { 0, NULL },
1584};
1585
Roland McGrathf9c49b22004-10-06 22:11:54 +00001586static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001587sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001588{
1589 static char buf[32];
Roland McGrathf9c49b22004-10-06 22:11:54 +00001590 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001591
1592 s = xlookup(fsmagic, magic);
1593 if (s) {
1594 sprintf(buf, "\"%s\"", s);
1595 return buf;
1596 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001597 sprintf(buf, "%#x", magic);
1598 return buf;
1599}
1600
1601static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001602printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001603{
1604 struct statfs statbuf;
1605
1606 if (syserror(tcp) || !verbose(tcp)) {
1607 tprintf("%#lx", addr);
1608 return;
1609 }
1610 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001611 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001612 return;
1613 }
1614#ifdef ALPHA
1615
1616 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1617 sprintfstype(statbuf.f_type),
1618 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001619 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001620 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001621 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1622 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001623#else /* !ALPHA */
1624 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1625 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001626 (unsigned long)statbuf.f_bsize,
1627 (unsigned long)statbuf.f_blocks,
1628 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001629 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1630 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001631 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001632 (unsigned long)statbuf.f_ffree,
1633 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001634 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001635#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001636#ifdef _STATFS_F_FRSIZE
1637 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1638#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001639 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001640}
1641
1642int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001643sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001644{
1645 if (entering(tcp)) {
1646 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001647 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001648 } else {
1649 printstatfs(tcp, tcp->u_arg[1]);
1650 }
1651 return 0;
1652}
1653
1654int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001655sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001656{
1657 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001658 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001659 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001660 } else {
1661 printstatfs(tcp, tcp->u_arg[1]);
1662 }
1663 return 0;
1664}
1665
Denys Vlasenko84703742012-02-25 02:38:52 +01001666#if defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001667static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001668printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001669{
1670 struct statfs64 statbuf;
1671
1672 if (syserror(tcp) || !verbose(tcp)) {
1673 tprintf("%#lx", addr);
1674 return;
1675 }
1676 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001677 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001678 return;
1679 }
Roland McGrath08738432005-06-03 02:40:39 +00001680 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001681 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001682 (unsigned long long)statbuf.f_bsize,
1683 (unsigned long long)statbuf.f_blocks,
1684 (unsigned long long)statbuf.f_bfree);
1685 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1686 (unsigned long long)statbuf.f_bavail,
1687 (unsigned long long)statbuf.f_files,
1688 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001689 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1690 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001691#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001692 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001693#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001694#ifdef _STATFS_F_FLAGS
1695 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1696#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001697 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001698}
1699
Andreas Schwab7d558012012-01-17 18:14:22 +01001700struct compat_statfs64 {
1701 uint32_t f_type;
1702 uint32_t f_bsize;
1703 uint64_t f_blocks;
1704 uint64_t f_bfree;
1705 uint64_t f_bavail;
1706 uint64_t f_files;
1707 uint64_t f_ffree;
1708 fsid_t f_fsid;
1709 uint32_t f_namelen;
1710 uint32_t f_frsize;
1711 uint32_t f_flags;
1712 uint32_t f_spare[4];
1713}
1714#if defined(X86_64) || defined(IA64)
1715 __attribute__ ((packed, aligned(4)))
1716#endif
1717;
1718
1719static void
1720printcompat_statfs64(struct tcb *tcp, long addr)
1721{
1722 struct compat_statfs64 statbuf;
1723
1724 if (syserror(tcp) || !verbose(tcp)) {
1725 tprintf("%#lx", addr);
1726 return;
1727 }
1728 if (umove(tcp, addr, &statbuf) < 0) {
1729 tprints("{...}");
1730 return;
1731 }
1732 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1733 sprintfstype(statbuf.f_type),
1734 (unsigned long)statbuf.f_bsize,
1735 (unsigned long long)statbuf.f_blocks,
1736 (unsigned long long)statbuf.f_bfree);
1737 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1738 (unsigned long long)statbuf.f_bavail,
1739 (unsigned long long)statbuf.f_files,
1740 (unsigned long long)statbuf.f_ffree,
1741 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1742 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1743 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001744 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
Andreas Schwab7d558012012-01-17 18:14:22 +01001745}
1746
Roland McGrathab147c52003-07-17 09:03:02 +00001747int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001748sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001749{
1750 if (entering(tcp)) {
1751 printpath(tcp, tcp->u_arg[0]);
1752 tprintf(", %lu, ", tcp->u_arg[1]);
1753 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001754 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001755 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001756 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1757 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001758 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001759 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001760 }
1761 return 0;
1762}
1763
1764int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001765sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001766{
1767 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001768 printfd(tcp, tcp->u_arg[0]);
1769 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001770 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001771 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001772 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001773 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1774 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001775 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001776 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001777 }
1778 return 0;
1779}
1780#endif
1781
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001782#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001783int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001784osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001785{
1786 if (entering(tcp)) {
1787 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001788 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001789 } else {
1790 printstatfs(tcp, tcp->u_arg[1]);
1791 tprintf(", %lu", tcp->u_arg[2]);
1792 }
1793 return 0;
1794}
1795
1796int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001797osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001798{
1799 if (entering(tcp)) {
1800 tprintf("%lu, ", tcp->u_arg[0]);
1801 } else {
1802 printstatfs(tcp, tcp->u_arg[1]);
1803 tprintf(", %lu", tcp->u_arg[2]);
1804 }
1805 return 0;
1806}
Denys Vlasenko84703742012-02-25 02:38:52 +01001807#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001808
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001809/* directory */
1810int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001811sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001812{
1813 if (entering(tcp)) {
1814 printpath(tcp, tcp->u_arg[0]);
1815 }
1816 return 0;
1817}
1818
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001819static int
1820decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001821{
1822 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001823 printpath(tcp, tcp->u_arg[offset]);
1824 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001825 }
1826 return 0;
1827}
1828
1829int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001830sys_mkdir(struct tcb *tcp)
1831{
1832 return decode_mkdir(tcp, 0);
1833}
1834
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001835int
1836sys_mkdirat(struct tcb *tcp)
1837{
1838 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001839 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001840 return decode_mkdir(tcp, 1);
1841}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001842
1843int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001844sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001845{
1846 if (entering(tcp)) {
1847 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001848 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001849 printpath(tcp, tcp->u_arg[1]);
1850 }
1851 return 0;
1852}
1853
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001854int
1855sys_linkat(struct tcb *tcp)
1856{
1857 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001858 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001859 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001860 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001861 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001862 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001863 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001864 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001865 }
1866 return 0;
1867}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001868
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001869int
1870sys_unlinkat(struct tcb *tcp)
1871{
1872 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001873 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001874 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001875 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001876 printflags(at_flags, tcp->u_arg[2], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001877 }
1878 return 0;
1879}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001880
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001881int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001882sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001883{
1884 if (entering(tcp)) {
1885 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001886 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001887 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001888 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001889 }
1890 return 0;
1891}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001892
1893static int
1894decode_readlink(struct tcb *tcp, int offset)
1895{
1896 if (entering(tcp)) {
1897 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001898 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001899 } else {
1900 if (syserror(tcp))
1901 tprintf("%#lx", tcp->u_arg[offset + 1]);
1902 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001903 /* Used to use printpathn(), but readlink
1904 * neither includes NUL in the returned count,
1905 * nor actually writes it into memory.
1906 * printpathn() would decide on printing
1907 * "..." continuation based on garbage
1908 * past return buffer's end.
1909 */
1910 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001911 tprintf(", %lu", tcp->u_arg[offset + 2]);
1912 }
1913 return 0;
1914}
1915
1916int
1917sys_readlink(struct tcb *tcp)
1918{
1919 return decode_readlink(tcp, 0);
1920}
1921
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001922int
1923sys_readlinkat(struct tcb *tcp)
1924{
1925 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001926 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001927 return decode_readlink(tcp, 1);
1928}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001929
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001930int
1931sys_renameat(struct tcb *tcp)
1932{
1933 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001934 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001935 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001936 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001937 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001938 printpath(tcp, tcp->u_arg[3]);
1939 }
1940 return 0;
1941}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001942
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001943int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001944sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001945{
1946 if (entering(tcp)) {
1947 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001948 printuid(", ", tcp->u_arg[1]);
1949 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001950 }
1951 return 0;
1952}
1953
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001954int
1955sys_fchownat(struct tcb *tcp)
1956{
1957 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001958 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001959 printpath(tcp, tcp->u_arg[1]);
1960 printuid(", ", tcp->u_arg[2]);
1961 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001962 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001963 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001964 }
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_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001970{
1971 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001972 printfd(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 +00001979static int
1980decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001981{
1982 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001983 printpath(tcp, tcp->u_arg[offset]);
1984 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001985 }
1986 return 0;
1987}
1988
1989int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001990sys_chmod(struct tcb *tcp)
1991{
1992 return decode_chmod(tcp, 0);
1993}
1994
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001995int
1996sys_fchmodat(struct tcb *tcp)
1997{
1998 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001999 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002000 return decode_chmod(tcp, 1);
2001}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002002
2003int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002004sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002005{
2006 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002007 printfd(tcp, tcp->u_arg[0]);
2008 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002009 }
2010 return 0;
2011}
2012
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002013#ifdef ALPHA
2014int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002015sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002016{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002017 if (entering(tcp)) {
2018 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002019 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002020 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2021 }
2022 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002023}
2024#endif
2025
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002026static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002027decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002028{
2029 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002030 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002031 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002032 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002033 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00002034 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002035 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00002036 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2037 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002038 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002039 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002040 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00002041 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002042 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00002043 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002044 }
2045 return 0;
2046}
2047
2048int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002049sys_utimes(struct tcb *tcp)
2050{
Roland McGrath6afc5652007-07-24 01:57:11 +00002051 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002052}
2053
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002054int
2055sys_futimesat(struct tcb *tcp)
2056{
2057 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002058 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002059 return decode_utimes(tcp, 1, 0);
2060}
2061
2062int
2063sys_utimensat(struct tcb *tcp)
2064{
2065 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002066 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002067 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002068 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00002069 printflags(at_flags, tcp->u_arg[3], "AT_???");
Roland McGrath6afc5652007-07-24 01:57:11 +00002070 }
2071 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002072}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002073
2074int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002075sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002076{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002077 union {
2078 long utl[2];
2079 int uti[2];
2080 } u;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002081 unsigned wordsize = personality_wordsize[current_personality];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002082
2083 if (entering(tcp)) {
2084 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002085 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002086 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002087 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002088 else if (!verbose(tcp))
2089 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002090 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002091 tprints("[?, ?]");
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002092 else if (wordsize == sizeof u.utl[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002093 tprintf("[%s,", sprinttime(u.utl[0]));
2094 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002095 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002096 else if (wordsize == sizeof u.uti[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002097 tprintf("[%s,", sprinttime(u.uti[0]));
2098 tprintf(" %s]", sprinttime(u.uti[1]));
2099 }
2100 else
2101 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002102 }
2103 return 0;
2104}
2105
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002106static int
2107decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002108{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002109 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002110
2111 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002112 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002113 tprintf(", %s", sprintmode(mode));
2114 switch (mode & S_IFMT) {
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002115 case S_IFCHR:
2116 case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002117#ifdef LINUXSPARC
2118 if (current_personality == 1)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002119 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002120 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2121 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002122 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002123#endif
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002124 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002125 (unsigned long) major(tcp->u_arg[offset + 2]),
2126 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002127 break;
2128 default:
2129 break;
2130 }
2131 }
2132 return 0;
2133}
2134
2135int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002136sys_mknod(struct tcb *tcp)
2137{
2138 return decode_mknod(tcp, 0);
2139}
2140
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002141int
2142sys_mknodat(struct tcb *tcp)
2143{
2144 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002145 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002146 return decode_mknod(tcp, 1);
2147}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002148
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002149static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002150printdir(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002151{
2152 struct dirent d;
2153
2154 if (!verbose(tcp)) {
2155 tprintf("%#lx", addr);
2156 return;
2157 }
2158 if (umove(tcp, addr, &d) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002159 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002160 return;
2161 }
2162 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002163 tprints("d_name=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002164 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002165 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002166}
2167
2168int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002169sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002170{
2171 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002172 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002173 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002174 } else {
2175 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2176 tprintf("%#lx", tcp->u_arg[1]);
2177 else
2178 printdir(tcp, tcp->u_arg[1]);
2179 /* Not much point in printing this out, it is always 1. */
2180 if (tcp->u_arg[2] != 1)
2181 tprintf(", %lu", tcp->u_arg[2]);
2182 }
2183 return 0;
2184}
2185
Roland McGratha4d48532005-06-08 20:45:28 +00002186static const struct xlat direnttypes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002187 { DT_UNKNOWN, "DT_UNKNOWN" },
2188 { DT_FIFO, "DT_FIFO" },
2189 { DT_CHR, "DT_CHR" },
2190 { DT_DIR, "DT_DIR" },
2191 { DT_BLK, "DT_BLK" },
2192 { DT_REG, "DT_REG" },
2193 { DT_LNK, "DT_LNK" },
2194 { DT_SOCK, "DT_SOCK" },
2195 { DT_WHT, "DT_WHT" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002196 { 0, NULL },
2197};
2198
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002199int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002200sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002201{
2202 int i, len, dents = 0;
2203 char *buf;
2204
2205 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002206 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002207 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002208 return 0;
2209 }
2210 if (syserror(tcp) || !verbose(tcp)) {
2211 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2212 return 0;
2213 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002214 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002215 /* Beware of insanely large or negative values in tcp->u_rval */
2216 if (tcp->u_rval > 1024*1024)
2217 len = 1024*1024;
2218 if (tcp->u_rval < 0)
2219 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002220 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002221 if (len && !buf)
2222 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002223 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002224 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002225 free(buf);
2226 return 0;
2227 }
2228 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002229 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002230 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002231 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002232 if (!abbrev(tcp)) {
2233 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2234 i ? " " : "", d->d_ino, d->d_off);
2235 tprintf("d_reclen=%u, d_name=\"%s\"}",
2236 d->d_reclen, d->d_name);
2237 }
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002238 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002239 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002240 break;
2241 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002242 i += d->d_reclen;
2243 dents++;
2244 }
2245 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002246 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002247 else
2248 tprintf("/* %u entries */", dents);
2249 tprintf(", %lu", tcp->u_arg[2]);
2250 free(buf);
2251 return 0;
2252}
2253
John Hughesbdf48f52001-03-06 15:08:09 +00002254#if _LFS64_LARGEFILE
2255int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002256sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002257{
2258 int i, len, dents = 0;
2259 char *buf;
2260
2261 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002262 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002263 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002264 return 0;
2265 }
2266 if (syserror(tcp) || !verbose(tcp)) {
2267 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2268 return 0;
2269 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002270
John Hughesbdf48f52001-03-06 15:08:09 +00002271 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002272 /* Beware of insanely large or negative tcp->u_rval */
2273 if (tcp->u_rval > 1024*1024)
2274 len = 1024*1024;
2275 if (tcp->u_rval < 0)
2276 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002277 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002278 if (len && !buf)
2279 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002280
John Hughesbdf48f52001-03-06 15:08:09 +00002281 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002282 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002283 free(buf);
2284 return 0;
2285 }
2286 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002287 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002288 for (i = 0; i < len;) {
2289 struct dirent64 *d = (struct dirent64 *) &buf[i];
John Hughesbdf48f52001-03-06 15:08:09 +00002290 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002291 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002292 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002293 d->d_ino,
2294 d->d_off);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002295 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002296 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002297 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002298 tprintf("d_reclen=%u, d_name=\"%s\"}",
2299 d->d_reclen, d->d_name);
2300 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002301 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002302 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002303 break;
2304 }
John Hughesbdf48f52001-03-06 15:08:09 +00002305 i += d->d_reclen;
2306 dents++;
2307 }
2308 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002309 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002310 else
2311 tprintf("/* %u entries */", dents);
2312 tprintf(", %lu", tcp->u_arg[2]);
2313 free(buf);
2314 return 0;
2315}
2316#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002317
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002318int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002319sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002320{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002321 if (exiting(tcp)) {
2322 if (syserror(tcp))
2323 tprintf("%#lx", tcp->u_arg[0]);
2324 else
2325 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2326 tprintf(", %lu", tcp->u_arg[1]);
2327 }
2328 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002329}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002330
2331#ifdef HAVE_SYS_ASYNCH_H
2332
2333int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002334sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002335{
2336 struct aio_result_t res;
2337
2338 if (entering(tcp)) {
2339 tprintf("%lu, ", tcp->u_arg[0]);
2340 } else {
2341 if (syserror(tcp))
2342 tprintf("%#lx", tcp->u_arg[1]);
2343 else
2344 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2345 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2346 printxval(whence, tcp->u_arg[4], "L_???");
2347 if (syserror(tcp) || tcp->u_arg[5] == 0
2348 || umove(tcp, tcp->u_arg[5], &res) < 0)
2349 tprintf(", %#lx", tcp->u_arg[5]);
2350 else
2351 tprintf(", {aio_return %d aio_errno %d}",
2352 res.aio_return, res.aio_errno);
2353 }
2354 return 0;
2355}
2356
2357int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002358sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002359{
2360 struct aio_result_t res;
2361
2362 if (entering(tcp)) {
2363 tprintf("%lu, ", tcp->u_arg[0]);
2364 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2365 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2366 printxval(whence, tcp->u_arg[4], "L_???");
2367 }
2368 else {
2369 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002370 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002371 else if (syserror(tcp)
2372 || umove(tcp, tcp->u_arg[5], &res) < 0)
2373 tprintf(", %#lx", tcp->u_arg[5]);
2374 else
2375 tprintf(", {aio_return %d aio_errno %d}",
2376 res.aio_return, res.aio_errno);
2377 }
2378 return 0;
2379}
2380
2381int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002382sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002383{
2384 if (entering(tcp))
2385 printtv(tcp, tcp->u_arg[0]);
2386 return 0;
2387}
2388
2389int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002390sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002391{
2392 struct aio_result_t res;
2393
2394 if (exiting(tcp)) {
2395 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002396 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002397 else if (syserror(tcp)
2398 || umove(tcp, tcp->u_arg[0], &res) < 0)
2399 tprintf("%#lx", tcp->u_arg[0]);
2400 else
2401 tprintf("{aio_return %d aio_errno %d}",
2402 res.aio_return, res.aio_errno);
2403 }
2404 return 0;
2405}
2406
2407#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002408
Roland McGratha4d48532005-06-08 20:45:28 +00002409static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002410#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002411 { XATTR_CREATE, "XATTR_CREATE" },
2412 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002413#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002414 { 0, NULL }
2415};
2416
Roland McGrath3292e222004-08-31 06:30:48 +00002417static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002418print_xattr_val(struct tcb *tcp, int failed,
2419 unsigned long arg,
2420 unsigned long insize,
2421 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002422{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002423 if (!failed) {
2424 unsigned long capacity = 4 * size + 1;
2425 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2426 if (buf == NULL || /* probably a bogus size argument */
2427 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2428 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002429 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002430 else {
2431 unsigned char *out = buf;
2432 unsigned char *in = &buf[3 * size];
2433 size_t i;
2434 for (i = 0; i < size; ++i) {
2435 if (isprint(in[i]))
2436 *out++ = in[i];
2437 else {
2438#define tohex(n) "0123456789abcdef"[n]
2439 *out++ = '\\';
2440 *out++ = 'x';
2441 *out++ = tohex(in[i] / 16);
2442 *out++ = tohex(in[i] % 16);
2443 }
2444 }
2445 /* Don't print terminating NUL if there is one. */
2446 if (i > 0 && in[i - 1] == '\0')
2447 out -= 4;
2448 *out = '\0';
2449 tprintf(", \"%s\", %ld", buf, insize);
2450 }
2451 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002452 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002453 if (failed)
2454 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002455}
2456
Roland McGrath186c5ac2002-12-15 23:58:23 +00002457int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002458sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002459{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002460 if (entering(tcp)) {
2461 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002462 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002463 printstr(tcp, tcp->u_arg[1], -1);
2464 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002465 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002466 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2467 }
2468 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002469}
2470
2471int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002472sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002473{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002474 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002475 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002476 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002477 printstr(tcp, tcp->u_arg[1], -1);
2478 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002479 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002480 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2481 }
2482 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002483}
2484
2485int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002486sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002487{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002488 if (entering(tcp)) {
2489 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002490 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002491 printstr(tcp, tcp->u_arg[1], -1);
2492 } else {
2493 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2494 tcp->u_rval);
2495 }
2496 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002497}
2498
2499int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002500sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002501{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002502 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002503 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002504 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002505 printstr(tcp, tcp->u_arg[1], -1);
2506 } else {
2507 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2508 tcp->u_rval);
2509 }
2510 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002511}
2512
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002513static void
2514print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2515{
2516 if (syserror(tcp)) {
2517 tprintf("%#lx", addr);
2518 } else {
2519 if (!addr) {
2520 tprints("NULL");
2521 } else {
2522 unsigned long len =
2523 (size < tcp->u_rval) ? size : tcp->u_rval;
2524 printstr(tcp, addr, len);
2525 }
2526 }
2527 tprintf(", %lu", size);
2528}
2529
Roland McGrath186c5ac2002-12-15 23:58:23 +00002530int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002531sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002532{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002533 if (entering(tcp)) {
2534 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002535 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002536 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002537 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002538 }
2539 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002540}
2541
2542int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002543sys_flistxattr(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]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002547 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002548 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002549 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002550 }
2551 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002552}
2553
2554int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002555sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002556{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002557 if (entering(tcp)) {
2558 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002559 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002560 printstr(tcp, tcp->u_arg[1], -1);
2561 }
2562 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002563}
2564
2565int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002566sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002567{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002568 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002569 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002570 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002571 printstr(tcp, tcp->u_arg[1], -1);
2572 }
2573 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002574}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002575
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002576static const struct xlat advise[] = {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002577 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2578 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2579 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2580 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2581 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2582 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2583 { 0, NULL }
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002584};
2585
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002586int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002587sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002588{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002589 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002590 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002591 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002592 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002593 argn = printllval(tcp, "%lld", 1);
2594 tprintf(", %ld, ", tcp->u_arg[argn++]);
2595 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002596 }
2597 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002598}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002599
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002600int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002601sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002602{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002603 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002604 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002605 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002606 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002607#if defined ARM || defined POWERPC
2608 argn = printllval(tcp, "%lld, ", 2);
2609#else
2610 argn = printllval(tcp, "%lld, ", 1);
2611#endif
2612 argn = printllval(tcp, "%lld, ", argn);
2613#if defined ARM || defined POWERPC
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002614 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002615#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002616 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002617#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002618 }
2619 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002620}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002621
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002622static const struct xlat inotify_modes[] = {
Dmitry V. Levind475c062011-03-03 01:02:41 +00002623 { 0x00000001, "IN_ACCESS" },
2624 { 0x00000002, "IN_MODIFY" },
2625 { 0x00000004, "IN_ATTRIB" },
2626 { 0x00000008, "IN_CLOSE_WRITE"},
2627 { 0x00000010, "IN_CLOSE_NOWRITE"},
2628 { 0x00000020, "IN_OPEN" },
2629 { 0x00000040, "IN_MOVED_FROM" },
2630 { 0x00000080, "IN_MOVED_TO" },
2631 { 0x00000100, "IN_CREATE" },
2632 { 0x00000200, "IN_DELETE" },
2633 { 0x00000400, "IN_DELETE_SELF"},
2634 { 0x00000800, "IN_MOVE_SELF" },
2635 { 0x00002000, "IN_UNMOUNT" },
2636 { 0x00004000, "IN_Q_OVERFLOW" },
2637 { 0x00008000, "IN_IGNORED" },
2638 { 0x01000000, "IN_ONLYDIR" },
2639 { 0x02000000, "IN_DONT_FOLLOW"},
2640 { 0x20000000, "IN_MASK_ADD" },
2641 { 0x40000000, "IN_ISDIR" },
2642 { 0x80000000, "IN_ONESHOT" },
2643 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002644};
2645
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002646static const struct xlat inotify_init_flags[] = {
2647 { 0x00000800, "IN_NONBLOCK" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002648 { 0x00080000, "IN_CLOEXEC" },
2649 { 0, NULL }
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002650};
2651
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002652int
2653sys_inotify_add_watch(struct tcb *tcp)
2654{
2655 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002656 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002657 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002658 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002659 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002660 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2661 }
2662 return 0;
2663}
2664
2665int
2666sys_inotify_rm_watch(struct tcb *tcp)
2667{
2668 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002669 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levinab1a70c2012-03-11 15:33:34 +00002670 tprintf(", %d", (int) tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002671 }
2672 return 0;
2673}
Roland McGrath96a96612008-05-20 04:56:18 +00002674
2675int
Mark Wielaardbab89402010-03-21 14:41:26 +01002676sys_inotify_init1(struct tcb *tcp)
2677{
2678 if (entering(tcp))
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002679 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
Mark Wielaardbab89402010-03-21 14:41:26 +01002680 return 0;
2681}
2682
2683int
Roland McGrath96a96612008-05-20 04:56:18 +00002684sys_fallocate(struct tcb *tcp)
2685{
2686 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002687 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002688 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002689 tprints(", ");
Roland McGrath96a96612008-05-20 04:56:18 +00002690 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002691 argn = printllval(tcp, "%llu, ", 2); /* offset */
2692 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002693 }
2694 return 0;
2695}
Dmitry V. Levin88293652012-03-09 21:02:19 +00002696
Dmitry V. Levinad0c01e2012-03-15 00:52:22 +00002697#ifndef SWAP_FLAG_PREFER
2698# define SWAP_FLAG_PREFER 0x8000
2699#endif
2700#ifndef SWAP_FLAG_DISCARD
2701# define SWAP_FLAG_DISCARD 0x10000
2702#endif
Dmitry V. Levin88293652012-03-09 21:02:19 +00002703static const struct xlat swap_flags[] = {
2704 { SWAP_FLAG_PREFER, "SWAP_FLAG_PREFER" },
2705 { SWAP_FLAG_DISCARD, "SWAP_FLAG_DISCARD" },
2706 { 0, NULL }
2707};
2708
2709int
2710sys_swapon(struct tcb *tcp)
2711{
2712 if (entering(tcp)) {
2713 int flags = tcp->u_arg[1];
2714 printpath(tcp, tcp->u_arg[0]);
2715 tprints(", ");
2716 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2717 "SWAP_FLAG_???");
2718 if (flags & SWAP_FLAG_PREFER)
2719 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);
2720 }
2721 return 0;
2722}