blob: 74f6adfd368ade13fea7086670b1589d0f4ba022 [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;
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000120} __attribute__((packed));
121# define HAVE_STAT64 1
Dmitry V. Levinbd2e28a2013-05-01 15:14:25 +0000122
123struct __old_kernel_stat {
124 unsigned short st_dev;
125 unsigned short st_ino;
126 unsigned short st_mode;
127 unsigned short st_nlink;
128 unsigned short st_uid;
129 unsigned short st_gid;
130 unsigned short st_rdev;
131 unsigned int st_size;
132 unsigned int st_atime;
133 unsigned int st_mtime;
134 unsigned int st_ctime;
135};
Denys Vlasenko84703742012-02-25 02:38:52 +0100136#else
137# undef dev_t
138# undef ino_t
139# undef mode_t
140# undef nlink_t
141# undef uid_t
142# undef gid_t
143# undef off_t
144# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100145# define dev_t __kernel_dev_t
146# define ino_t __kernel_ino_t
147# define mode_t __kernel_mode_t
148# define nlink_t __kernel_nlink_t
149# define uid_t __kernel_uid_t
150# define gid_t __kernel_gid_t
151# define off_t __kernel_off_t
152# define loff_t __kernel_loff_t
Wichert Akkermana6013701999-07-08 14:00:58 +0000153
Denys Vlasenko84703742012-02-25 02:38:52 +0100154# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +0000155
Denys Vlasenko84703742012-02-25 02:38:52 +0100156# undef dev_t
157# undef ino_t
158# undef mode_t
159# undef nlink_t
160# undef uid_t
161# undef gid_t
162# undef off_t
163# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100164# define dev_t dev_t
165# define ino_t ino_t
166# define mode_t mode_t
167# define nlink_t nlink_t
168# define uid_t uid_t
169# define gid_t gid_t
170# define off_t off_t
171# define loff_t loff_t
172#endif
173
Denys Vlasenko84703742012-02-25 02:38:52 +0100174#define stat libc_stat
175#define stat64 libc_stat64
176#include <sys/stat.h>
177#undef stat
178#undef stat64
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100179/* These might be macros. */
Denys Vlasenko84703742012-02-25 02:38:52 +0100180#undef st_atime
181#undef st_mtime
182#undef st_ctime
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000183
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000184#include <fcntl.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000185#ifdef HAVE_SYS_VFS_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100186# include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000187#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +0000188#ifdef HAVE_LINUX_XATTR_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100189# include <linux/xattr.h>
Denys Vlasenkoed720fd2012-02-25 02:24:03 +0100190#else
Denys Vlasenko84703742012-02-25 02:38:52 +0100191# define XATTR_CREATE 1
192# define XATTR_REPLACE 2
Roland McGrath186c5ac2002-12-15 23:58:23 +0000193#endif
194
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000195#ifdef MAJOR_IN_SYSMACROS
Denys Vlasenko84703742012-02-25 02:38:52 +0100196# include <sys/sysmacros.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000197#endif
198
199#ifdef MAJOR_IN_MKDEV
Denys Vlasenko84703742012-02-25 02:38:52 +0100200# include <sys/mkdev.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000201#endif
202
203#ifdef HAVE_SYS_ASYNCH_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100204# include <sys/asynch.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205#endif
206
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100207struct kernel_dirent {
208 unsigned long d_ino;
209 unsigned long d_off;
210 unsigned short d_reclen;
211 char d_name[1];
212};
213
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000214#include "xlat/open_access_modes.h"
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000215
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000216#include "xlat/open_mode_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000217
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000218#ifndef AT_FDCWD
219# define AT_FDCWD -100
220#endif
221
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000222/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
223 * extension to get the right value. We do this by declaring fd as int here.
224 */
Dmitry V. Levin99db95d2014-02-05 04:13:18 +0000225void
Dmitry V. Levin31382132011-03-04 05:08:02 +0300226print_dirfd(struct tcb *tcp, int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000227{
228 if (fd == AT_FDCWD)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200229 tprints("AT_FDCWD, ");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200230 else {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300231 printfd(tcp, fd);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200232 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300233 }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000234}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000235
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000236/*
237 * low bits of the open(2) flags define access mode,
238 * other bits are real flags.
239 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000240const char *
241sprint_open_modes(mode_t flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000242{
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100243 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000244 char *p;
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100245 char sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000246 const char *str;
247 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000248
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100249 sep = ' ';
250 p = stpcpy(outstr, "flags");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000251 str = xlookup(open_access_modes, flags & 3);
252 if (str) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100253 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200254 p = stpcpy(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000255 flags &= ~3;
256 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000257 return outstr;
258 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000259 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000260
261 for (x = open_mode_flags; x->str; x++) {
262 if ((flags & x->val) == x->val) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100263 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200264 p = stpcpy(p, x->str);
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000265 flags &= ~x->val;
266 if (!flags)
267 return outstr;
268 sep = '|';
269 }
270 }
271 /* flags is still nonzero */
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100272 *p++ = sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000273 sprintf(p, "%#x", flags);
274 return outstr;
275}
276
277void
278tprint_open_modes(mode_t flags)
279{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200280 tprints(sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000281}
282
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000283static int
284decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000285{
286 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000287 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200288 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000289 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000290 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000291 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000292 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000293 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000294 }
295 }
296 return 0;
297}
298
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000299int
300sys_open(struct tcb *tcp)
301{
302 return decode_open(tcp, 0);
303}
304
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000305int
306sys_openat(struct tcb *tcp)
307{
308 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300309 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000310 return decode_open(tcp, 1);
311}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000312
Denys Vlasenko9472a272013-02-12 11:43:46 +0100313#if defined(SPARC) || defined(SPARC64)
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000314#include "xlat/openmodessol.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000315
316int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000317solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000318{
319 if (entering(tcp)) {
320 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200321 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000322 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000323 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000324 if (tcp->u_arg[1] & 0x100) {
325 /* mode */
326 tprintf(", %#lo", tcp->u_arg[2]);
327 }
328 }
329 return 0;
330}
331
332#endif
333
334int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000335sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000336{
337 if (entering(tcp)) {
338 printpath(tcp, tcp->u_arg[0]);
339 tprintf(", %#lo", tcp->u_arg[1]);
340 }
341 return 0;
342}
343
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000344#include "xlat/access_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000345
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000346static int
347decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000348{
349 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000350 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200351 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000352 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000353 }
354 return 0;
355}
356
357int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000358sys_access(struct tcb *tcp)
359{
360 return decode_access(tcp, 0);
361}
362
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000363int
364sys_faccessat(struct tcb *tcp)
365{
366 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300367 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000368 return decode_access(tcp, 1);
369}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000370
371int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000372sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000373{
374 if (entering(tcp)) {
375 tprintf("%#lo", tcp->u_arg[0]);
376 }
377 return RVAL_OCTAL;
378}
379
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000380#include "xlat/whence_codes.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000381
Denys Vlasenko386b8712013-02-17 01:38:14 +0100382/* Linux kernel has exactly one version of lseek:
383 * fs/read_write.c::SYSCALL_DEFINE3(lseek, unsigned, fd, off_t, offset, unsigned, origin)
384 * In kernel, off_t is always the same as (kernel's) long
385 * (see include/uapi/asm-generic/posix_types.h),
386 * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument.
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100387 * Use test/x32_lseek.c to test lseek decoding.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100388 */
H.J. Luc933f272012-04-16 17:41:13 +0200389#if defined(LINUX_MIPSN32) || defined(X32)
Roland McGrath542c2c62008-05-20 01:11:56 +0000390int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000391sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000392{
393 long long offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100394 int whence;
Roland McGrath542c2c62008-05-20 01:11:56 +0000395
396 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300397 printfd(tcp, tcp->u_arg[0]);
Roland McGrath542c2c62008-05-20 01:11:56 +0000398 offset = tcp->ext_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100399 whence = tcp->u_arg[2];
400 if (whence == SEEK_SET)
401 tprintf(", %llu, ", offset);
Roland McGrath542c2c62008-05-20 01:11:56 +0000402 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100403 tprintf(", %lld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100404 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath542c2c62008-05-20 01:11:56 +0000405 }
H.J. Ludd0130b2012-04-16 12:16:45 +0200406 return RVAL_LUDECIMAL;
Roland McGrath542c2c62008-05-20 01:11:56 +0000407}
H.J. Ludd0130b2012-04-16 12:16:45 +0200408#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000409int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000410sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000411{
Denys Vlasenko06121762013-02-17 20:08:50 +0100412 long offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100413 int whence;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000414
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000415 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300416 printfd(tcp, tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000417 offset = tcp->u_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100418 whence = tcp->u_arg[2];
419 if (whence == SEEK_SET)
420 tprintf(", %lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000421 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100422 tprintf(", %ld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100423 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000424 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000425 return RVAL_UDECIMAL;
426}
John Hughes5a826b82001-03-07 13:21:24 +0000427#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000428
Denys Vlasenko386b8712013-02-17 01:38:14 +0100429/* llseek syscall takes explicitly two ulong arguments hi, lo,
430 * rather than one 64-bit argument for which LONG_LONG works
431 * appropriate for the native byte order.
432 *
433 * See kernel's fs/read_write.c::SYSCALL_DEFINE5(llseek, ...)
434 *
435 * hi,lo are "unsigned longs" and combined exactly this way in kernel:
436 * ((loff_t) hi << 32) | lo
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100437 * Note that for architectures with kernel's long wider than userspace long
Denys Vlasenko386b8712013-02-17 01:38:14 +0100438 * (such as x32), combining code will use *kernel's*, i.e. *wide* longs
Denys Vlasenko06121762013-02-17 20:08:50 +0100439 * for hi and lo. We would need to use tcp->ext_arg[N] on x32...
440 * ...however, x32 (and x86_64) does not _have_ llseek syscall as such.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100441 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000442int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000443sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000444{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000445 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300446 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000447 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300448 tprintf(", %llu, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100449 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300450 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000451 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300452 tprintf(", %lld, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100453 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300454 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000455 }
456 else {
Denys Vlasenko386b8712013-02-17 01:38:14 +0100457 long long off;
Denys Vlasenko1d632462009-04-14 12:51:00 +0000458 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
459 tprintf("%#lx, ", tcp->u_arg[3]);
460 else
461 tprintf("[%llu], ", off);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100462 printxval(whence_codes, tcp->u_arg[4], "SEEK_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000463 }
464 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000465}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000466
467int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000468sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000469{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000470 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100471 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300472 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin7845a422014-04-17 13:32:47 +0000473 argn = printllval_aligned(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100474 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000475 }
476 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000477}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000478
479int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000480sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000481{
482 if (entering(tcp)) {
483 printpath(tcp, tcp->u_arg[0]);
484 tprintf(", %lu", tcp->u_arg[1]);
485 }
486 return 0;
487}
488
John Hughes96f51472001-03-06 16:50:41 +0000489int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000490sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000491{
492 if (entering(tcp)) {
493 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin7845a422014-04-17 13:32:47 +0000494 printllval_aligned(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000495 }
496 return 0;
497}
John Hughes96f51472001-03-06 16:50:41 +0000498
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000499int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000500sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000501{
502 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300503 printfd(tcp, tcp->u_arg[0]);
504 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000505 }
506 return 0;
507}
508
John Hughes96f51472001-03-06 16:50:41 +0000509int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000510sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000511{
512 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300513 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin7845a422014-04-17 13:32:47 +0000514 printllval_aligned(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000515 }
516 return 0;
517}
John Hughes96f51472001-03-06 16:50:41 +0000518
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000519/* several stats */
520
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000521#include "xlat/modetypes.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522
Roland McGrathf9c49b22004-10-06 22:11:54 +0000523static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000524sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525{
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100526 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
527 + sizeof(int)*3
528 + /*paranoia:*/ 8];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000529 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000530
531 if ((mode & S_IFMT) == 0)
532 s = "";
533 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
534 sprintf(buf, "%#o", mode);
535 return buf;
536 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100537 s = buf + sprintf(buf, "%s%s%s%s", s,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000538 (mode & S_ISUID) ? "|S_ISUID" : "",
539 (mode & S_ISGID) ? "|S_ISGID" : "",
540 (mode & S_ISVTX) ? "|S_ISVTX" : "");
541 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
542 if (mode)
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100543 sprintf((char*)s, "|%#o", mode);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000544 s = (*buf == '|') ? buf + 1 : buf;
545 return *s ? s : "0";
546}
547
548static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000549sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000550{
551 struct tm *tmp;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100552 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000553
554 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000555 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000556 return buf;
557 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200558 tmp = localtime(&t);
559 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000560 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
561 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
562 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
563 else
564 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
565
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000566 return buf;
567}
568
Denys Vlasenko9472a272013-02-12 11:43:46 +0100569#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000570typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000571 int tv_sec;
572 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000573} timestruct_t;
574
575struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000576 unsigned st_dev;
577 int st_pad1[3]; /* network id */
578 unsigned st_ino;
579 unsigned st_mode;
580 unsigned st_nlink;
581 unsigned st_uid;
582 unsigned st_gid;
583 unsigned st_rdev;
584 int st_pad2[2];
585 int st_size;
586 int st_pad3; /* st_size, off_t expansion */
587 timestruct_t st_atime;
588 timestruct_t st_mtime;
589 timestruct_t st_ctime;
590 int st_blksize;
591 int st_blocks;
592 char st_fstype[16];
593 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000594};
595
596static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000597printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000598{
599 struct solstat statbuf;
600
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000601 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200602 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000603 return;
604 }
605 if (!abbrev(tcp)) {
606 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
607 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
608 (unsigned long) (statbuf.st_dev & 0x3ffff),
609 (unsigned long) statbuf.st_ino,
610 sprintmode(statbuf.st_mode));
611 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
612 (unsigned long) statbuf.st_nlink,
613 (unsigned long) statbuf.st_uid,
614 (unsigned long) statbuf.st_gid);
615 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
616 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
617 }
618 else
619 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
620 switch (statbuf.st_mode & S_IFMT) {
621 case S_IFCHR: case S_IFBLK:
622 tprintf("st_rdev=makedev(%lu, %lu), ",
623 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
624 (unsigned long) (statbuf.st_rdev & 0x3ffff));
625 break;
626 default:
627 tprintf("st_size=%u, ", statbuf.st_size);
628 break;
629 }
630 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000631 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
632 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
633 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000634 }
635 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200636 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000637}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000638
Denys Vlasenko9472a272013-02-12 11:43:46 +0100639# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000640static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000641printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000642{
643 struct stat_sparc64 statbuf;
644
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000645 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200646 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000647 return;
648 }
649
650 if (!abbrev(tcp)) {
651 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
652 (unsigned long) major(statbuf.st_dev),
653 (unsigned long) minor(statbuf.st_dev),
654 (unsigned long) statbuf.st_ino,
655 sprintmode(statbuf.st_mode));
656 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
657 (unsigned long) statbuf.st_nlink,
658 (unsigned long) statbuf.st_uid,
659 (unsigned long) statbuf.st_gid);
660 tprintf("st_blksize=%lu, ",
661 (unsigned long) statbuf.st_blksize);
662 tprintf("st_blocks=%lu, ",
663 (unsigned long) statbuf.st_blocks);
664 }
665 else
666 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
667 switch (statbuf.st_mode & S_IFMT) {
668 case S_IFCHR: case S_IFBLK:
669 tprintf("st_rdev=makedev(%lu, %lu), ",
670 (unsigned long) major(statbuf.st_rdev),
671 (unsigned long) minor(statbuf.st_rdev));
672 break;
673 default:
674 tprintf("st_size=%lu, ", statbuf.st_size);
675 break;
676 }
677 if (!abbrev(tcp)) {
678 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
679 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100680 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000681 }
682 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200683 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000684}
Denys Vlasenko9472a272013-02-12 11:43:46 +0100685# endif /* SPARC64 */
686#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000687
Denys Vlasenko84703742012-02-25 02:38:52 +0100688#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200689struct stat_powerpc32 {
690 unsigned int st_dev;
691 unsigned int st_ino;
692 unsigned int st_mode;
693 unsigned short st_nlink;
694 unsigned int st_uid;
695 unsigned int st_gid;
696 unsigned int st_rdev;
697 unsigned int st_size;
698 unsigned int st_blksize;
699 unsigned int st_blocks;
700 unsigned int st_atime;
701 unsigned int st_atime_nsec;
702 unsigned int st_mtime;
703 unsigned int st_mtime_nsec;
704 unsigned int st_ctime;
705 unsigned int st_ctime_nsec;
706 unsigned int __unused4;
707 unsigned int __unused5;
708};
709
710static void
711printstat_powerpc32(struct tcb *tcp, long addr)
712{
713 struct stat_powerpc32 statbuf;
714
715 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200716 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200717 return;
718 }
719
720 if (!abbrev(tcp)) {
721 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
722 major(statbuf.st_dev), minor(statbuf.st_dev),
723 statbuf.st_ino,
724 sprintmode(statbuf.st_mode));
725 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
726 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
727 tprintf("st_blksize=%u, ", statbuf.st_blksize);
728 tprintf("st_blocks=%u, ", statbuf.st_blocks);
729 }
730 else
731 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
732 switch (statbuf.st_mode & S_IFMT) {
733 case S_IFCHR: case S_IFBLK:
734 tprintf("st_rdev=makedev(%lu, %lu), ",
735 (unsigned long) major(statbuf.st_rdev),
736 (unsigned long) minor(statbuf.st_rdev));
737 break;
738 default:
739 tprintf("st_size=%u, ", statbuf.st_size);
740 break;
741 }
742 if (!abbrev(tcp)) {
743 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
744 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100745 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200746 }
747 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200748 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200749}
Denys Vlasenko84703742012-02-25 02:38:52 +0100750#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200751
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000752#include "xlat/fileflags.h"
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000753
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000754static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000755realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000756{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000757 if (!abbrev(tcp)) {
758 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
759 (unsigned long) major(statbuf->st_dev),
760 (unsigned long) minor(statbuf->st_dev),
761 (unsigned long) statbuf->st_ino,
762 sprintmode(statbuf->st_mode));
763 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
764 (unsigned long) statbuf->st_nlink,
765 (unsigned long) statbuf->st_uid,
766 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000767#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000768 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
769#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000770#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000771 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
772#endif
773 }
774 else
775 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
776 switch (statbuf->st_mode & S_IFMT) {
777 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000778#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000779 tprintf("st_rdev=makedev(%lu, %lu), ",
780 (unsigned long) major(statbuf->st_rdev),
781 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000782#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000783 tprintf("st_size=makedev(%lu, %lu), ",
784 (unsigned long) major(statbuf->st_size),
785 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000786#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000787 break;
788 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000789 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000790 break;
791 }
792 if (!abbrev(tcp)) {
793 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
794 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
795 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000796#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200797 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000798 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000799#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000800#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000801 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
802#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000803#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000804 tprintf(", st_level=%ld", statbuf->st_level);
805#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000806#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000807 tprintf(", st_fstype=%.*s",
808 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
809#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000810#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000811 tprintf(", st_gen=%u", statbuf->st_gen);
812#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200813 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000814 }
815 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200816 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000817}
818
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000819#ifndef X32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000820static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000821printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000822{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000823 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000824
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000825 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200826 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000827 return;
828 }
829 if (syserror(tcp) || !verbose(tcp)) {
830 tprintf("%#lx", addr);
831 return;
832 }
833
Denys Vlasenko9472a272013-02-12 11:43:46 +0100834#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000835 if (current_personality == 1) {
836 printstatsol(tcp, addr);
837 return;
838 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000839#ifdef SPARC64
840 else if (current_personality == 2) {
841 printstat_sparc64(tcp, addr);
842 return;
843 }
844#endif
Denys Vlasenko9472a272013-02-12 11:43:46 +0100845#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000846
Denys Vlasenko84703742012-02-25 02:38:52 +0100847#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200848 if (current_personality == 1) {
849 printstat_powerpc32(tcp, addr);
850 return;
851 }
852#endif
853
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000854 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200855 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000856 return;
857 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000858
859 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000860}
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000861#else /* X32 */
862# define printstat printstat64
863#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000864
Elliott Hughes391c0d82014-04-03 17:50:14 -0700865#if !defined HAVE_STAT64 && (defined AARCH64 || defined X86_64)
Roland McGrathe6d0f712007-08-07 01:22:49 +0000866/*
867 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
868 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
869 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
870 * __GNUC__ is needed for the required __attribute__ below.
Elliott Hughes391c0d82014-04-03 17:50:14 -0700871 *
872 * Similarly, aarch64 has a unified `struct stat' but its arm personality
873 * needs `struct stat64' (which also expects a 32-bit `long' but which
874 * shouldn't be packed).
Roland McGrathe6d0f712007-08-07 01:22:49 +0000875 */
876struct stat64 {
877 unsigned long long st_dev;
878 unsigned char __pad0[4];
879 unsigned int __st_ino;
880 unsigned int st_mode;
881 unsigned int st_nlink;
882 unsigned int st_uid;
883 unsigned int st_gid;
884 unsigned long long st_rdev;
885 unsigned char __pad3[4];
886 long long st_size;
887 unsigned int st_blksize;
888 unsigned long long st_blocks;
889 unsigned int st_atime;
890 unsigned int st_atime_nsec;
891 unsigned int st_mtime;
892 unsigned int st_mtime_nsec;
893 unsigned int st_ctime;
894 unsigned int st_ctime_nsec;
895 unsigned long long st_ino;
Elliott Hughes391c0d82014-04-03 17:50:14 -0700896}
897# if defined X86_64
898 __attribute__((packed))
899# define STAT64_SIZE 96
900#else
901# define STAT64_SIZE 104
902# endif
903;
Roland McGrathe6d0f712007-08-07 01:22:49 +0000904# define HAVE_STAT64 1
Roland McGrathe6d0f712007-08-07 01:22:49 +0000905#endif
906
Wichert Akkermanc7926982000-04-10 22:22:31 +0000907#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000908static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000909printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000910{
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000911#ifdef X32
912 struct stat statbuf;
913#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000914 struct stat64 statbuf;
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000915#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000916
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000917#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +0000918 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
919#endif
920
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000921 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200922 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000923 return;
924 }
925 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000926 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000927 return;
928 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000929
Denys Vlasenko9472a272013-02-12 11:43:46 +0100930#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000931 if (current_personality == 1) {
932 printstatsol(tcp, addr);
933 return;
934 }
935# ifdef SPARC64
936 else if (current_personality == 2) {
937 printstat_sparc64(tcp, addr);
938 return;
939 }
940# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +0100941#endif /* SPARC[64] */
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000942
Elliott Hughes391c0d82014-04-03 17:50:14 -0700943#if defined AARCH64
944 if (current_personality != 0) {
945 printstat(tcp, addr);
946 return;
947 }
948#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100949#if defined X86_64
H.J. Lu35be5812012-04-16 13:00:01 +0200950 if (current_personality != 1) {
Andreas Schwab61b74352009-10-16 11:37:13 +0200951 printstat(tcp, addr);
952 return;
953 }
954#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +0000955
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000956 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200957 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000958 return;
959 }
960
961 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +0000962 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000963 (unsigned long) major(statbuf.st_dev),
964 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +0000965 (unsigned long long) statbuf.st_ino,
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000966 sprintmode(statbuf.st_mode));
967 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
968 (unsigned long) statbuf.st_nlink,
969 (unsigned long) statbuf.st_uid,
970 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000971#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000972 tprintf("st_blksize=%lu, ",
973 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000974#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
975#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000976 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000977#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000978 }
979 else
980 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
981 switch (statbuf.st_mode & S_IFMT) {
982 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000983#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000984 tprintf("st_rdev=makedev(%lu, %lu), ",
985 (unsigned long) major(statbuf.st_rdev),
986 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000987#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000988 tprintf("st_size=makedev(%lu, %lu), ",
989 (unsigned long) major(statbuf.st_size),
990 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000991#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000992 break;
993 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +0000994 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000995 break;
996 }
997 if (!abbrev(tcp)) {
998 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
999 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001000 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001001#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001002 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001003 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001004#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001005#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001006 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1007#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001008#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001009 tprintf(", st_level=%ld", statbuf.st_level);
1010#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001011#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001012 tprintf(", st_fstype=%.*s",
1013 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1014#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001015#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001016 tprintf(", st_gen=%u", statbuf.st_gen);
1017#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001018 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001019 }
1020 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001021 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001022}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001023#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001024
Denys Vlasenko8435d672013-02-18 15:47:57 +01001025#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001026static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001027convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001028{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001029 newbuf->st_dev = oldbuf->st_dev;
1030 newbuf->st_ino = oldbuf->st_ino;
1031 newbuf->st_mode = oldbuf->st_mode;
1032 newbuf->st_nlink = oldbuf->st_nlink;
1033 newbuf->st_uid = oldbuf->st_uid;
1034 newbuf->st_gid = oldbuf->st_gid;
1035 newbuf->st_rdev = oldbuf->st_rdev;
1036 newbuf->st_size = oldbuf->st_size;
1037 newbuf->st_atime = oldbuf->st_atime;
1038 newbuf->st_mtime = oldbuf->st_mtime;
1039 newbuf->st_ctime = oldbuf->st_ctime;
1040 newbuf->st_blksize = 0; /* not supported in old_stat */
1041 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001042}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001043
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001044static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001045printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001046{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001047 struct __old_kernel_stat statbuf;
1048 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001049
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001050 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001051 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001052 return;
1053 }
1054 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001055 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001056 return;
1057 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001058
Denys Vlasenko9472a272013-02-12 11:43:46 +01001059# if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001060 if (current_personality == 1) {
1061 printstatsol(tcp, addr);
1062 return;
1063 }
Denys Vlasenko84703742012-02-25 02:38:52 +01001064# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001065
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001066 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001067 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001068 return;
1069 }
1070
1071 convertoldstat(&statbuf, &newstatbuf);
1072 realprintstat(tcp, &newstatbuf);
1073}
Denys Vlasenko84703742012-02-25 02:38:52 +01001074#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001075
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001076int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001077sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001078{
1079 if (entering(tcp)) {
1080 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001081 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001082 } else {
1083 printstat(tcp, tcp->u_arg[1]);
1084 }
1085 return 0;
1086}
1087
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001088#ifdef X32
1089static void
1090printstat64_x32(struct tcb *tcp, long addr)
1091{
1092 struct stat64 statbuf;
1093
1094 if (!addr) {
1095 tprints("NULL");
1096 return;
1097 }
1098 if (syserror(tcp) || !verbose(tcp)) {
1099 tprintf("%#lx", addr);
1100 return;
1101 }
1102
1103 if (umove(tcp, addr, &statbuf) < 0) {
1104 tprints("{...}");
1105 return;
1106 }
1107
1108 if (!abbrev(tcp)) {
1109 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1110 (unsigned long) major(statbuf.st_dev),
1111 (unsigned long) minor(statbuf.st_dev),
1112 (unsigned long long) statbuf.st_ino,
1113 sprintmode(statbuf.st_mode));
1114 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1115 (unsigned long) statbuf.st_nlink,
1116 (unsigned long) statbuf.st_uid,
1117 (unsigned long) statbuf.st_gid);
1118 tprintf("st_blksize=%lu, ",
1119 (unsigned long) statbuf.st_blksize);
1120 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1121 }
1122 else
1123 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1124 switch (statbuf.st_mode & S_IFMT) {
1125 case S_IFCHR: case S_IFBLK:
1126 tprintf("st_rdev=makedev(%lu, %lu), ",
1127 (unsigned long) major(statbuf.st_rdev),
1128 (unsigned long) minor(statbuf.st_rdev));
1129 break;
1130 default:
1131 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1132 break;
1133 }
1134 if (!abbrev(tcp)) {
1135 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1136 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1137 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1138 tprints("}");
1139 }
1140 else
1141 tprints("...}");
1142}
1143#endif /* X32 */
1144
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001145int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001146sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001147{
1148#ifdef HAVE_STAT64
1149 if (entering(tcp)) {
1150 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001151 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001152 } else {
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001153# ifdef X32
1154 printstat64_x32(tcp, tcp->u_arg[1]);
1155# else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001156 printstat64(tcp, tcp->u_arg[1]);
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001157# endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001158 }
1159 return 0;
1160#else
1161 return printargs(tcp);
1162#endif
1163}
1164
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001165#ifndef AT_SYMLINK_NOFOLLOW
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001166# define AT_SYMLINK_NOFOLLOW 0x100
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001167#endif
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001168#ifndef AT_REMOVEDIR
1169# define AT_REMOVEDIR 0x200
1170#endif
1171#ifndef AT_SYMLINK_FOLLOW
1172# define AT_SYMLINK_FOLLOW 0x400
1173#endif
1174#ifndef AT_NO_AUTOMOUNT
1175# define AT_NO_AUTOMOUNT 0x800
1176#endif
1177#ifndef AT_EMPTY_PATH
1178# define AT_EMPTY_PATH 0x1000
1179#endif
1180
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001181#include "xlat/at_flags.h"
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001182
1183int
1184sys_newfstatat(struct tcb *tcp)
1185{
1186 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001187 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001188 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001189 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001190 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001191#ifdef POWERPC64
1192 if (current_personality == 0)
1193 printstat(tcp, tcp->u_arg[2]);
1194 else
1195 printstat64(tcp, tcp->u_arg[2]);
1196#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001197 printstat64(tcp, tcp->u_arg[2]);
1198#else
1199 printstat(tcp, tcp->u_arg[2]);
1200#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001201 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001202 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001203 }
1204 return 0;
1205}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001206
Denys Vlasenko8435d672013-02-18 15:47:57 +01001207#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001208int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001209sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001210{
1211 if (entering(tcp)) {
1212 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001213 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001214 } else {
1215 printoldstat(tcp, tcp->u_arg[1]);
1216 }
1217 return 0;
1218}
Denys Vlasenko84703742012-02-25 02:38:52 +01001219#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001220
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001221int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001222sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001223{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001224 if (entering(tcp)) {
1225 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001226 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001227 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001228 printstat(tcp, tcp->u_arg[1]);
1229 }
1230 return 0;
1231}
1232
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001233int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001234sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001235{
1236#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001237 if (entering(tcp)) {
1238 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001239 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001240 } else {
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001241# ifdef X32
1242 printstat64_x32(tcp, tcp->u_arg[1]);
1243# else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001244 printstat64(tcp, tcp->u_arg[1]);
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001245# endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001246 }
1247 return 0;
1248#else
1249 return printargs(tcp);
1250#endif
1251}
1252
Denys Vlasenko8435d672013-02-18 15:47:57 +01001253#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001254int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001255sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001256{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001257 if (entering(tcp)) {
1258 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001259 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001260 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001261 printoldstat(tcp, tcp->u_arg[1]);
1262 }
1263 return 0;
1264}
Denys Vlasenko84703742012-02-25 02:38:52 +01001265#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001266
Denys Vlasenko9472a272013-02-12 11:43:46 +01001267#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001268
1269int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001270sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001271{
1272 if (entering(tcp)) {
1273 tprintf("%ld, ", tcp->u_arg[0]);
1274 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001275 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001276 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001277# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001278 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001279 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001280 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001281# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001282 printstat(tcp, tcp->u_arg[2]);
1283 }
1284 return 0;
1285}
1286
1287int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001288sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001289{
1290 if (entering(tcp))
1291 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1292 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001293# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001294 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001295 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001296 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001297# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001298 printstat(tcp, tcp->u_arg[2]);
1299 }
1300 return 0;
1301}
1302
1303int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001304sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001305{
1306 if (entering(tcp)) {
1307 tprintf("%ld, ", tcp->u_arg[0]);
1308 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001309 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001310 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001311# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001312 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001313 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001314 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001315# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001316 printstat(tcp, tcp->u_arg[2]);
1317 }
1318 return 0;
1319}
1320
1321int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001322sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001323{
1324 int mode = tcp->u_arg[2];
1325
1326 if (entering(tcp)) {
1327 tprintf("%ld, ", tcp->u_arg[0]);
1328 printpath(tcp, tcp->u_arg[1]);
1329 tprintf(", %s", sprintmode(mode));
1330 switch (mode & S_IFMT) {
1331 case S_IFCHR: case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001332 tprintf(", makedev(%lu, %lu)",
1333 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1334 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001335 break;
1336 default:
1337 break;
1338 }
1339 }
1340 return 0;
1341}
1342
Denys Vlasenko84703742012-02-25 02:38:52 +01001343# ifdef HAVE_SYS_ACL_H
Wichert Akkerman8829a551999-06-11 13:18:40 +00001344
Denys Vlasenko84703742012-02-25 02:38:52 +01001345# include <sys/acl.h>
Wichert Akkerman8829a551999-06-11 13:18:40 +00001346
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001347#include "xlat/aclcmds.h"
Wichert Akkerman8829a551999-06-11 13:18:40 +00001348
1349int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001350sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001351{
1352 if (entering(tcp)) {
1353 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001354 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001355 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1356 tprintf(", %ld", tcp->u_arg[2]);
1357 /*
1358 * FIXME - dump out the list of aclent_t's pointed to
1359 * by "tcp->u_arg[3]" if it's not NULL.
1360 */
1361 if (tcp->u_arg[3])
1362 tprintf(", %#lx", tcp->u_arg[3]);
1363 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001364 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001365 }
1366 return 0;
1367}
1368
Wichert Akkerman8829a551999-06-11 13:18:40 +00001369int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001370sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001371{
1372 if (entering(tcp)) {
1373 tprintf("%ld, ", tcp->u_arg[0]);
1374 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1375 tprintf(", %ld", tcp->u_arg[2]);
1376 /*
1377 * FIXME - dump out the list of aclent_t's pointed to
1378 * by "tcp->u_arg[3]" if it's not NULL.
1379 */
1380 if (tcp->u_arg[3])
1381 tprintf(", %#lx", tcp->u_arg[3]);
1382 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001383 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001384 }
1385 return 0;
1386}
1387
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001388#include "xlat/aclipc.h"
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001389
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001390int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001391sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001392{
1393 if (entering(tcp)) {
1394 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1395 tprintf(", %#lx, ", tcp->u_arg[1]);
1396 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1397 tprintf(", %ld", tcp->u_arg[3]);
1398 /*
1399 * FIXME - dump out the list of aclent_t's pointed to
1400 * by "tcp->u_arg[4]" if it's not NULL.
1401 */
1402 if (tcp->u_arg[4])
1403 tprintf(", %#lx", tcp->u_arg[4]);
1404 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001405 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001406 }
1407 return 0;
1408}
1409
Denys Vlasenko84703742012-02-25 02:38:52 +01001410# endif /* HAVE_SYS_ACL_H */
Wichert Akkerman8829a551999-06-11 13:18:40 +00001411
Denys Vlasenko9472a272013-02-12 11:43:46 +01001412#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00001414#include "xlat/fsmagic.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001415
Roland McGrathf9c49b22004-10-06 22:11:54 +00001416static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001417sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001418{
1419 static char buf[32];
Roland McGrathf9c49b22004-10-06 22:11:54 +00001420 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001421
1422 s = xlookup(fsmagic, magic);
1423 if (s) {
1424 sprintf(buf, "\"%s\"", s);
1425 return buf;
1426 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001427 sprintf(buf, "%#x", magic);
1428 return buf;
1429}
1430
1431static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001432printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001433{
1434 struct statfs statbuf;
1435
1436 if (syserror(tcp) || !verbose(tcp)) {
1437 tprintf("%#lx", addr);
1438 return;
1439 }
1440 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001441 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001442 return;
1443 }
1444#ifdef ALPHA
1445
1446 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1447 sprintfstype(statbuf.f_type),
1448 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001449 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001450 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001451 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1452 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001453#else /* !ALPHA */
1454 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1455 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001456 (unsigned long)statbuf.f_bsize,
1457 (unsigned long)statbuf.f_blocks,
1458 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001459 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1460 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001461 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001462 (unsigned long)statbuf.f_ffree,
1463 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001464 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001465#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001466#ifdef _STATFS_F_FRSIZE
1467 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1468#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001469 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001470}
1471
1472int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001473sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001474{
1475 if (entering(tcp)) {
1476 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001477 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001478 } else {
1479 printstatfs(tcp, tcp->u_arg[1]);
1480 }
1481 return 0;
1482}
1483
1484int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001485sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001486{
1487 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001488 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001489 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001490 } else {
1491 printstatfs(tcp, tcp->u_arg[1]);
1492 }
1493 return 0;
1494}
1495
Denys Vlasenko84703742012-02-25 02:38:52 +01001496#if defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001497static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001498printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001499{
1500 struct statfs64 statbuf;
1501
1502 if (syserror(tcp) || !verbose(tcp)) {
1503 tprintf("%#lx", addr);
1504 return;
1505 }
1506 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001507 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001508 return;
1509 }
Roland McGrath08738432005-06-03 02:40:39 +00001510 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001511 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001512 (unsigned long long)statbuf.f_bsize,
1513 (unsigned long long)statbuf.f_blocks,
1514 (unsigned long long)statbuf.f_bfree);
1515 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1516 (unsigned long long)statbuf.f_bavail,
1517 (unsigned long long)statbuf.f_files,
1518 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001519 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1520 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001521#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001522 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001523#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001524#ifdef _STATFS_F_FLAGS
1525 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1526#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001527 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001528}
1529
Andreas Schwab7d558012012-01-17 18:14:22 +01001530struct compat_statfs64 {
1531 uint32_t f_type;
1532 uint32_t f_bsize;
1533 uint64_t f_blocks;
1534 uint64_t f_bfree;
1535 uint64_t f_bavail;
1536 uint64_t f_files;
1537 uint64_t f_ffree;
1538 fsid_t f_fsid;
1539 uint32_t f_namelen;
1540 uint32_t f_frsize;
1541 uint32_t f_flags;
1542 uint32_t f_spare[4];
1543}
1544#if defined(X86_64) || defined(IA64)
1545 __attribute__ ((packed, aligned(4)))
1546#endif
1547;
1548
1549static void
1550printcompat_statfs64(struct tcb *tcp, long addr)
1551{
1552 struct compat_statfs64 statbuf;
1553
1554 if (syserror(tcp) || !verbose(tcp)) {
1555 tprintf("%#lx", addr);
1556 return;
1557 }
1558 if (umove(tcp, addr, &statbuf) < 0) {
1559 tprints("{...}");
1560 return;
1561 }
1562 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1563 sprintfstype(statbuf.f_type),
1564 (unsigned long)statbuf.f_bsize,
1565 (unsigned long long)statbuf.f_blocks,
1566 (unsigned long long)statbuf.f_bfree);
1567 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1568 (unsigned long long)statbuf.f_bavail,
1569 (unsigned long long)statbuf.f_files,
1570 (unsigned long long)statbuf.f_ffree,
1571 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1572 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1573 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001574 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
Andreas Schwab7d558012012-01-17 18:14:22 +01001575}
1576
Roland McGrathab147c52003-07-17 09:03:02 +00001577int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001578sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001579{
1580 if (entering(tcp)) {
1581 printpath(tcp, tcp->u_arg[0]);
1582 tprintf(", %lu, ", tcp->u_arg[1]);
1583 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001584 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001585 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001586 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1587 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001588 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001589 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001590 }
1591 return 0;
1592}
1593
1594int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001595sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001596{
1597 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001598 printfd(tcp, tcp->u_arg[0]);
1599 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001600 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001601 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001602 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001603 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1604 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001605 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001606 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001607 }
1608 return 0;
1609}
1610#endif
1611
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001612#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001613int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001614osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001615{
1616 if (entering(tcp)) {
1617 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001618 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001619 } else {
1620 printstatfs(tcp, tcp->u_arg[1]);
1621 tprintf(", %lu", tcp->u_arg[2]);
1622 }
1623 return 0;
1624}
1625
1626int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001627osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001628{
1629 if (entering(tcp)) {
1630 tprintf("%lu, ", tcp->u_arg[0]);
1631 } else {
1632 printstatfs(tcp, tcp->u_arg[1]);
1633 tprintf(", %lu", tcp->u_arg[2]);
1634 }
1635 return 0;
1636}
Denys Vlasenko84703742012-02-25 02:38:52 +01001637#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001638
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001639/* directory */
1640int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001641sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001642{
1643 if (entering(tcp)) {
1644 printpath(tcp, tcp->u_arg[0]);
1645 }
1646 return 0;
1647}
1648
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001649static int
1650decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001651{
1652 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001653 printpath(tcp, tcp->u_arg[offset]);
1654 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001655 }
1656 return 0;
1657}
1658
1659int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001660sys_mkdir(struct tcb *tcp)
1661{
1662 return decode_mkdir(tcp, 0);
1663}
1664
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001665int
1666sys_mkdirat(struct tcb *tcp)
1667{
1668 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001669 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001670 return decode_mkdir(tcp, 1);
1671}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001672
1673int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001674sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001675{
1676 if (entering(tcp)) {
1677 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001678 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001679 printpath(tcp, tcp->u_arg[1]);
1680 }
1681 return 0;
1682}
1683
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001684int
1685sys_linkat(struct tcb *tcp)
1686{
1687 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001688 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001689 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001690 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001691 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001692 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001693 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001694 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001695 }
1696 return 0;
1697}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001698
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001699int
1700sys_unlinkat(struct tcb *tcp)
1701{
1702 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001703 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001704 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001705 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001706 printflags(at_flags, tcp->u_arg[2], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001707 }
1708 return 0;
1709}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001710
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001711int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001712sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001713{
1714 if (entering(tcp)) {
1715 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001716 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001717 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001718 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001719 }
1720 return 0;
1721}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001722
1723static int
1724decode_readlink(struct tcb *tcp, int offset)
1725{
1726 if (entering(tcp)) {
1727 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001728 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001729 } else {
1730 if (syserror(tcp))
1731 tprintf("%#lx", tcp->u_arg[offset + 1]);
1732 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001733 /* Used to use printpathn(), but readlink
1734 * neither includes NUL in the returned count,
1735 * nor actually writes it into memory.
1736 * printpathn() would decide on printing
1737 * "..." continuation based on garbage
1738 * past return buffer's end.
1739 */
1740 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001741 tprintf(", %lu", tcp->u_arg[offset + 2]);
1742 }
1743 return 0;
1744}
1745
1746int
1747sys_readlink(struct tcb *tcp)
1748{
1749 return decode_readlink(tcp, 0);
1750}
1751
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001752int
1753sys_readlinkat(struct tcb *tcp)
1754{
1755 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001756 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001757 return decode_readlink(tcp, 1);
1758}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001759
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001760int
1761sys_renameat(struct tcb *tcp)
1762{
1763 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001764 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001765 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001766 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001767 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001768 printpath(tcp, tcp->u_arg[3]);
1769 }
1770 return 0;
1771}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001772
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001773int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001774sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001775{
1776 if (entering(tcp)) {
1777 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001778 printuid(", ", tcp->u_arg[1]);
1779 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001780 }
1781 return 0;
1782}
1783
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001784int
1785sys_fchownat(struct tcb *tcp)
1786{
1787 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001788 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001789 printpath(tcp, tcp->u_arg[1]);
1790 printuid(", ", tcp->u_arg[2]);
1791 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001792 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001793 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001794 }
1795 return 0;
1796}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001797
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001798int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001799sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001800{
1801 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001802 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001803 printuid(", ", tcp->u_arg[1]);
1804 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001805 }
1806 return 0;
1807}
1808
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001809static int
1810decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001811{
1812 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001813 printpath(tcp, tcp->u_arg[offset]);
1814 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001815 }
1816 return 0;
1817}
1818
1819int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001820sys_chmod(struct tcb *tcp)
1821{
1822 return decode_chmod(tcp, 0);
1823}
1824
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001825int
1826sys_fchmodat(struct tcb *tcp)
1827{
1828 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001829 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001830 return decode_chmod(tcp, 1);
1831}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001832
1833int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001834sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001835{
1836 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001837 printfd(tcp, tcp->u_arg[0]);
1838 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001839 }
1840 return 0;
1841}
1842
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001843#ifdef ALPHA
1844int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001845sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001846{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001847 if (entering(tcp)) {
1848 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001849 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00001850 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
1851 }
1852 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001853}
1854#endif
1855
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001856static int
Roland McGrath6afc5652007-07-24 01:57:11 +00001857decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001858{
1859 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001860 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001861 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00001862 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001863 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00001864 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001865 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00001866 printtv_bitness(tcp, tcp->u_arg[offset + 1],
1867 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001868 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00001869 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001870 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00001871 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001872 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00001873 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001874 }
1875 return 0;
1876}
1877
1878int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001879sys_utimes(struct tcb *tcp)
1880{
Roland McGrath6afc5652007-07-24 01:57:11 +00001881 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001882}
1883
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001884int
1885sys_futimesat(struct tcb *tcp)
1886{
1887 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001888 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00001889 return decode_utimes(tcp, 1, 0);
1890}
1891
1892int
1893sys_utimensat(struct tcb *tcp)
1894{
1895 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001896 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00001897 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001898 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001899 printflags(at_flags, tcp->u_arg[3], "AT_???");
Roland McGrath6afc5652007-07-24 01:57:11 +00001900 }
1901 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001902}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001903
1904int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001905sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001906{
Roland McGrath7e9817c2007-07-05 20:31:58 +00001907 union {
1908 long utl[2];
1909 int uti[2];
Denys Vlasenko751acb32013-02-08 15:34:46 +01001910 long paranoia_for_huge_wordsize[4];
Roland McGrath7e9817c2007-07-05 20:31:58 +00001911 } u;
Denys Vlasenko751acb32013-02-08 15:34:46 +01001912 unsigned wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001913
1914 if (entering(tcp)) {
1915 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001916 tprints(", ");
Denys Vlasenko751acb32013-02-08 15:34:46 +01001917
1918 wordsize = current_wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001919 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001920 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001921 else if (!verbose(tcp))
1922 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001923 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001924 tprints("[?, ?]");
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001925 else if (wordsize == sizeof u.utl[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00001926 tprintf("[%s,", sprinttime(u.utl[0]));
1927 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001928 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001929 else if (wordsize == sizeof u.uti[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00001930 tprintf("[%s,", sprinttime(u.uti[0]));
1931 tprintf(" %s]", sprinttime(u.uti[1]));
1932 }
1933 else
Denys Vlasenko751acb32013-02-08 15:34:46 +01001934 tprintf("<decode error: unsupported wordsize %d>",
1935 wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001936 }
1937 return 0;
1938}
1939
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001940static int
1941decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001942{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001943 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001944
1945 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001946 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001947 tprintf(", %s", sprintmode(mode));
1948 switch (mode & S_IFMT) {
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001949 case S_IFCHR:
1950 case S_IFBLK:
Denys Vlasenko9472a272013-02-12 11:43:46 +01001951#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001952 if (current_personality == 1)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001953 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001954 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
1955 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001956 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00001957#endif
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001958 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001959 (unsigned long) major(tcp->u_arg[offset + 2]),
1960 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001961 break;
1962 default:
1963 break;
1964 }
1965 }
1966 return 0;
1967}
1968
1969int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001970sys_mknod(struct tcb *tcp)
1971{
1972 return decode_mknod(tcp, 0);
1973}
1974
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001975int
1976sys_mknodat(struct tcb *tcp)
1977{
1978 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001979 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001980 return decode_mknod(tcp, 1);
1981}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001982
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001983static void
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00001984print_old_dirent(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001985{
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00001986#ifdef SH64
1987 typedef struct kernel_dirent old_dirent_t;
1988#else
1989 typedef struct {
1990 uint32_t d_ino;
1991 uint32_t d_off;
1992 unsigned short d_reclen;
1993 char d_name[1];
1994 } old_dirent_t;
1995#endif
1996 old_dirent_t d;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001997
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00001998 if (!verbose(tcp) || umove(tcp, addr, &d) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001999 tprintf("%#lx", addr);
2000 return;
2001 }
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002002
2003 tprintf("{d_ino=%lu, d_off=%lu, d_reclen=%u, d_name=\"",
2004 (unsigned long) d.d_ino, (unsigned long) d.d_off, d.d_reclen);
2005 if (d.d_reclen > 256)
2006 d.d_reclen = 256;
2007 printpathn(tcp, addr + offsetof(old_dirent_t, d_name), d.d_reclen);
2008 tprints("\"}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002009}
2010
2011int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002012sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002013{
2014 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002015 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002016 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002017 } else {
2018 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2019 tprintf("%#lx", tcp->u_arg[1]);
2020 else
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002021 print_old_dirent(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002022 /* Not much point in printing this out, it is always 1. */
2023 if (tcp->u_arg[2] != 1)
2024 tprintf(", %lu", tcp->u_arg[2]);
2025 }
2026 return 0;
2027}
2028
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00002029#include "xlat/direnttypes.h"
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002030
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002031int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002032sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002033{
2034 int i, len, dents = 0;
2035 char *buf;
2036
2037 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002038 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002039 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002040 return 0;
2041 }
2042 if (syserror(tcp) || !verbose(tcp)) {
2043 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2044 return 0;
2045 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002046 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002047 /* Beware of insanely large or negative values in tcp->u_rval */
2048 if (tcp->u_rval > 1024*1024)
2049 len = 1024*1024;
2050 if (tcp->u_rval < 0)
2051 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002052 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002053 if (len && !buf)
2054 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002055 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002056 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002057 free(buf);
2058 return 0;
2059 }
2060 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002061 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002062 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002063 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002064 if (!abbrev(tcp)) {
2065 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2066 i ? " " : "", d->d_ino, d->d_off);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002067 tprintf("d_reclen=%u, d_name=\"%s\", d_type=",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002068 d->d_reclen, d->d_name);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002069 printxval(direnttypes, buf[i + d->d_reclen - 1], "DT_???");
2070 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002071 }
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002072 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002073 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002074 break;
2075 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002076 i += d->d_reclen;
2077 dents++;
2078 }
2079 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002080 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002081 else
2082 tprintf("/* %u entries */", dents);
2083 tprintf(", %lu", tcp->u_arg[2]);
2084 free(buf);
2085 return 0;
2086}
2087
John Hughesbdf48f52001-03-06 15:08:09 +00002088int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002089sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002090{
2091 int i, len, dents = 0;
2092 char *buf;
2093
2094 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002095 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002096 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002097 return 0;
2098 }
2099 if (syserror(tcp) || !verbose(tcp)) {
2100 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2101 return 0;
2102 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002103
John Hughesbdf48f52001-03-06 15:08:09 +00002104 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002105 /* Beware of insanely large or negative tcp->u_rval */
2106 if (tcp->u_rval > 1024*1024)
2107 len = 1024*1024;
2108 if (tcp->u_rval < 0)
2109 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002110 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002111 if (len && !buf)
2112 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002113
John Hughesbdf48f52001-03-06 15:08:09 +00002114 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002115 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002116 free(buf);
2117 return 0;
2118 }
2119 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002120 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002121 for (i = 0; i < len;) {
2122 struct dirent64 *d = (struct dirent64 *) &buf[i];
John Hughesbdf48f52001-03-06 15:08:09 +00002123 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002124 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002125 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002126 d->d_ino,
2127 d->d_off);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002128 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002129 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002130 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002131 tprintf("d_reclen=%u, d_name=\"%s\"}",
2132 d->d_reclen, d->d_name);
2133 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002134 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002135 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002136 break;
2137 }
John Hughesbdf48f52001-03-06 15:08:09 +00002138 i += d->d_reclen;
2139 dents++;
2140 }
2141 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002142 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002143 else
2144 tprintf("/* %u entries */", dents);
2145 tprintf(", %lu", tcp->u_arg[2]);
2146 free(buf);
2147 return 0;
2148}
Roland McGrath186c5ac2002-12-15 23:58:23 +00002149
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002150int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002151sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002152{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002153 if (exiting(tcp)) {
2154 if (syserror(tcp))
2155 tprintf("%#lx", tcp->u_arg[0]);
2156 else
2157 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2158 tprintf(", %lu", tcp->u_arg[1]);
2159 }
2160 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002161}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002162
2163#ifdef HAVE_SYS_ASYNCH_H
2164
2165int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002166sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002167{
2168 struct aio_result_t res;
2169
2170 if (entering(tcp)) {
2171 tprintf("%lu, ", tcp->u_arg[0]);
2172 } else {
2173 if (syserror(tcp))
2174 tprintf("%#lx", tcp->u_arg[1]);
2175 else
2176 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2177 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2178 printxval(whence, tcp->u_arg[4], "L_???");
2179 if (syserror(tcp) || tcp->u_arg[5] == 0
2180 || umove(tcp, tcp->u_arg[5], &res) < 0)
2181 tprintf(", %#lx", tcp->u_arg[5]);
2182 else
2183 tprintf(", {aio_return %d aio_errno %d}",
2184 res.aio_return, res.aio_errno);
2185 }
2186 return 0;
2187}
2188
2189int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002190sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002191{
2192 struct aio_result_t res;
2193
2194 if (entering(tcp)) {
2195 tprintf("%lu, ", tcp->u_arg[0]);
2196 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2197 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2198 printxval(whence, tcp->u_arg[4], "L_???");
2199 }
2200 else {
2201 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002202 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002203 else if (syserror(tcp)
2204 || umove(tcp, tcp->u_arg[5], &res) < 0)
2205 tprintf(", %#lx", tcp->u_arg[5]);
2206 else
2207 tprintf(", {aio_return %d aio_errno %d}",
2208 res.aio_return, res.aio_errno);
2209 }
2210 return 0;
2211}
2212
2213int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002214sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002215{
2216 if (entering(tcp))
2217 printtv(tcp, tcp->u_arg[0]);
2218 return 0;
2219}
2220
2221int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002222sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002223{
2224 struct aio_result_t res;
2225
2226 if (exiting(tcp)) {
2227 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002228 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002229 else if (syserror(tcp)
2230 || umove(tcp, tcp->u_arg[0], &res) < 0)
2231 tprintf("%#lx", tcp->u_arg[0]);
2232 else
2233 tprintf("{aio_return %d aio_errno %d}",
2234 res.aio_return, res.aio_errno);
2235 }
2236 return 0;
2237}
2238
2239#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002240
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00002241#include "xlat/xattrflags.h"
Roland McGrath186c5ac2002-12-15 23:58:23 +00002242
Roland McGrath3292e222004-08-31 06:30:48 +00002243static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002244print_xattr_val(struct tcb *tcp, int failed,
2245 unsigned long arg,
2246 unsigned long insize,
2247 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002248{
Dmitry V. Levin1f215132012-12-07 21:38:52 +00002249 if (insize == 0)
2250 failed = 1;
Denys Vlasenko1d632462009-04-14 12:51:00 +00002251 if (!failed) {
2252 unsigned long capacity = 4 * size + 1;
2253 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2254 if (buf == NULL || /* probably a bogus size argument */
2255 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2256 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002257 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002258 else {
2259 unsigned char *out = buf;
2260 unsigned char *in = &buf[3 * size];
2261 size_t i;
2262 for (i = 0; i < size; ++i) {
Denys Vlasenko5198ed42013-03-06 23:44:23 +01002263 if (in[i] >= ' ' && in[i] <= 0x7e)
Denys Vlasenko1d632462009-04-14 12:51:00 +00002264 *out++ = in[i];
2265 else {
2266#define tohex(n) "0123456789abcdef"[n]
2267 *out++ = '\\';
2268 *out++ = 'x';
2269 *out++ = tohex(in[i] / 16);
2270 *out++ = tohex(in[i] % 16);
2271 }
2272 }
2273 /* Don't print terminating NUL if there is one. */
2274 if (i > 0 && in[i - 1] == '\0')
2275 out -= 4;
2276 *out = '\0';
2277 tprintf(", \"%s\", %ld", buf, insize);
2278 }
2279 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002280 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002281 if (failed)
2282 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002283}
2284
Roland McGrath186c5ac2002-12-15 23:58:23 +00002285int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002286sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002287{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002288 if (entering(tcp)) {
2289 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002290 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002291 printstr(tcp, tcp->u_arg[1], -1);
2292 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002293 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002294 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2295 }
2296 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002297}
2298
2299int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002300sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002301{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002302 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002303 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002304 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002305 printstr(tcp, tcp->u_arg[1], -1);
2306 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002307 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002308 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2309 }
2310 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002311}
2312
2313int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002314sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002315{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002316 if (entering(tcp)) {
2317 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002318 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002319 printstr(tcp, tcp->u_arg[1], -1);
2320 } else {
2321 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2322 tcp->u_rval);
2323 }
2324 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002325}
2326
2327int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002328sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002329{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002330 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002331 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002332 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002333 printstr(tcp, tcp->u_arg[1], -1);
2334 } else {
2335 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2336 tcp->u_rval);
2337 }
2338 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002339}
2340
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002341static void
2342print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2343{
2344 if (syserror(tcp)) {
2345 tprintf("%#lx", addr);
2346 } else {
2347 if (!addr) {
2348 tprints("NULL");
2349 } else {
2350 unsigned long len =
2351 (size < tcp->u_rval) ? size : tcp->u_rval;
2352 printstr(tcp, addr, len);
2353 }
2354 }
2355 tprintf(", %lu", size);
2356}
2357
Roland McGrath186c5ac2002-12-15 23:58:23 +00002358int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002359sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002360{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002361 if (entering(tcp)) {
2362 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002363 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002364 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002365 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002366 }
2367 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002368}
2369
2370int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002371sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002372{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002373 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002374 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002375 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002376 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002377 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002378 }
2379 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002380}
2381
2382int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002383sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002384{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002385 if (entering(tcp)) {
2386 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002387 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002388 printstr(tcp, tcp->u_arg[1], -1);
2389 }
2390 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002391}
2392
2393int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002394sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002395{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002396 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002397 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002398 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002399 printstr(tcp, tcp->u_arg[1], -1);
2400 }
2401 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002402}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002403
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00002404#include "xlat/advise.h"
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002405
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002406int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002407sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002408{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002409 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002410 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002411 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin7845a422014-04-17 13:32:47 +00002412 argn = printllval_aligned(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002413 tprintf(", %ld, ", tcp->u_arg[argn++]);
2414 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002415 }
2416 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002417}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002418
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002419int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002420sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002421{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002422 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002423 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002424 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin7845a422014-04-17 13:32:47 +00002425 argn = printllval_aligned(tcp, ", %lld, ", 1);
2426 argn = printllval_aligned(tcp, "%lld, ", argn);
Dmitry V. Levin8e096c42013-05-06 18:23:01 +00002427#if defined __ARM_EABI__ || defined AARCH64 || defined POWERPC || defined XTENSA
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002428 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002429#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002430 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002431#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002432 }
2433 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002434}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002435
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00002436#include "xlat/sync_file_range_flags.h"
William Manley16b9dcf2013-08-09 18:04:11 +01002437
2438int
2439sys_sync_file_range(struct tcb *tcp)
2440{
2441 if (entering(tcp)) {
2442 int argn;
2443 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin7845a422014-04-17 13:32:47 +00002444 argn = printllval_aligned(tcp, ", %lld, ", 1);
2445 argn = printllval_aligned(tcp, "%lld, ", argn);
William Manley16b9dcf2013-08-09 18:04:11 +01002446 printflags(sync_file_range_flags, tcp->u_arg[argn],
2447 "SYNC_FILE_RANGE_???");
2448 }
2449 return 0;
2450}
2451
2452int
2453sys_sync_file_range2(struct tcb *tcp)
2454{
2455 if (entering(tcp)) {
2456 int argn;
2457 printfd(tcp, tcp->u_arg[0]);
2458 printflags(sync_file_range_flags, 1,
2459 "SYNC_FILE_RANGE_???");
Dmitry V. Levin7845a422014-04-17 13:32:47 +00002460 argn = printllval_aligned(tcp, ", %lld, ", 2);
2461 argn = printllval_aligned(tcp, "%lld, ", argn);
William Manley16b9dcf2013-08-09 18:04:11 +01002462 }
2463 return 0;
2464}
2465
Mark Wielaardbab89402010-03-21 14:41:26 +01002466int
Roland McGrath96a96612008-05-20 04:56:18 +00002467sys_fallocate(struct tcb *tcp)
2468{
2469 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002470 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002471 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002472 tprintf(", %#lo, ", tcp->u_arg[1]); /* mode */
Dmitry V. Levin7845a422014-04-17 13:32:47 +00002473 argn = printllval_aligned(tcp, "%llu, ", 2); /* offset */
2474 printllval_aligned(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002475 }
2476 return 0;
2477}
Dmitry V. Levin88293652012-03-09 21:02:19 +00002478
Dmitry V. Levinad0c01e2012-03-15 00:52:22 +00002479#ifndef SWAP_FLAG_PREFER
2480# define SWAP_FLAG_PREFER 0x8000
2481#endif
2482#ifndef SWAP_FLAG_DISCARD
2483# define SWAP_FLAG_DISCARD 0x10000
2484#endif
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +00002485#include "xlat/swap_flags.h"
Dmitry V. Levin88293652012-03-09 21:02:19 +00002486
2487int
2488sys_swapon(struct tcb *tcp)
2489{
2490 if (entering(tcp)) {
2491 int flags = tcp->u_arg[1];
2492 printpath(tcp, tcp->u_arg[0]);
2493 tprints(", ");
2494 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2495 "SWAP_FLAG_???");
2496 if (flags & SWAP_FLAG_PREFER)
2497 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);
2498 }
2499 return 0;
2500}