blob: cfdd0bb98911323e845a83b1a1ee7115013d7063 [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 Vlasenko9472a272013-02-12 11:43:46 +010035#if defined(SPARC) || defined(SPARC64)
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
H.J. Lu35be5812012-04-16 13:00:01 +020076#elif defined(X32)
77struct stat {
78 unsigned long long st_dev;
79 unsigned long long st_ino;
80 unsigned long long st_nlink;
81
82 unsigned int st_mode;
83 unsigned int st_uid;
84 unsigned int st_gid;
85 unsigned int __pad0;
86 unsigned long long st_rdev;
87 long long st_size;
88 long long st_blksize;
89 long long st_blocks;
90
91 unsigned long long st_atime;
92 unsigned long long st_atime_nsec;
93 unsigned long long st_mtime;
94 unsigned long long st_mtime_nsec;
95 unsigned long long st_ctime;
96 unsigned long long st_ctime_nsec;
97 long long __unused[3];
98};
H.J. Lu085e4282012-04-17 11:05:04 -070099
100struct stat64 {
101 unsigned long long st_dev;
102 unsigned char __pad0[4];
103 unsigned long __st_ino;
104 unsigned int st_mode;
105 unsigned int st_nlink;
106 unsigned long st_uid;
107 unsigned long st_gid;
108 unsigned long long st_rdev;
109 unsigned char __pad3[4];
110 long long st_size;
111 unsigned long st_blksize;
112 unsigned long long st_blocks;
113 unsigned long st_atime;
114 unsigned long st_atime_nsec;
115 unsigned long st_mtime;
116 unsigned int st_mtime_nsec;
117 unsigned long st_ctime;
118 unsigned long st_ctime_nsec;
119 unsigned long long st_ino;
120};
Denys Vlasenko84703742012-02-25 02:38:52 +0100121#else
122# undef dev_t
123# undef ino_t
124# undef mode_t
125# undef nlink_t
126# undef uid_t
127# undef gid_t
128# undef off_t
129# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100130# define dev_t __kernel_dev_t
131# define ino_t __kernel_ino_t
132# define mode_t __kernel_mode_t
133# define nlink_t __kernel_nlink_t
134# define uid_t __kernel_uid_t
135# define gid_t __kernel_gid_t
136# define off_t __kernel_off_t
137# define loff_t __kernel_loff_t
Wichert Akkermana6013701999-07-08 14:00:58 +0000138
Denys Vlasenko84703742012-02-25 02:38:52 +0100139# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +0000140
Denys Vlasenko84703742012-02-25 02:38:52 +0100141# undef dev_t
142# undef ino_t
143# undef mode_t
144# undef nlink_t
145# undef uid_t
146# undef gid_t
147# undef off_t
148# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100149# define dev_t dev_t
150# define ino_t ino_t
151# define mode_t mode_t
152# define nlink_t nlink_t
153# define uid_t uid_t
154# define gid_t gid_t
155# define off_t off_t
156# define loff_t loff_t
157#endif
158
159#ifdef HPPA /* asm-parisc/stat.h defines stat64 */
160# undef stat64
161#endif
162#define stat libc_stat
163#define stat64 libc_stat64
164#include <sys/stat.h>
165#undef stat
166#undef stat64
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100167/* These might be macros. */
Denys Vlasenko84703742012-02-25 02:38:52 +0100168#undef st_atime
169#undef st_mtime
170#undef st_ctime
171#ifdef HPPA
172# define stat64 hpux_stat64
173#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000174
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000175#include <fcntl.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000176#ifdef HAVE_SYS_VFS_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100177# include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000178#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +0000179#ifdef HAVE_LINUX_XATTR_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100180# include <linux/xattr.h>
Denys Vlasenkoed720fd2012-02-25 02:24:03 +0100181#else
Denys Vlasenko84703742012-02-25 02:38:52 +0100182# define XATTR_CREATE 1
183# define XATTR_REPLACE 2
Roland McGrath186c5ac2002-12-15 23:58:23 +0000184#endif
185
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186#ifdef MAJOR_IN_SYSMACROS
Denys Vlasenko84703742012-02-25 02:38:52 +0100187# include <sys/sysmacros.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000188#endif
189
190#ifdef MAJOR_IN_MKDEV
Denys Vlasenko84703742012-02-25 02:38:52 +0100191# include <sys/mkdev.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000192#endif
193
194#ifdef HAVE_SYS_ASYNCH_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100195# include <sys/asynch.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000196#endif
197
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100198struct kernel_dirent {
199 unsigned long d_ino;
200 unsigned long d_off;
201 unsigned short d_reclen;
202 char d_name[1];
203};
204
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000205const struct xlat open_access_modes[] = {
206 { O_RDONLY, "O_RDONLY" },
207 { O_WRONLY, "O_WRONLY" },
208 { O_RDWR, "O_RDWR" },
209#ifdef O_ACCMODE
210 { O_ACCMODE, "O_ACCMODE" },
211#endif
212 { 0, NULL },
213};
214
215const struct xlat open_mode_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000216 { O_CREAT, "O_CREAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000217 { O_EXCL, "O_EXCL" },
218 { O_NOCTTY, "O_NOCTTY" },
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000219 { O_TRUNC, "O_TRUNC" },
220 { O_APPEND, "O_APPEND" },
221 { O_NONBLOCK, "O_NONBLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000222#ifdef O_SYNC
223 { O_SYNC, "O_SYNC" },
224#endif
225#ifdef O_ASYNC
226 { O_ASYNC, "O_ASYNC" },
227#endif
228#ifdef O_DSYNC
229 { O_DSYNC, "O_DSYNC" },
230#endif
231#ifdef O_RSYNC
232 { O_RSYNC, "O_RSYNC" },
233#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000234#if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000235 { O_NDELAY, "O_NDELAY" },
236#endif
237#ifdef O_PRIV
238 { O_PRIV, "O_PRIV" },
239#endif
240#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000241 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000242#endif
243#ifdef O_LARGEFILE
Roland McGrathfee836e2005-02-02 22:11:32 +0000244# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
245# undef O_LARGEFILE
246# ifdef SPARC64
247# define O_LARGEFILE 0x40000
248# elif defined X86_64 || defined S390X
249# define O_LARGEFILE 0100000
250# endif
251# endif
Roland McGrath663a8a02005-02-04 09:49:56 +0000252# ifdef O_LARGEFILE
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200253 { O_LARGEFILE, "O_LARGEFILE" },
Roland McGrath663a8a02005-02-04 09:49:56 +0000254# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000255#endif
256#ifdef O_DIRECTORY
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200257 { O_DIRECTORY, "O_DIRECTORY" },
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000258#endif
259#ifdef O_NOFOLLOW
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200260 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000261#endif
Roland McGrath1025c3e2005-05-09 07:40:35 +0000262#ifdef O_NOATIME
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200263 { O_NOATIME, "O_NOATIME" },
Roland McGrath1025c3e2005-05-09 07:40:35 +0000264#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000265#ifdef O_CLOEXEC
266 { O_CLOEXEC, "O_CLOEXEC" },
267#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000268#ifdef FNDELAY
269 { FNDELAY, "FNDELAY" },
270#endif
271#ifdef FAPPEND
272 { FAPPEND, "FAPPEND" },
273#endif
274#ifdef FMARK
275 { FMARK, "FMARK" },
276#endif
277#ifdef FDEFER
278 { FDEFER, "FDEFER" },
279#endif
280#ifdef FASYNC
281 { FASYNC, "FASYNC" },
282#endif
283#ifdef FSHLOCK
284 { FSHLOCK, "FSHLOCK" },
285#endif
286#ifdef FEXLOCK
287 { FEXLOCK, "FEXLOCK" },
288#endif
289#ifdef FCREAT
290 { FCREAT, "FCREAT" },
291#endif
292#ifdef FTRUNC
293 { FTRUNC, "FTRUNC" },
294#endif
295#ifdef FEXCL
296 { FEXCL, "FEXCL" },
297#endif
298#ifdef FNBIO
299 { FNBIO, "FNBIO" },
300#endif
301#ifdef FSYNC
302 { FSYNC, "FSYNC" },
303#endif
304#ifdef FNOCTTY
305 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000306#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000307#ifdef O_SHLOCK
308 { O_SHLOCK, "O_SHLOCK" },
309#endif
310#ifdef O_EXLOCK
311 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000312#endif
313 { 0, NULL },
314};
315
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000316#ifndef AT_FDCWD
317# define AT_FDCWD -100
318#endif
319
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000320/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
321 * extension to get the right value. We do this by declaring fd as int here.
322 */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000323static void
Dmitry V. Levin31382132011-03-04 05:08:02 +0300324print_dirfd(struct tcb *tcp, int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000325{
326 if (fd == AT_FDCWD)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200327 tprints("AT_FDCWD, ");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200328 else {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300329 printfd(tcp, fd);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200330 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300331 }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000332}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000333
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000334/*
335 * low bits of the open(2) flags define access mode,
336 * other bits are real flags.
337 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000338const char *
339sprint_open_modes(mode_t flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000340{
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100341 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000342 char *p;
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100343 char sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000344 const char *str;
345 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000346
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100347 sep = ' ';
348 p = stpcpy(outstr, "flags");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000349 str = xlookup(open_access_modes, flags & 3);
350 if (str) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100351 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200352 p = stpcpy(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000353 flags &= ~3;
354 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000355 return outstr;
356 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000357 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000358
359 for (x = open_mode_flags; x->str; x++) {
360 if ((flags & x->val) == x->val) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100361 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200362 p = stpcpy(p, x->str);
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000363 flags &= ~x->val;
364 if (!flags)
365 return outstr;
366 sep = '|';
367 }
368 }
369 /* flags is still nonzero */
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100370 *p++ = sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000371 sprintf(p, "%#x", flags);
372 return outstr;
373}
374
375void
376tprint_open_modes(mode_t flags)
377{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200378 tprints(sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000379}
380
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000381static int
382decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000383{
384 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000385 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200386 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000387 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000388 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000389 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000390 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000391 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000392 }
393 }
394 return 0;
395}
396
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000397int
398sys_open(struct tcb *tcp)
399{
400 return decode_open(tcp, 0);
401}
402
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000403int
404sys_openat(struct tcb *tcp)
405{
406 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300407 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000408 return decode_open(tcp, 1);
409}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000410
Denys Vlasenko9472a272013-02-12 11:43:46 +0100411#if defined(SPARC) || defined(SPARC64)
Roland McGratha4d48532005-06-08 20:45:28 +0000412static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000413 { 0, "O_RDWR" },
414 { 1, "O_RDONLY" },
415 { 2, "O_WRONLY" },
416 { 0x80, "O_NONBLOCK" },
417 { 8, "O_APPEND" },
418 { 0x100, "O_CREAT" },
419 { 0x200, "O_TRUNC" },
420 { 0x400, "O_EXCL" },
421 { 0x800, "O_NOCTTY" },
422 { 0x10, "O_SYNC" },
423 { 0x40, "O_DSYNC" },
424 { 0x8000, "O_RSYNC" },
425 { 4, "O_NDELAY" },
426 { 0x1000, "O_PRIV" },
427 { 0, NULL },
428};
429
430int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000431solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000432{
433 if (entering(tcp)) {
434 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200435 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000436 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000437 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438 if (tcp->u_arg[1] & 0x100) {
439 /* mode */
440 tprintf(", %#lo", tcp->u_arg[2]);
441 }
442 }
443 return 0;
444}
445
446#endif
447
448int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000449sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000450{
451 if (entering(tcp)) {
452 printpath(tcp, tcp->u_arg[0]);
453 tprintf(", %#lo", tcp->u_arg[1]);
454 }
455 return 0;
456}
457
Roland McGrathd9f816f2004-09-04 03:39:20 +0000458static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000459 { F_OK, "F_OK", },
460 { R_OK, "R_OK" },
461 { W_OK, "W_OK" },
462 { X_OK, "X_OK" },
463#ifdef EFF_ONLY_OK
464 { EFF_ONLY_OK, "EFF_ONLY_OK" },
465#endif
466#ifdef EX_OK
467 { EX_OK, "EX_OK" },
468#endif
469 { 0, NULL },
470};
471
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000472static int
473decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000474{
475 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000476 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200477 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000478 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000479 }
480 return 0;
481}
482
483int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000484sys_access(struct tcb *tcp)
485{
486 return decode_access(tcp, 0);
487}
488
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000489int
490sys_faccessat(struct tcb *tcp)
491{
492 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300493 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000494 return decode_access(tcp, 1);
495}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000496
497int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000498sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000499{
500 if (entering(tcp)) {
501 tprintf("%#lo", tcp->u_arg[0]);
502 }
503 return RVAL_OCTAL;
504}
505
Denys Vlasenko86738a22013-02-17 14:31:55 +0100506const struct xlat whence_codes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000507 { SEEK_SET, "SEEK_SET" },
508 { SEEK_CUR, "SEEK_CUR" },
509 { SEEK_END, "SEEK_END" },
Denys Vlasenko86738a22013-02-17 14:31:55 +0100510#ifdef SEEK_DATA
511 { SEEK_DATA, "SEEK_DATA" },
512#endif
513#ifdef SEEK_HOLE
514 { SEEK_HOLE, "SEEK_HOLE" },
515#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000516 { 0, NULL },
517};
518
Denys Vlasenko386b8712013-02-17 01:38:14 +0100519/* Linux kernel has exactly one version of lseek:
520 * fs/read_write.c::SYSCALL_DEFINE3(lseek, unsigned, fd, off_t, offset, unsigned, origin)
521 * In kernel, off_t is always the same as (kernel's) long
522 * (see include/uapi/asm-generic/posix_types.h),
523 * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument.
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100524 * Use test/x32_lseek.c to test lseek decoding.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100525 */
H.J. Luc933f272012-04-16 17:41:13 +0200526#if defined(LINUX_MIPSN32) || defined(X32)
Roland McGrath542c2c62008-05-20 01:11:56 +0000527int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000528sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000529{
530 long long offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100531 int whence;
Roland McGrath542c2c62008-05-20 01:11:56 +0000532
533 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300534 printfd(tcp, tcp->u_arg[0]);
Roland McGrath542c2c62008-05-20 01:11:56 +0000535 offset = tcp->ext_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100536 whence = tcp->u_arg[2];
537 if (whence == SEEK_SET)
538 tprintf(", %llu, ", offset);
Roland McGrath542c2c62008-05-20 01:11:56 +0000539 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100540 tprintf(", %lld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100541 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath542c2c62008-05-20 01:11:56 +0000542 }
H.J. Ludd0130b2012-04-16 12:16:45 +0200543 return RVAL_LUDECIMAL;
Roland McGrath542c2c62008-05-20 01:11:56 +0000544}
H.J. Ludd0130b2012-04-16 12:16:45 +0200545#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000546int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000547sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000548{
Denys Vlasenko06121762013-02-17 20:08:50 +0100549 long offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100550 int whence;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000551
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000552 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300553 printfd(tcp, tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000554 offset = tcp->u_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100555 whence = tcp->u_arg[2];
556 if (whence == SEEK_SET)
557 tprintf(", %lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100559 tprintf(", %ld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100560 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000561 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000562 return RVAL_UDECIMAL;
563}
John Hughes5a826b82001-03-07 13:21:24 +0000564#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000565
Denys Vlasenko386b8712013-02-17 01:38:14 +0100566/* llseek syscall takes explicitly two ulong arguments hi, lo,
567 * rather than one 64-bit argument for which LONG_LONG works
568 * appropriate for the native byte order.
569 *
570 * See kernel's fs/read_write.c::SYSCALL_DEFINE5(llseek, ...)
571 *
572 * hi,lo are "unsigned longs" and combined exactly this way in kernel:
573 * ((loff_t) hi << 32) | lo
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100574 * Note that for architectures with kernel's long wider than userspace long
Denys Vlasenko386b8712013-02-17 01:38:14 +0100575 * (such as x32), combining code will use *kernel's*, i.e. *wide* longs
Denys Vlasenko06121762013-02-17 20:08:50 +0100576 * for hi and lo. We would need to use tcp->ext_arg[N] on x32...
577 * ...however, x32 (and x86_64) does not _have_ llseek syscall as such.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100578 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000579int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000580sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000581{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000582 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300583 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000584 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300585 tprintf(", %llu, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100586 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300587 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000588 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300589 tprintf(", %lld, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100590 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300591 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000592 }
593 else {
Denys Vlasenko386b8712013-02-17 01:38:14 +0100594 long long off;
Denys Vlasenko1d632462009-04-14 12:51:00 +0000595 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
596 tprintf("%#lx, ", tcp->u_arg[3]);
597 else
598 tprintf("[%llu], ", off);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100599 printxval(whence_codes, tcp->u_arg[4], "SEEK_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000600 }
601 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000602}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000603
604int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000605sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000606{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000607 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100608 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300609 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +0200610 argn = printllval(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100611 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000612 }
613 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000614}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000615
616int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000617sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000618{
619 if (entering(tcp)) {
620 printpath(tcp, tcp->u_arg[0]);
621 tprintf(", %lu", tcp->u_arg[1]);
622 }
623 return 0;
624}
625
Denys Vlasenko8435d672013-02-18 15:47:57 +0100626#if _LFS64_LARGEFILE
John Hughes96f51472001-03-06 16:50:41 +0000627int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000628sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000629{
630 if (entering(tcp)) {
631 printpath(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100632 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000633 }
634 return 0;
635}
636#endif
637
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000638int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000639sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000640{
641 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300642 printfd(tcp, tcp->u_arg[0]);
643 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000644 }
645 return 0;
646}
647
Denys Vlasenko8435d672013-02-18 15:47:57 +0100648#if _LFS64_LARGEFILE
John Hughes96f51472001-03-06 16:50:41 +0000649int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000650sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000651{
652 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300653 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +0200654 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000655 }
656 return 0;
657}
658#endif
659
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000660/* several stats */
661
Roland McGrathd9f816f2004-09-04 03:39:20 +0000662static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000663 { S_IFREG, "S_IFREG" },
664 { S_IFSOCK, "S_IFSOCK" },
665 { S_IFIFO, "S_IFIFO" },
666 { S_IFLNK, "S_IFLNK" },
667 { S_IFDIR, "S_IFDIR" },
668 { S_IFBLK, "S_IFBLK" },
669 { S_IFCHR, "S_IFCHR" },
670 { 0, NULL },
671};
672
Roland McGrathf9c49b22004-10-06 22:11:54 +0000673static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000674sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000675{
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100676 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
677 + sizeof(int)*3
678 + /*paranoia:*/ 8];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000679 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000680
681 if ((mode & S_IFMT) == 0)
682 s = "";
683 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
684 sprintf(buf, "%#o", mode);
685 return buf;
686 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100687 s = buf + sprintf(buf, "%s%s%s%s", s,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000688 (mode & S_ISUID) ? "|S_ISUID" : "",
689 (mode & S_ISGID) ? "|S_ISGID" : "",
690 (mode & S_ISVTX) ? "|S_ISVTX" : "");
691 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
692 if (mode)
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100693 sprintf((char*)s, "|%#o", mode);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000694 s = (*buf == '|') ? buf + 1 : buf;
695 return *s ? s : "0";
696}
697
698static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000699sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000700{
701 struct tm *tmp;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100702 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000703
704 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000705 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000706 return buf;
707 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200708 tmp = localtime(&t);
709 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000710 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
711 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
712 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
713 else
714 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
715
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000716 return buf;
717}
718
Denys Vlasenko9472a272013-02-12 11:43:46 +0100719#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000720typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000721 int tv_sec;
722 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000723} timestruct_t;
724
725struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000726 unsigned st_dev;
727 int st_pad1[3]; /* network id */
728 unsigned st_ino;
729 unsigned st_mode;
730 unsigned st_nlink;
731 unsigned st_uid;
732 unsigned st_gid;
733 unsigned st_rdev;
734 int st_pad2[2];
735 int st_size;
736 int st_pad3; /* st_size, off_t expansion */
737 timestruct_t st_atime;
738 timestruct_t st_mtime;
739 timestruct_t st_ctime;
740 int st_blksize;
741 int st_blocks;
742 char st_fstype[16];
743 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000744};
745
746static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000747printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000748{
749 struct solstat statbuf;
750
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000751 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200752 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000753 return;
754 }
755 if (!abbrev(tcp)) {
756 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
757 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
758 (unsigned long) (statbuf.st_dev & 0x3ffff),
759 (unsigned long) statbuf.st_ino,
760 sprintmode(statbuf.st_mode));
761 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
762 (unsigned long) statbuf.st_nlink,
763 (unsigned long) statbuf.st_uid,
764 (unsigned long) statbuf.st_gid);
765 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
766 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
767 }
768 else
769 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
770 switch (statbuf.st_mode & S_IFMT) {
771 case S_IFCHR: case S_IFBLK:
772 tprintf("st_rdev=makedev(%lu, %lu), ",
773 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
774 (unsigned long) (statbuf.st_rdev & 0x3ffff));
775 break;
776 default:
777 tprintf("st_size=%u, ", statbuf.st_size);
778 break;
779 }
780 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000781 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
782 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
783 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000784 }
785 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200786 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000787}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000788
Denys Vlasenko9472a272013-02-12 11:43:46 +0100789# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000790static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000791printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000792{
793 struct stat_sparc64 statbuf;
794
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000795 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200796 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000797 return;
798 }
799
800 if (!abbrev(tcp)) {
801 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
802 (unsigned long) major(statbuf.st_dev),
803 (unsigned long) minor(statbuf.st_dev),
804 (unsigned long) statbuf.st_ino,
805 sprintmode(statbuf.st_mode));
806 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
807 (unsigned long) statbuf.st_nlink,
808 (unsigned long) statbuf.st_uid,
809 (unsigned long) statbuf.st_gid);
810 tprintf("st_blksize=%lu, ",
811 (unsigned long) statbuf.st_blksize);
812 tprintf("st_blocks=%lu, ",
813 (unsigned long) statbuf.st_blocks);
814 }
815 else
816 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
817 switch (statbuf.st_mode & S_IFMT) {
818 case S_IFCHR: case S_IFBLK:
819 tprintf("st_rdev=makedev(%lu, %lu), ",
820 (unsigned long) major(statbuf.st_rdev),
821 (unsigned long) minor(statbuf.st_rdev));
822 break;
823 default:
824 tprintf("st_size=%lu, ", statbuf.st_size);
825 break;
826 }
827 if (!abbrev(tcp)) {
828 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
829 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100830 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000831 }
832 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200833 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000834}
Denys Vlasenko9472a272013-02-12 11:43:46 +0100835# endif /* SPARC64 */
836#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000837
Denys Vlasenko84703742012-02-25 02:38:52 +0100838#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200839struct stat_powerpc32 {
840 unsigned int st_dev;
841 unsigned int st_ino;
842 unsigned int st_mode;
843 unsigned short st_nlink;
844 unsigned int st_uid;
845 unsigned int st_gid;
846 unsigned int st_rdev;
847 unsigned int st_size;
848 unsigned int st_blksize;
849 unsigned int st_blocks;
850 unsigned int st_atime;
851 unsigned int st_atime_nsec;
852 unsigned int st_mtime;
853 unsigned int st_mtime_nsec;
854 unsigned int st_ctime;
855 unsigned int st_ctime_nsec;
856 unsigned int __unused4;
857 unsigned int __unused5;
858};
859
860static void
861printstat_powerpc32(struct tcb *tcp, long addr)
862{
863 struct stat_powerpc32 statbuf;
864
865 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200866 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200867 return;
868 }
869
870 if (!abbrev(tcp)) {
871 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
872 major(statbuf.st_dev), minor(statbuf.st_dev),
873 statbuf.st_ino,
874 sprintmode(statbuf.st_mode));
875 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
876 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
877 tprintf("st_blksize=%u, ", statbuf.st_blksize);
878 tprintf("st_blocks=%u, ", statbuf.st_blocks);
879 }
880 else
881 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
882 switch (statbuf.st_mode & S_IFMT) {
883 case S_IFCHR: case S_IFBLK:
884 tprintf("st_rdev=makedev(%lu, %lu), ",
885 (unsigned long) major(statbuf.st_rdev),
886 (unsigned long) minor(statbuf.st_rdev));
887 break;
888 default:
889 tprintf("st_size=%u, ", statbuf.st_size);
890 break;
891 }
892 if (!abbrev(tcp)) {
893 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
894 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100895 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200896 }
897 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200898 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200899}
Denys Vlasenko84703742012-02-25 02:38:52 +0100900#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200901
Roland McGratha4d48532005-06-08 20:45:28 +0000902static const struct xlat fileflags[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000903 { 0, NULL },
904};
905
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000906static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000907realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000908{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000909 if (!abbrev(tcp)) {
910 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
911 (unsigned long) major(statbuf->st_dev),
912 (unsigned long) minor(statbuf->st_dev),
913 (unsigned long) statbuf->st_ino,
914 sprintmode(statbuf->st_mode));
915 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
916 (unsigned long) statbuf->st_nlink,
917 (unsigned long) statbuf->st_uid,
918 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000919#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000920 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
921#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000922#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000923 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
924#endif
925 }
926 else
927 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
928 switch (statbuf->st_mode & S_IFMT) {
929 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000930#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000931 tprintf("st_rdev=makedev(%lu, %lu), ",
932 (unsigned long) major(statbuf->st_rdev),
933 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000934#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000935 tprintf("st_size=makedev(%lu, %lu), ",
936 (unsigned long) major(statbuf->st_size),
937 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000938#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000939 break;
940 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000941 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000942 break;
943 }
944 if (!abbrev(tcp)) {
945 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
946 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
947 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000948#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200949 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000950 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000951#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000952#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000953 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
954#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000955#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000956 tprintf(", st_level=%ld", statbuf->st_level);
957#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000958#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000959 tprintf(", st_fstype=%.*s",
960 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
961#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000962#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000963 tprintf(", st_gen=%u", statbuf->st_gen);
964#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200965 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000966 }
967 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200968 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000969}
970
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000971static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000972printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000973{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000974 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000975
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000976 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200977 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000978 return;
979 }
980 if (syserror(tcp) || !verbose(tcp)) {
981 tprintf("%#lx", addr);
982 return;
983 }
984
Denys Vlasenko9472a272013-02-12 11:43:46 +0100985#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000986 if (current_personality == 1) {
987 printstatsol(tcp, addr);
988 return;
989 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000990#ifdef SPARC64
991 else if (current_personality == 2) {
992 printstat_sparc64(tcp, addr);
993 return;
994 }
995#endif
Denys Vlasenko9472a272013-02-12 11:43:46 +0100996#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000997
Denys Vlasenko84703742012-02-25 02:38:52 +0100998#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200999 if (current_personality == 1) {
1000 printstat_powerpc32(tcp, addr);
1001 return;
1002 }
1003#endif
1004
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001005 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001006 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001007 return;
1008 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001009
1010 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001011}
1012
Denys Vlasenko84703742012-02-25 02:38:52 +01001013#if !defined HAVE_STAT64 && defined X86_64
Roland McGrathe6d0f712007-08-07 01:22:49 +00001014/*
1015 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1016 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1017 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1018 * __GNUC__ is needed for the required __attribute__ below.
1019 */
1020struct stat64 {
1021 unsigned long long st_dev;
1022 unsigned char __pad0[4];
1023 unsigned int __st_ino;
1024 unsigned int st_mode;
1025 unsigned int st_nlink;
1026 unsigned int st_uid;
1027 unsigned int st_gid;
1028 unsigned long long st_rdev;
1029 unsigned char __pad3[4];
1030 long long st_size;
1031 unsigned int st_blksize;
1032 unsigned long long st_blocks;
1033 unsigned int st_atime;
1034 unsigned int st_atime_nsec;
1035 unsigned int st_mtime;
1036 unsigned int st_mtime_nsec;
1037 unsigned int st_ctime;
1038 unsigned int st_ctime_nsec;
1039 unsigned long long st_ino;
1040} __attribute__((packed));
1041# define HAVE_STAT64 1
1042# define STAT64_SIZE 96
1043#endif
1044
Wichert Akkermanc7926982000-04-10 22:22:31 +00001045#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001046static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001047printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001048{
1049 struct stat64 statbuf;
1050
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001051#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001052 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1053#endif
1054
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001055 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001056 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001057 return;
1058 }
1059 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001060 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001061 return;
1062 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001063
Denys Vlasenko9472a272013-02-12 11:43:46 +01001064#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001065 if (current_personality == 1) {
1066 printstatsol(tcp, addr);
1067 return;
1068 }
1069# ifdef SPARC64
1070 else if (current_personality == 2) {
1071 printstat_sparc64(tcp, addr);
1072 return;
1073 }
1074# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +01001075#endif /* SPARC[64] */
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001076
Denys Vlasenko84703742012-02-25 02:38:52 +01001077#if defined X86_64
H.J. Lu35be5812012-04-16 13:00:01 +02001078 if (current_personality != 1) {
Andreas Schwab61b74352009-10-16 11:37:13 +02001079 printstat(tcp, addr);
1080 return;
1081 }
1082#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +00001083
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001084 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001085 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001086 return;
1087 }
1088
1089 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001090#ifdef HAVE_LONG_LONG
1091 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1092#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001093 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001094#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001095 (unsigned long) major(statbuf.st_dev),
1096 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001097#ifdef HAVE_LONG_LONG
1098 (unsigned long long) statbuf.st_ino,
1099#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001100 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001101#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001102 sprintmode(statbuf.st_mode));
1103 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1104 (unsigned long) statbuf.st_nlink,
1105 (unsigned long) statbuf.st_uid,
1106 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001107#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001108 tprintf("st_blksize=%lu, ",
1109 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001110#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1111#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001112 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001113#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001114 }
1115 else
1116 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1117 switch (statbuf.st_mode & S_IFMT) {
1118 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001119#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001120 tprintf("st_rdev=makedev(%lu, %lu), ",
1121 (unsigned long) major(statbuf.st_rdev),
1122 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001123#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001124 tprintf("st_size=makedev(%lu, %lu), ",
1125 (unsigned long) major(statbuf.st_size),
1126 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001127#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001128 break;
1129 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001130#ifdef HAVE_LONG_LONG
1131 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1132#else
1133 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1134#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001135 break;
1136 }
1137 if (!abbrev(tcp)) {
1138 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1139 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001140 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001141#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001142 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001143 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001144#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001145#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001146 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1147#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001148#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001149 tprintf(", st_level=%ld", statbuf.st_level);
1150#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001151#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001152 tprintf(", st_fstype=%.*s",
1153 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1154#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001155#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001156 tprintf(", st_gen=%u", statbuf.st_gen);
1157#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001158 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001159 }
1160 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001161 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001162}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001163#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001164
Denys Vlasenko8435d672013-02-18 15:47:57 +01001165#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001166static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001167convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001168{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001169 newbuf->st_dev = oldbuf->st_dev;
1170 newbuf->st_ino = oldbuf->st_ino;
1171 newbuf->st_mode = oldbuf->st_mode;
1172 newbuf->st_nlink = oldbuf->st_nlink;
1173 newbuf->st_uid = oldbuf->st_uid;
1174 newbuf->st_gid = oldbuf->st_gid;
1175 newbuf->st_rdev = oldbuf->st_rdev;
1176 newbuf->st_size = oldbuf->st_size;
1177 newbuf->st_atime = oldbuf->st_atime;
1178 newbuf->st_mtime = oldbuf->st_mtime;
1179 newbuf->st_ctime = oldbuf->st_ctime;
1180 newbuf->st_blksize = 0; /* not supported in old_stat */
1181 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001182}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001183
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001184static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001185printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001186{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001187 struct __old_kernel_stat statbuf;
1188 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001189
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001190 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001191 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001192 return;
1193 }
1194 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001195 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001196 return;
1197 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001198
Denys Vlasenko9472a272013-02-12 11:43:46 +01001199# if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001200 if (current_personality == 1) {
1201 printstatsol(tcp, addr);
1202 return;
1203 }
Denys Vlasenko84703742012-02-25 02:38:52 +01001204# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001205
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001206 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001207 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001208 return;
1209 }
1210
1211 convertoldstat(&statbuf, &newstatbuf);
1212 realprintstat(tcp, &newstatbuf);
1213}
Denys Vlasenko84703742012-02-25 02:38:52 +01001214#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001215
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001216int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001217sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001218{
1219 if (entering(tcp)) {
1220 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001221 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001222 } else {
1223 printstat(tcp, tcp->u_arg[1]);
1224 }
1225 return 0;
1226}
1227
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001228int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001229sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001230{
1231#ifdef HAVE_STAT64
1232 if (entering(tcp)) {
1233 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001234 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001235 } else {
1236 printstat64(tcp, tcp->u_arg[1]);
1237 }
1238 return 0;
1239#else
1240 return printargs(tcp);
1241#endif
1242}
1243
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001244#ifndef AT_SYMLINK_NOFOLLOW
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001245# define AT_SYMLINK_NOFOLLOW 0x100
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001246#endif
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001247#ifndef AT_REMOVEDIR
1248# define AT_REMOVEDIR 0x200
1249#endif
1250#ifndef AT_SYMLINK_FOLLOW
1251# define AT_SYMLINK_FOLLOW 0x400
1252#endif
1253#ifndef AT_NO_AUTOMOUNT
1254# define AT_NO_AUTOMOUNT 0x800
1255#endif
1256#ifndef AT_EMPTY_PATH
1257# define AT_EMPTY_PATH 0x1000
1258#endif
1259
1260static const struct xlat at_flags[] = {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001261 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001262 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1263 { AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" },
1264 { AT_NO_AUTOMOUNT, "AT_NO_AUTOMOUNT" },
1265 { AT_EMPTY_PATH, "AT_EMPTY_PATH" },
1266 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001267};
1268
1269int
1270sys_newfstatat(struct tcb *tcp)
1271{
1272 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001273 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001274 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001275 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001276 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001277#ifdef POWERPC64
1278 if (current_personality == 0)
1279 printstat(tcp, tcp->u_arg[2]);
1280 else
1281 printstat64(tcp, tcp->u_arg[2]);
1282#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001283 printstat64(tcp, tcp->u_arg[2]);
1284#else
1285 printstat(tcp, tcp->u_arg[2]);
1286#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001287 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001288 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001289 }
1290 return 0;
1291}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001292
Denys Vlasenko8435d672013-02-18 15:47:57 +01001293#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001294int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001295sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001296{
1297 if (entering(tcp)) {
1298 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001299 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001300 } else {
1301 printoldstat(tcp, tcp->u_arg[1]);
1302 }
1303 return 0;
1304}
Denys Vlasenko84703742012-02-25 02:38:52 +01001305#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001306
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001307int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001308sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001309{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001310 if (entering(tcp)) {
1311 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001312 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001313 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001314 printstat(tcp, tcp->u_arg[1]);
1315 }
1316 return 0;
1317}
1318
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001319int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001320sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001321{
1322#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001323 if (entering(tcp)) {
1324 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001325 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001326 } else {
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001327 printstat64(tcp, tcp->u_arg[1]);
1328 }
1329 return 0;
1330#else
1331 return printargs(tcp);
1332#endif
1333}
1334
Denys Vlasenko8435d672013-02-18 15:47:57 +01001335#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001336int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001337sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001338{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001339 if (entering(tcp)) {
1340 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001341 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001342 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001343 printoldstat(tcp, tcp->u_arg[1]);
1344 }
1345 return 0;
1346}
Denys Vlasenko84703742012-02-25 02:38:52 +01001347#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001348
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001349int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001350sys_lstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001351{
1352 if (entering(tcp)) {
1353 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001354 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001355 } else {
1356 printstat(tcp, tcp->u_arg[1]);
1357 }
1358 return 0;
1359}
1360
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001361int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001362sys_lstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001363{
1364#ifdef HAVE_STAT64
1365 if (entering(tcp)) {
1366 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001367 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001368 } else {
1369 printstat64(tcp, tcp->u_arg[1]);
1370 }
1371 return 0;
1372#else
1373 return printargs(tcp);
1374#endif
1375}
1376
Denys Vlasenko8435d672013-02-18 15:47:57 +01001377#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001378int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001379sys_oldlstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001380{
1381 if (entering(tcp)) {
1382 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001383 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001384 } else {
1385 printoldstat(tcp, tcp->u_arg[1]);
1386 }
1387 return 0;
1388}
Denys Vlasenko84703742012-02-25 02:38:52 +01001389#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001390
Denys Vlasenko9472a272013-02-12 11:43:46 +01001391#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001392
1393int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001394sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001395{
1396 if (entering(tcp)) {
1397 tprintf("%ld, ", tcp->u_arg[0]);
1398 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001399 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001400 } 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_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413{
1414 if (entering(tcp))
1415 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1416 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001417# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001418 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001419 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001420 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001421# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001422 printstat(tcp, tcp->u_arg[2]);
1423 }
1424 return 0;
1425}
1426
1427int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001428sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001429{
1430 if (entering(tcp)) {
1431 tprintf("%ld, ", tcp->u_arg[0]);
1432 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001433 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001434 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001435# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001436 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001437 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001438 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001439# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001440 printstat(tcp, tcp->u_arg[2]);
1441 }
1442 return 0;
1443}
1444
1445int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001446sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001447{
1448 int mode = tcp->u_arg[2];
1449
1450 if (entering(tcp)) {
1451 tprintf("%ld, ", tcp->u_arg[0]);
1452 printpath(tcp, tcp->u_arg[1]);
1453 tprintf(", %s", sprintmode(mode));
1454 switch (mode & S_IFMT) {
1455 case S_IFCHR: case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001456 tprintf(", makedev(%lu, %lu)",
1457 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1458 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001459 break;
1460 default:
1461 break;
1462 }
1463 }
1464 return 0;
1465}
1466
Denys Vlasenko84703742012-02-25 02:38:52 +01001467# ifdef HAVE_SYS_ACL_H
Wichert Akkerman8829a551999-06-11 13:18:40 +00001468
Denys Vlasenko84703742012-02-25 02:38:52 +01001469# include <sys/acl.h>
Wichert Akkerman8829a551999-06-11 13:18:40 +00001470
Roland McGratha4d48532005-06-08 20:45:28 +00001471static const struct xlat aclcmds[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001472# ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001473 { SETACL, "SETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001474# endif
1475# ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001476 { GETACL, "GETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001477# endif
1478# ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001479 { GETACLCNT, "GETACLCNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001480# endif
1481# ifdef ACL_GET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001482 { ACL_GET, "ACL_GET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001483# endif
1484# ifdef ACL_SET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001485 { ACL_SET, "ACL_SET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001486# endif
1487# ifdef ACL_CNT
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001488 { ACL_CNT, "ACL_CNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001489# endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001490 { 0, NULL },
1491};
1492
1493int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001494sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001495{
1496 if (entering(tcp)) {
1497 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001498 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001499 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1500 tprintf(", %ld", tcp->u_arg[2]);
1501 /*
1502 * FIXME - dump out the list of aclent_t's pointed to
1503 * by "tcp->u_arg[3]" if it's not NULL.
1504 */
1505 if (tcp->u_arg[3])
1506 tprintf(", %#lx", tcp->u_arg[3]);
1507 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001508 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001509 }
1510 return 0;
1511}
1512
Wichert Akkerman8829a551999-06-11 13:18:40 +00001513int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001514sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001515{
1516 if (entering(tcp)) {
1517 tprintf("%ld, ", tcp->u_arg[0]);
1518 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1519 tprintf(", %ld", tcp->u_arg[2]);
1520 /*
1521 * FIXME - dump out the list of aclent_t's pointed to
1522 * by "tcp->u_arg[3]" if it's not NULL.
1523 */
1524 if (tcp->u_arg[3])
1525 tprintf(", %#lx", tcp->u_arg[3]);
1526 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001527 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001528 }
1529 return 0;
1530}
1531
Roland McGratha4d48532005-06-08 20:45:28 +00001532static const struct xlat aclipc[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001533# ifdef IPC_SHM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001534 { IPC_SHM, "IPC_SHM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001535# endif
1536# ifdef IPC_SEM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001537 { IPC_SEM, "IPC_SEM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001538# endif
1539# ifdef IPC_MSG
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001540 { IPC_MSG, "IPC_MSG" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001541# endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001542 { 0, NULL },
1543};
1544
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001545int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001546sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001547{
1548 if (entering(tcp)) {
1549 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1550 tprintf(", %#lx, ", tcp->u_arg[1]);
1551 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1552 tprintf(", %ld", tcp->u_arg[3]);
1553 /*
1554 * FIXME - dump out the list of aclent_t's pointed to
1555 * by "tcp->u_arg[4]" if it's not NULL.
1556 */
1557 if (tcp->u_arg[4])
1558 tprintf(", %#lx", tcp->u_arg[4]);
1559 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001560 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001561 }
1562 return 0;
1563}
1564
Denys Vlasenko84703742012-02-25 02:38:52 +01001565# endif /* HAVE_SYS_ACL_H */
Wichert Akkerman8829a551999-06-11 13:18:40 +00001566
Denys Vlasenko9472a272013-02-12 11:43:46 +01001567#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001568
Roland McGrathd9f816f2004-09-04 03:39:20 +00001569static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001570 { 0x73757245, "CODA_SUPER_MAGIC" },
1571 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1572 { 0x1373, "DEVFS_SUPER_MAGIC" },
1573 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1574 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001575 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1576 { 0xef53, "EXT2_SUPER_MAGIC" },
1577 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001578 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001579 { 0x9660, "ISOFS_SUPER_MAGIC" },
1580 { 0x137f, "MINIX_SUPER_MAGIC" },
1581 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001582 { 0x2468, "MINIX2_SUPER_MAGIC" },
1583 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001584 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001585 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001586 { 0x6969, "NFS_SUPER_MAGIC" },
1587 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001588 { 0x002f, "QNX4_SUPER_MAGIC" },
1589 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1590 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1591 { 0x517b, "SMB_SUPER_MAGIC" },
1592 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1593 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1594 { 0x00011954, "UFS_MAGIC" },
1595 { 0x54190100, "UFS_CIGAM" },
1596 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001597 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001598 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001599 { 0, NULL },
1600};
1601
Roland McGrathf9c49b22004-10-06 22:11:54 +00001602static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001603sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001604{
1605 static char buf[32];
Roland McGrathf9c49b22004-10-06 22:11:54 +00001606 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001607
1608 s = xlookup(fsmagic, magic);
1609 if (s) {
1610 sprintf(buf, "\"%s\"", s);
1611 return buf;
1612 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001613 sprintf(buf, "%#x", magic);
1614 return buf;
1615}
1616
1617static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001618printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001619{
1620 struct statfs statbuf;
1621
1622 if (syserror(tcp) || !verbose(tcp)) {
1623 tprintf("%#lx", addr);
1624 return;
1625 }
1626 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001627 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001628 return;
1629 }
1630#ifdef ALPHA
1631
1632 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1633 sprintfstype(statbuf.f_type),
1634 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001635 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001636 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001637 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1638 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001639#else /* !ALPHA */
1640 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1641 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001642 (unsigned long)statbuf.f_bsize,
1643 (unsigned long)statbuf.f_blocks,
1644 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001645 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1646 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001647 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001648 (unsigned long)statbuf.f_ffree,
1649 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001650 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001651#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001652#ifdef _STATFS_F_FRSIZE
1653 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1654#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001655 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001656}
1657
1658int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001659sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001660{
1661 if (entering(tcp)) {
1662 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001663 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001664 } else {
1665 printstatfs(tcp, tcp->u_arg[1]);
1666 }
1667 return 0;
1668}
1669
1670int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001671sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001672{
1673 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001674 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001675 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001676 } else {
1677 printstatfs(tcp, tcp->u_arg[1]);
1678 }
1679 return 0;
1680}
1681
Denys Vlasenko84703742012-02-25 02:38:52 +01001682#if defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001683static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001684printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001685{
1686 struct statfs64 statbuf;
1687
1688 if (syserror(tcp) || !verbose(tcp)) {
1689 tprintf("%#lx", addr);
1690 return;
1691 }
1692 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001693 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001694 return;
1695 }
Roland McGrath08738432005-06-03 02:40:39 +00001696 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001697 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001698 (unsigned long long)statbuf.f_bsize,
1699 (unsigned long long)statbuf.f_blocks,
1700 (unsigned long long)statbuf.f_bfree);
1701 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1702 (unsigned long long)statbuf.f_bavail,
1703 (unsigned long long)statbuf.f_files,
1704 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001705 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1706 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001707#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001708 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001709#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001710#ifdef _STATFS_F_FLAGS
1711 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1712#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001713 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001714}
1715
Andreas Schwab7d558012012-01-17 18:14:22 +01001716struct compat_statfs64 {
1717 uint32_t f_type;
1718 uint32_t f_bsize;
1719 uint64_t f_blocks;
1720 uint64_t f_bfree;
1721 uint64_t f_bavail;
1722 uint64_t f_files;
1723 uint64_t f_ffree;
1724 fsid_t f_fsid;
1725 uint32_t f_namelen;
1726 uint32_t f_frsize;
1727 uint32_t f_flags;
1728 uint32_t f_spare[4];
1729}
1730#if defined(X86_64) || defined(IA64)
1731 __attribute__ ((packed, aligned(4)))
1732#endif
1733;
1734
1735static void
1736printcompat_statfs64(struct tcb *tcp, long addr)
1737{
1738 struct compat_statfs64 statbuf;
1739
1740 if (syserror(tcp) || !verbose(tcp)) {
1741 tprintf("%#lx", addr);
1742 return;
1743 }
1744 if (umove(tcp, addr, &statbuf) < 0) {
1745 tprints("{...}");
1746 return;
1747 }
1748 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1749 sprintfstype(statbuf.f_type),
1750 (unsigned long)statbuf.f_bsize,
1751 (unsigned long long)statbuf.f_blocks,
1752 (unsigned long long)statbuf.f_bfree);
1753 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1754 (unsigned long long)statbuf.f_bavail,
1755 (unsigned long long)statbuf.f_files,
1756 (unsigned long long)statbuf.f_ffree,
1757 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1758 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1759 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001760 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
Andreas Schwab7d558012012-01-17 18:14:22 +01001761}
1762
Roland McGrathab147c52003-07-17 09:03:02 +00001763int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001764sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001765{
1766 if (entering(tcp)) {
1767 printpath(tcp, tcp->u_arg[0]);
1768 tprintf(", %lu, ", tcp->u_arg[1]);
1769 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001770 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001771 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001772 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1773 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001774 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001775 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001776 }
1777 return 0;
1778}
1779
1780int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001781sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001782{
1783 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001784 printfd(tcp, tcp->u_arg[0]);
1785 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001786 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001787 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001788 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001789 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1790 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001791 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001792 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001793 }
1794 return 0;
1795}
1796#endif
1797
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001798#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001799int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001800osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001801{
1802 if (entering(tcp)) {
1803 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001804 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001805 } else {
1806 printstatfs(tcp, tcp->u_arg[1]);
1807 tprintf(", %lu", tcp->u_arg[2]);
1808 }
1809 return 0;
1810}
1811
1812int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001813osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001814{
1815 if (entering(tcp)) {
1816 tprintf("%lu, ", tcp->u_arg[0]);
1817 } else {
1818 printstatfs(tcp, tcp->u_arg[1]);
1819 tprintf(", %lu", tcp->u_arg[2]);
1820 }
1821 return 0;
1822}
Denys Vlasenko84703742012-02-25 02:38:52 +01001823#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001824
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001825/* directory */
1826int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001827sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001828{
1829 if (entering(tcp)) {
1830 printpath(tcp, tcp->u_arg[0]);
1831 }
1832 return 0;
1833}
1834
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001835static int
1836decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001837{
1838 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001839 printpath(tcp, tcp->u_arg[offset]);
1840 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001841 }
1842 return 0;
1843}
1844
1845int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001846sys_mkdir(struct tcb *tcp)
1847{
1848 return decode_mkdir(tcp, 0);
1849}
1850
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001851int
1852sys_mkdirat(struct tcb *tcp)
1853{
1854 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001855 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001856 return decode_mkdir(tcp, 1);
1857}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001858
1859int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001860sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001861{
1862 if (entering(tcp)) {
1863 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001864 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001865 printpath(tcp, tcp->u_arg[1]);
1866 }
1867 return 0;
1868}
1869
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001870int
1871sys_linkat(struct tcb *tcp)
1872{
1873 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001874 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001875 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001876 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001877 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001878 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001879 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001880 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001881 }
1882 return 0;
1883}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001884
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001885int
1886sys_unlinkat(struct tcb *tcp)
1887{
1888 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001889 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001890 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001891 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001892 printflags(at_flags, tcp->u_arg[2], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001893 }
1894 return 0;
1895}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001896
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001897int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001898sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001899{
1900 if (entering(tcp)) {
1901 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001902 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001903 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001904 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001905 }
1906 return 0;
1907}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001908
1909static int
1910decode_readlink(struct tcb *tcp, int offset)
1911{
1912 if (entering(tcp)) {
1913 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001914 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001915 } else {
1916 if (syserror(tcp))
1917 tprintf("%#lx", tcp->u_arg[offset + 1]);
1918 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001919 /* Used to use printpathn(), but readlink
1920 * neither includes NUL in the returned count,
1921 * nor actually writes it into memory.
1922 * printpathn() would decide on printing
1923 * "..." continuation based on garbage
1924 * past return buffer's end.
1925 */
1926 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001927 tprintf(", %lu", tcp->u_arg[offset + 2]);
1928 }
1929 return 0;
1930}
1931
1932int
1933sys_readlink(struct tcb *tcp)
1934{
1935 return decode_readlink(tcp, 0);
1936}
1937
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001938int
1939sys_readlinkat(struct tcb *tcp)
1940{
1941 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001942 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001943 return decode_readlink(tcp, 1);
1944}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001945
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001946int
1947sys_renameat(struct tcb *tcp)
1948{
1949 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001950 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001951 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001952 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001953 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001954 printpath(tcp, tcp->u_arg[3]);
1955 }
1956 return 0;
1957}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001958
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001959int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001960sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001961{
1962 if (entering(tcp)) {
1963 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001964 printuid(", ", tcp->u_arg[1]);
1965 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001966 }
1967 return 0;
1968}
1969
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001970int
1971sys_fchownat(struct tcb *tcp)
1972{
1973 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001974 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001975 printpath(tcp, tcp->u_arg[1]);
1976 printuid(", ", tcp->u_arg[2]);
1977 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001978 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001979 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001980 }
1981 return 0;
1982}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001983
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001984int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001985sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001986{
1987 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001988 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001989 printuid(", ", tcp->u_arg[1]);
1990 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001991 }
1992 return 0;
1993}
1994
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001995static int
1996decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001997{
1998 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001999 printpath(tcp, tcp->u_arg[offset]);
2000 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002001 }
2002 return 0;
2003}
2004
2005int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002006sys_chmod(struct tcb *tcp)
2007{
2008 return decode_chmod(tcp, 0);
2009}
2010
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002011int
2012sys_fchmodat(struct tcb *tcp)
2013{
2014 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002015 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002016 return decode_chmod(tcp, 1);
2017}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002018
2019int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002020sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002021{
2022 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002023 printfd(tcp, tcp->u_arg[0]);
2024 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002025 }
2026 return 0;
2027}
2028
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002029#ifdef ALPHA
2030int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002031sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002032{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002033 if (entering(tcp)) {
2034 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002035 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002036 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2037 }
2038 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002039}
2040#endif
2041
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002042static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002043decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002044{
2045 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002046 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002047 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002048 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002049 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00002050 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002051 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00002052 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2053 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002054 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002055 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002056 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00002057 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002058 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00002059 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002060 }
2061 return 0;
2062}
2063
2064int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002065sys_utimes(struct tcb *tcp)
2066{
Roland McGrath6afc5652007-07-24 01:57:11 +00002067 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002068}
2069
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002070int
2071sys_futimesat(struct tcb *tcp)
2072{
2073 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002074 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002075 return decode_utimes(tcp, 1, 0);
2076}
2077
2078int
2079sys_utimensat(struct tcb *tcp)
2080{
2081 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002082 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002083 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002084 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00002085 printflags(at_flags, tcp->u_arg[3], "AT_???");
Roland McGrath6afc5652007-07-24 01:57:11 +00002086 }
2087 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002088}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002089
2090int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002091sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002092{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002093 union {
2094 long utl[2];
2095 int uti[2];
Denys Vlasenko751acb32013-02-08 15:34:46 +01002096 long paranoia_for_huge_wordsize[4];
Roland McGrath7e9817c2007-07-05 20:31:58 +00002097 } u;
Denys Vlasenko751acb32013-02-08 15:34:46 +01002098 unsigned wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002099
2100 if (entering(tcp)) {
2101 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002102 tprints(", ");
Denys Vlasenko751acb32013-02-08 15:34:46 +01002103
2104 wordsize = current_wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002105 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002106 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002107 else if (!verbose(tcp))
2108 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002109 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002110 tprints("[?, ?]");
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002111 else if (wordsize == sizeof u.utl[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002112 tprintf("[%s,", sprinttime(u.utl[0]));
2113 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002114 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002115 else if (wordsize == sizeof u.uti[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002116 tprintf("[%s,", sprinttime(u.uti[0]));
2117 tprintf(" %s]", sprinttime(u.uti[1]));
2118 }
2119 else
Denys Vlasenko751acb32013-02-08 15:34:46 +01002120 tprintf("<decode error: unsupported wordsize %d>",
2121 wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002122 }
2123 return 0;
2124}
2125
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002126static int
2127decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002128{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002129 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002130
2131 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002132 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002133 tprintf(", %s", sprintmode(mode));
2134 switch (mode & S_IFMT) {
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002135 case S_IFCHR:
2136 case S_IFBLK:
Denys Vlasenko9472a272013-02-12 11:43:46 +01002137#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002138 if (current_personality == 1)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002139 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002140 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2141 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002142 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002143#endif
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002144 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002145 (unsigned long) major(tcp->u_arg[offset + 2]),
2146 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002147 break;
2148 default:
2149 break;
2150 }
2151 }
2152 return 0;
2153}
2154
2155int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002156sys_mknod(struct tcb *tcp)
2157{
2158 return decode_mknod(tcp, 0);
2159}
2160
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002161int
2162sys_mknodat(struct tcb *tcp)
2163{
2164 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002165 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002166 return decode_mknod(tcp, 1);
2167}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002168
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002169static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002170printdir(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002171{
2172 struct dirent d;
2173
2174 if (!verbose(tcp)) {
2175 tprintf("%#lx", addr);
2176 return;
2177 }
2178 if (umove(tcp, addr, &d) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002179 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002180 return;
2181 }
2182 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002183 tprints("d_name=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002184 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002185 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002186}
2187
2188int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002189sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002190{
2191 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002192 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002193 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002194 } else {
2195 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2196 tprintf("%#lx", tcp->u_arg[1]);
2197 else
2198 printdir(tcp, tcp->u_arg[1]);
2199 /* Not much point in printing this out, it is always 1. */
2200 if (tcp->u_arg[2] != 1)
2201 tprintf(", %lu", tcp->u_arg[2]);
2202 }
2203 return 0;
2204}
2205
Roland McGratha4d48532005-06-08 20:45:28 +00002206static const struct xlat direnttypes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002207 { DT_UNKNOWN, "DT_UNKNOWN" },
2208 { DT_FIFO, "DT_FIFO" },
2209 { DT_CHR, "DT_CHR" },
2210 { DT_DIR, "DT_DIR" },
2211 { DT_BLK, "DT_BLK" },
2212 { DT_REG, "DT_REG" },
2213 { DT_LNK, "DT_LNK" },
2214 { DT_SOCK, "DT_SOCK" },
2215 { DT_WHT, "DT_WHT" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002216 { 0, NULL },
2217};
2218
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002219int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002220sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002221{
2222 int i, len, dents = 0;
2223 char *buf;
2224
2225 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002226 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002227 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002228 return 0;
2229 }
2230 if (syserror(tcp) || !verbose(tcp)) {
2231 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2232 return 0;
2233 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002234 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002235 /* Beware of insanely large or negative values in tcp->u_rval */
2236 if (tcp->u_rval > 1024*1024)
2237 len = 1024*1024;
2238 if (tcp->u_rval < 0)
2239 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002240 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002241 if (len && !buf)
2242 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002243 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002244 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002245 free(buf);
2246 return 0;
2247 }
2248 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002249 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002250 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002251 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002252 if (!abbrev(tcp)) {
2253 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2254 i ? " " : "", d->d_ino, d->d_off);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002255 tprintf("d_reclen=%u, d_name=\"%s\", d_type=",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002256 d->d_reclen, d->d_name);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002257 printxval(direnttypes, buf[i + d->d_reclen - 1], "DT_???");
2258 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002259 }
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002260 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002261 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002262 break;
2263 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002264 i += d->d_reclen;
2265 dents++;
2266 }
2267 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002268 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002269 else
2270 tprintf("/* %u entries */", dents);
2271 tprintf(", %lu", tcp->u_arg[2]);
2272 free(buf);
2273 return 0;
2274}
2275
John Hughesbdf48f52001-03-06 15:08:09 +00002276#if _LFS64_LARGEFILE
2277int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002278sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002279{
2280 int i, len, dents = 0;
2281 char *buf;
2282
2283 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002284 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002285 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002286 return 0;
2287 }
2288 if (syserror(tcp) || !verbose(tcp)) {
2289 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2290 return 0;
2291 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002292
John Hughesbdf48f52001-03-06 15:08:09 +00002293 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002294 /* Beware of insanely large or negative tcp->u_rval */
2295 if (tcp->u_rval > 1024*1024)
2296 len = 1024*1024;
2297 if (tcp->u_rval < 0)
2298 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002299 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002300 if (len && !buf)
2301 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002302
John Hughesbdf48f52001-03-06 15:08:09 +00002303 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002304 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002305 free(buf);
2306 return 0;
2307 }
2308 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002309 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002310 for (i = 0; i < len;) {
2311 struct dirent64 *d = (struct dirent64 *) &buf[i];
John Hughesbdf48f52001-03-06 15:08:09 +00002312 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002313 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002314 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002315 d->d_ino,
2316 d->d_off);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002317 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002318 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002319 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002320 tprintf("d_reclen=%u, d_name=\"%s\"}",
2321 d->d_reclen, d->d_name);
2322 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002323 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002324 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002325 break;
2326 }
John Hughesbdf48f52001-03-06 15:08:09 +00002327 i += d->d_reclen;
2328 dents++;
2329 }
2330 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002331 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002332 else
2333 tprintf("/* %u entries */", dents);
2334 tprintf(", %lu", tcp->u_arg[2]);
2335 free(buf);
2336 return 0;
2337}
2338#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002339
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002340int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002341sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002342{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002343 if (exiting(tcp)) {
2344 if (syserror(tcp))
2345 tprintf("%#lx", tcp->u_arg[0]);
2346 else
2347 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2348 tprintf(", %lu", tcp->u_arg[1]);
2349 }
2350 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002351}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002352
2353#ifdef HAVE_SYS_ASYNCH_H
2354
2355int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002356sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002357{
2358 struct aio_result_t res;
2359
2360 if (entering(tcp)) {
2361 tprintf("%lu, ", tcp->u_arg[0]);
2362 } else {
2363 if (syserror(tcp))
2364 tprintf("%#lx", tcp->u_arg[1]);
2365 else
2366 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2367 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2368 printxval(whence, tcp->u_arg[4], "L_???");
2369 if (syserror(tcp) || tcp->u_arg[5] == 0
2370 || umove(tcp, tcp->u_arg[5], &res) < 0)
2371 tprintf(", %#lx", tcp->u_arg[5]);
2372 else
2373 tprintf(", {aio_return %d aio_errno %d}",
2374 res.aio_return, res.aio_errno);
2375 }
2376 return 0;
2377}
2378
2379int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002380sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002381{
2382 struct aio_result_t res;
2383
2384 if (entering(tcp)) {
2385 tprintf("%lu, ", tcp->u_arg[0]);
2386 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2387 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2388 printxval(whence, tcp->u_arg[4], "L_???");
2389 }
2390 else {
2391 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002392 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002393 else if (syserror(tcp)
2394 || umove(tcp, tcp->u_arg[5], &res) < 0)
2395 tprintf(", %#lx", tcp->u_arg[5]);
2396 else
2397 tprintf(", {aio_return %d aio_errno %d}",
2398 res.aio_return, res.aio_errno);
2399 }
2400 return 0;
2401}
2402
2403int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002404sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002405{
2406 if (entering(tcp))
2407 printtv(tcp, tcp->u_arg[0]);
2408 return 0;
2409}
2410
2411int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002412sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002413{
2414 struct aio_result_t res;
2415
2416 if (exiting(tcp)) {
2417 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002418 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002419 else if (syserror(tcp)
2420 || umove(tcp, tcp->u_arg[0], &res) < 0)
2421 tprintf("%#lx", tcp->u_arg[0]);
2422 else
2423 tprintf("{aio_return %d aio_errno %d}",
2424 res.aio_return, res.aio_errno);
2425 }
2426 return 0;
2427}
2428
2429#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002430
Roland McGratha4d48532005-06-08 20:45:28 +00002431static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002432#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002433 { XATTR_CREATE, "XATTR_CREATE" },
2434 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002435#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002436 { 0, NULL }
2437};
2438
Roland McGrath3292e222004-08-31 06:30:48 +00002439static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002440print_xattr_val(struct tcb *tcp, int failed,
2441 unsigned long arg,
2442 unsigned long insize,
2443 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002444{
Dmitry V. Levin1f215132012-12-07 21:38:52 +00002445 if (insize == 0)
2446 failed = 1;
Denys Vlasenko1d632462009-04-14 12:51:00 +00002447 if (!failed) {
2448 unsigned long capacity = 4 * size + 1;
2449 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2450 if (buf == NULL || /* probably a bogus size argument */
2451 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2452 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002453 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002454 else {
2455 unsigned char *out = buf;
2456 unsigned char *in = &buf[3 * size];
2457 size_t i;
2458 for (i = 0; i < size; ++i) {
2459 if (isprint(in[i]))
2460 *out++ = in[i];
2461 else {
2462#define tohex(n) "0123456789abcdef"[n]
2463 *out++ = '\\';
2464 *out++ = 'x';
2465 *out++ = tohex(in[i] / 16);
2466 *out++ = tohex(in[i] % 16);
2467 }
2468 }
2469 /* Don't print terminating NUL if there is one. */
2470 if (i > 0 && in[i - 1] == '\0')
2471 out -= 4;
2472 *out = '\0';
2473 tprintf(", \"%s\", %ld", buf, insize);
2474 }
2475 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002476 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002477 if (failed)
2478 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002479}
2480
Roland McGrath186c5ac2002-12-15 23:58:23 +00002481int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002482sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002483{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002484 if (entering(tcp)) {
2485 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002486 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002487 printstr(tcp, tcp->u_arg[1], -1);
2488 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002489 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002490 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2491 }
2492 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002493}
2494
2495int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002496sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002497{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002498 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002499 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002500 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002501 printstr(tcp, tcp->u_arg[1], -1);
2502 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002503 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002504 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2505 }
2506 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002507}
2508
2509int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002510sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002511{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002512 if (entering(tcp)) {
2513 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002514 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002515 printstr(tcp, tcp->u_arg[1], -1);
2516 } else {
2517 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2518 tcp->u_rval);
2519 }
2520 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002521}
2522
2523int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002524sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002525{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002526 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002527 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002528 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002529 printstr(tcp, tcp->u_arg[1], -1);
2530 } else {
2531 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2532 tcp->u_rval);
2533 }
2534 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002535}
2536
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002537static void
2538print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2539{
2540 if (syserror(tcp)) {
2541 tprintf("%#lx", addr);
2542 } else {
2543 if (!addr) {
2544 tprints("NULL");
2545 } else {
2546 unsigned long len =
2547 (size < tcp->u_rval) ? size : tcp->u_rval;
2548 printstr(tcp, addr, len);
2549 }
2550 }
2551 tprintf(", %lu", size);
2552}
2553
Roland McGrath186c5ac2002-12-15 23:58:23 +00002554int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002555sys_listxattr(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]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002559 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002560 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002561 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002562 }
2563 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002564}
2565
2566int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002567sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002568{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002569 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002570 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002571 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002572 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002573 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002574 }
2575 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002576}
2577
2578int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002579sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002580{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002581 if (entering(tcp)) {
2582 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002583 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002584 printstr(tcp, tcp->u_arg[1], -1);
2585 }
2586 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002587}
2588
2589int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002590sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002591{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002592 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002593 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002594 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002595 printstr(tcp, tcp->u_arg[1], -1);
2596 }
2597 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002598}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002599
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002600static const struct xlat advise[] = {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002601 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2602 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2603 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2604 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2605 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2606 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2607 { 0, NULL }
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002608};
2609
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002610int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002611sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002612{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002613 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002614 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002615 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002616 argn = printllval(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002617 tprintf(", %ld, ", tcp->u_arg[argn++]);
2618 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002619 }
2620 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002621}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002622
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002623int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002624sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002625{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002626 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002627 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002628 printfd(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002629#if defined ARM || defined POWERPC
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002630 argn = printllval(tcp, ", %lld, ", 2);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002631#else
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002632 argn = printllval(tcp, ", %lld, ", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002633#endif
2634 argn = printllval(tcp, "%lld, ", argn);
2635#if defined ARM || defined POWERPC
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002636 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002637#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002638 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002639#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002640 }
2641 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002642}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002643
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002644static const struct xlat inotify_modes[] = {
Dmitry V. Levind475c062011-03-03 01:02:41 +00002645 { 0x00000001, "IN_ACCESS" },
2646 { 0x00000002, "IN_MODIFY" },
2647 { 0x00000004, "IN_ATTRIB" },
2648 { 0x00000008, "IN_CLOSE_WRITE"},
2649 { 0x00000010, "IN_CLOSE_NOWRITE"},
2650 { 0x00000020, "IN_OPEN" },
2651 { 0x00000040, "IN_MOVED_FROM" },
2652 { 0x00000080, "IN_MOVED_TO" },
2653 { 0x00000100, "IN_CREATE" },
2654 { 0x00000200, "IN_DELETE" },
2655 { 0x00000400, "IN_DELETE_SELF"},
2656 { 0x00000800, "IN_MOVE_SELF" },
2657 { 0x00002000, "IN_UNMOUNT" },
2658 { 0x00004000, "IN_Q_OVERFLOW" },
2659 { 0x00008000, "IN_IGNORED" },
2660 { 0x01000000, "IN_ONLYDIR" },
2661 { 0x02000000, "IN_DONT_FOLLOW"},
2662 { 0x20000000, "IN_MASK_ADD" },
2663 { 0x40000000, "IN_ISDIR" },
2664 { 0x80000000, "IN_ONESHOT" },
2665 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002666};
2667
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002668static const struct xlat inotify_init_flags[] = {
2669 { 0x00000800, "IN_NONBLOCK" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002670 { 0x00080000, "IN_CLOEXEC" },
2671 { 0, NULL }
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002672};
2673
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002674int
2675sys_inotify_add_watch(struct tcb *tcp)
2676{
2677 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002678 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002679 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002680 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002681 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002682 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2683 }
2684 return 0;
2685}
2686
2687int
2688sys_inotify_rm_watch(struct tcb *tcp)
2689{
2690 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002691 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levinab1a70c2012-03-11 15:33:34 +00002692 tprintf(", %d", (int) tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002693 }
2694 return 0;
2695}
Roland McGrath96a96612008-05-20 04:56:18 +00002696
2697int
Mark Wielaardbab89402010-03-21 14:41:26 +01002698sys_inotify_init1(struct tcb *tcp)
2699{
2700 if (entering(tcp))
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002701 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
Mark Wielaardbab89402010-03-21 14:41:26 +01002702 return 0;
2703}
2704
2705int
Roland McGrath96a96612008-05-20 04:56:18 +00002706sys_fallocate(struct tcb *tcp)
2707{
2708 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002709 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002710 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002711 tprintf(", %#lo, ", tcp->u_arg[1]); /* mode */
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002712 argn = printllval(tcp, "%llu, ", 2); /* offset */
2713 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002714 }
2715 return 0;
2716}
Dmitry V. Levin88293652012-03-09 21:02:19 +00002717
Dmitry V. Levinad0c01e2012-03-15 00:52:22 +00002718#ifndef SWAP_FLAG_PREFER
2719# define SWAP_FLAG_PREFER 0x8000
2720#endif
2721#ifndef SWAP_FLAG_DISCARD
2722# define SWAP_FLAG_DISCARD 0x10000
2723#endif
Dmitry V. Levin88293652012-03-09 21:02:19 +00002724static const struct xlat swap_flags[] = {
2725 { SWAP_FLAG_PREFER, "SWAP_FLAG_PREFER" },
2726 { SWAP_FLAG_DISCARD, "SWAP_FLAG_DISCARD" },
2727 { 0, NULL }
2728};
2729
2730int
2731sys_swapon(struct tcb *tcp)
2732{
2733 if (entering(tcp)) {
2734 int flags = tcp->u_arg[1];
2735 printpath(tcp, tcp->u_arg[0]);
2736 tprints(", ");
2737 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2738 "SWAP_FLAG_???");
2739 if (flags & SWAP_FLAG_PREFER)
2740 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);
2741 }
2742 return 0;
2743}
H.J. Lu085e4282012-04-17 11:05:04 -07002744
2745#ifdef X32
2746# undef stat64
2747# undef sys_fstat64
2748# undef sys_stat64
2749
2750static void
2751realprintstat64(struct tcb *tcp, long addr)
2752{
2753 struct stat64 statbuf;
2754
2755 if (!addr) {
2756 tprints("NULL");
2757 return;
2758 }
2759 if (syserror(tcp) || !verbose(tcp)) {
2760 tprintf("%#lx", addr);
2761 return;
2762 }
2763
2764 if (umove(tcp, addr, &statbuf) < 0) {
2765 tprints("{...}");
2766 return;
2767 }
2768
2769 if (!abbrev(tcp)) {
2770 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
2771 (unsigned long) major(statbuf.st_dev),
2772 (unsigned long) minor(statbuf.st_dev),
2773 (unsigned long long) statbuf.st_ino,
2774 sprintmode(statbuf.st_mode));
2775 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
2776 (unsigned long) statbuf.st_nlink,
2777 (unsigned long) statbuf.st_uid,
2778 (unsigned long) statbuf.st_gid);
2779 tprintf("st_blksize=%lu, ",
2780 (unsigned long) statbuf.st_blksize);
2781 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
2782 }
2783 else
2784 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
2785 switch (statbuf.st_mode & S_IFMT) {
2786 case S_IFCHR: case S_IFBLK:
2787 tprintf("st_rdev=makedev(%lu, %lu), ",
2788 (unsigned long) major(statbuf.st_rdev),
2789 (unsigned long) minor(statbuf.st_rdev));
2790 break;
2791 default:
2792 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
2793 break;
2794 }
2795 if (!abbrev(tcp)) {
2796 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
2797 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
2798 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
2799 tprints("}");
2800 }
2801 else
2802 tprints("...}");
2803}
2804
2805int
2806sys_fstat64(struct tcb *tcp)
2807{
2808 if (entering(tcp)) {
2809 printfd(tcp, tcp->u_arg[0]);
2810 tprints(", ");
2811 } else {
2812 realprintstat64(tcp, tcp->u_arg[1]);
2813 }
2814 return 0;
2815}
2816
2817int
2818sys_stat64(struct tcb *tcp)
2819{
2820 if (entering(tcp)) {
2821 printpath(tcp, tcp->u_arg[0]);
2822 tprints(", ");
2823 } else {
2824 realprintstat64(tcp, tcp->u_arg[1]);
2825 }
2826 return 0;
2827}
2828#endif