blob: 5f3b506aacd6f4b119c7ffb80fea97a2e7793c49 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include <dirent.h>
Dmitry V. Levin88293652012-03-09 21:02:19 +000033#include <sys/swap.h>
Roland McGrathc531e572008-08-01 01:13:10 +000034
Denys Vlasenko84703742012-02-25 02:38:52 +010035#ifdef LINUXSPARC
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000036struct stat {
37 unsigned short st_dev;
38 unsigned int st_ino;
39 unsigned short st_mode;
40 short st_nlink;
41 unsigned short st_uid;
42 unsigned short st_gid;
43 unsigned short st_rdev;
44 unsigned int st_size;
45 int st_atime;
46 unsigned int __unused1;
47 int st_mtime;
48 unsigned int __unused2;
49 int st_ctime;
50 unsigned int __unused3;
51 int st_blksize;
52 int st_blocks;
53 unsigned int __unused4[2];
54};
Denys Vlasenko84703742012-02-25 02:38:52 +010055# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +000056struct stat_sparc64 {
57 unsigned int st_dev;
58 unsigned long st_ino;
59 unsigned int st_mode;
60 unsigned int st_nlink;
61 unsigned int st_uid;
62 unsigned int st_gid;
63 unsigned int st_rdev;
64 long st_size;
65 long st_atime;
66 long st_mtime;
67 long st_ctime;
68 long st_blksize;
69 long st_blocks;
70 unsigned long __unused4[2];
71};
Denys Vlasenko84703742012-02-25 02:38:52 +010072# endif /* SPARC64 */
73# define stat kernel_stat
74# include <asm/stat.h>
75# undef stat
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};
Denys Vlasenko84703742012-02-25 02:38:52 +010099#else
100# undef dev_t
101# undef ino_t
102# undef mode_t
103# undef nlink_t
104# undef uid_t
105# undef gid_t
106# undef off_t
107# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100108# define dev_t __kernel_dev_t
109# define ino_t __kernel_ino_t
110# define mode_t __kernel_mode_t
111# define nlink_t __kernel_nlink_t
112# define uid_t __kernel_uid_t
113# define gid_t __kernel_gid_t
114# define off_t __kernel_off_t
115# define loff_t __kernel_loff_t
Wichert Akkermana6013701999-07-08 14:00:58 +0000116
Denys Vlasenko84703742012-02-25 02:38:52 +0100117# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +0000118
Denys Vlasenko84703742012-02-25 02:38:52 +0100119# undef dev_t
120# undef ino_t
121# undef mode_t
122# undef nlink_t
123# undef uid_t
124# undef gid_t
125# undef off_t
126# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100127# define dev_t dev_t
128# define ino_t ino_t
129# define mode_t mode_t
130# define nlink_t nlink_t
131# define uid_t uid_t
132# define gid_t gid_t
133# define off_t off_t
134# define loff_t loff_t
135#endif
136
137#ifdef HPPA /* asm-parisc/stat.h defines stat64 */
138# undef stat64
139#endif
140#define stat libc_stat
141#define stat64 libc_stat64
142#include <sys/stat.h>
143#undef stat
144#undef stat64
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100145/* These might be macros. */
Denys Vlasenko84703742012-02-25 02:38:52 +0100146#undef st_atime
147#undef st_mtime
148#undef st_ctime
149#ifdef HPPA
150# define stat64 hpux_stat64
151#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000152
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000153#include <fcntl.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000154#ifdef HAVE_SYS_VFS_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100155# include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000156#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +0000157#ifdef HAVE_LINUX_XATTR_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100158# include <linux/xattr.h>
Denys Vlasenkoed720fd2012-02-25 02:24:03 +0100159#else
Denys Vlasenko84703742012-02-25 02:38:52 +0100160# define XATTR_CREATE 1
161# define XATTR_REPLACE 2
Roland McGrath186c5ac2002-12-15 23:58:23 +0000162#endif
163
John Hughes70623be2001-03-08 13:59:00 +0000164#if HAVE_LONG_LONG_OFF_T
165/*
166 * Ugly hacks for systems that have typedef long long off_t
167 */
Denys Vlasenko84703742012-02-25 02:38:52 +0100168# define stat64 stat
169# define HAVE_STAT64 1 /* Ugly hack */
Denys Vlasenko84703742012-02-25 02:38:52 +0100170# define sys_stat64 sys_stat
171# define sys_fstat64 sys_fstat
172# define sys_lstat64 sys_lstat
Denys Vlasenko84703742012-02-25 02:38:52 +0100173# define sys_truncate64 sys_truncate
174# define sys_ftruncate64 sys_ftruncate
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000175#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000176
177#ifdef MAJOR_IN_SYSMACROS
Denys Vlasenko84703742012-02-25 02:38:52 +0100178# include <sys/sysmacros.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000179#endif
180
181#ifdef MAJOR_IN_MKDEV
Denys Vlasenko84703742012-02-25 02:38:52 +0100182# include <sys/mkdev.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000183#endif
184
185#ifdef HAVE_SYS_ASYNCH_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100186# include <sys/asynch.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000187#endif
188
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100189struct kernel_dirent {
190 unsigned long d_ino;
191 unsigned long d_off;
192 unsigned short d_reclen;
193 char d_name[1];
194};
195
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000196const struct xlat open_access_modes[] = {
197 { O_RDONLY, "O_RDONLY" },
198 { O_WRONLY, "O_WRONLY" },
199 { O_RDWR, "O_RDWR" },
200#ifdef O_ACCMODE
201 { O_ACCMODE, "O_ACCMODE" },
202#endif
203 { 0, NULL },
204};
205
206const struct xlat open_mode_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000207 { O_CREAT, "O_CREAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000208 { O_EXCL, "O_EXCL" },
209 { O_NOCTTY, "O_NOCTTY" },
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000210 { O_TRUNC, "O_TRUNC" },
211 { O_APPEND, "O_APPEND" },
212 { O_NONBLOCK, "O_NONBLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000213#ifdef O_SYNC
214 { O_SYNC, "O_SYNC" },
215#endif
216#ifdef O_ASYNC
217 { O_ASYNC, "O_ASYNC" },
218#endif
219#ifdef O_DSYNC
220 { O_DSYNC, "O_DSYNC" },
221#endif
222#ifdef O_RSYNC
223 { O_RSYNC, "O_RSYNC" },
224#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000225#if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000226 { O_NDELAY, "O_NDELAY" },
227#endif
228#ifdef O_PRIV
229 { O_PRIV, "O_PRIV" },
230#endif
231#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000232 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000233#endif
234#ifdef O_LARGEFILE
Roland McGrathfee836e2005-02-02 22:11:32 +0000235# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
236# undef O_LARGEFILE
237# ifdef SPARC64
238# define O_LARGEFILE 0x40000
239# elif defined X86_64 || defined S390X
240# define O_LARGEFILE 0100000
241# endif
242# endif
Roland McGrath663a8a02005-02-04 09:49:56 +0000243# ifdef O_LARGEFILE
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200244 { O_LARGEFILE, "O_LARGEFILE" },
Roland McGrath663a8a02005-02-04 09:49:56 +0000245# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000246#endif
247#ifdef O_DIRECTORY
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200248 { O_DIRECTORY, "O_DIRECTORY" },
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000249#endif
250#ifdef O_NOFOLLOW
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200251 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000252#endif
Roland McGrath1025c3e2005-05-09 07:40:35 +0000253#ifdef O_NOATIME
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200254 { O_NOATIME, "O_NOATIME" },
Roland McGrath1025c3e2005-05-09 07:40:35 +0000255#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000256#ifdef O_CLOEXEC
257 { O_CLOEXEC, "O_CLOEXEC" },
258#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000259#ifdef FNDELAY
260 { FNDELAY, "FNDELAY" },
261#endif
262#ifdef FAPPEND
263 { FAPPEND, "FAPPEND" },
264#endif
265#ifdef FMARK
266 { FMARK, "FMARK" },
267#endif
268#ifdef FDEFER
269 { FDEFER, "FDEFER" },
270#endif
271#ifdef FASYNC
272 { FASYNC, "FASYNC" },
273#endif
274#ifdef FSHLOCK
275 { FSHLOCK, "FSHLOCK" },
276#endif
277#ifdef FEXLOCK
278 { FEXLOCK, "FEXLOCK" },
279#endif
280#ifdef FCREAT
281 { FCREAT, "FCREAT" },
282#endif
283#ifdef FTRUNC
284 { FTRUNC, "FTRUNC" },
285#endif
286#ifdef FEXCL
287 { FEXCL, "FEXCL" },
288#endif
289#ifdef FNBIO
290 { FNBIO, "FNBIO" },
291#endif
292#ifdef FSYNC
293 { FSYNC, "FSYNC" },
294#endif
295#ifdef FNOCTTY
296 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000297#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000298#ifdef O_SHLOCK
299 { O_SHLOCK, "O_SHLOCK" },
300#endif
301#ifdef O_EXLOCK
302 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000303#endif
304 { 0, NULL },
305};
306
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000307#ifndef AT_FDCWD
308# define AT_FDCWD -100
309#endif
310
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000311/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
312 * extension to get the right value. We do this by declaring fd as int here.
313 */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000314static void
Dmitry V. Levin31382132011-03-04 05:08:02 +0300315print_dirfd(struct tcb *tcp, int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000316{
317 if (fd == AT_FDCWD)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200318 tprints("AT_FDCWD, ");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200319 else {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300320 printfd(tcp, fd);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200321 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300322 }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000323}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000324
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000325/*
326 * low bits of the open(2) flags define access mode,
327 * other bits are real flags.
328 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000329const char *
330sprint_open_modes(mode_t flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000331{
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100332 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000333 char *p;
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100334 char sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000335 const char *str;
336 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000337
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100338 sep = ' ';
339 p = stpcpy(outstr, "flags");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000340 str = xlookup(open_access_modes, flags & 3);
341 if (str) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100342 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200343 p = stpcpy(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000344 flags &= ~3;
345 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000346 return outstr;
347 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000348 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000349
350 for (x = open_mode_flags; x->str; x++) {
351 if ((flags & x->val) == x->val) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100352 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200353 p = stpcpy(p, x->str);
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000354 flags &= ~x->val;
355 if (!flags)
356 return outstr;
357 sep = '|';
358 }
359 }
360 /* flags is still nonzero */
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100361 *p++ = sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000362 sprintf(p, "%#x", flags);
363 return outstr;
364}
365
366void
367tprint_open_modes(mode_t flags)
368{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200369 tprints(sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000370}
371
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000372static int
373decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000374{
375 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000376 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200377 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000378 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000379 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000380 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000381 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000382 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000383 }
384 }
385 return 0;
386}
387
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000388int
389sys_open(struct tcb *tcp)
390{
391 return decode_open(tcp, 0);
392}
393
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000394int
395sys_openat(struct tcb *tcp)
396{
397 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300398 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000399 return decode_open(tcp, 1);
400}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000401
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000402#ifdef LINUXSPARC
Roland McGratha4d48532005-06-08 20:45:28 +0000403static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000404 { 0, "O_RDWR" },
405 { 1, "O_RDONLY" },
406 { 2, "O_WRONLY" },
407 { 0x80, "O_NONBLOCK" },
408 { 8, "O_APPEND" },
409 { 0x100, "O_CREAT" },
410 { 0x200, "O_TRUNC" },
411 { 0x400, "O_EXCL" },
412 { 0x800, "O_NOCTTY" },
413 { 0x10, "O_SYNC" },
414 { 0x40, "O_DSYNC" },
415 { 0x8000, "O_RSYNC" },
416 { 4, "O_NDELAY" },
417 { 0x1000, "O_PRIV" },
418 { 0, NULL },
419};
420
421int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000422solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000423{
424 if (entering(tcp)) {
425 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200426 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000427 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000428 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000429 if (tcp->u_arg[1] & 0x100) {
430 /* mode */
431 tprintf(", %#lo", tcp->u_arg[2]);
432 }
433 }
434 return 0;
435}
436
437#endif
438
439int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000440sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000441{
442 if (entering(tcp)) {
443 printpath(tcp, tcp->u_arg[0]);
444 tprintf(", %#lo", tcp->u_arg[1]);
445 }
446 return 0;
447}
448
Roland McGrathd9f816f2004-09-04 03:39:20 +0000449static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000450 { F_OK, "F_OK", },
451 { R_OK, "R_OK" },
452 { W_OK, "W_OK" },
453 { X_OK, "X_OK" },
454#ifdef EFF_ONLY_OK
455 { EFF_ONLY_OK, "EFF_ONLY_OK" },
456#endif
457#ifdef EX_OK
458 { EX_OK, "EX_OK" },
459#endif
460 { 0, NULL },
461};
462
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000463static int
464decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000465{
466 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000467 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200468 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000469 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000470 }
471 return 0;
472}
473
474int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000475sys_access(struct tcb *tcp)
476{
477 return decode_access(tcp, 0);
478}
479
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000480int
481sys_faccessat(struct tcb *tcp)
482{
483 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300484 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000485 return decode_access(tcp, 1);
486}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000487
488int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000489sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000490{
491 if (entering(tcp)) {
492 tprintf("%#lo", tcp->u_arg[0]);
493 }
494 return RVAL_OCTAL;
495}
496
Roland McGrathd9f816f2004-09-04 03:39:20 +0000497static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000498 { SEEK_SET, "SEEK_SET" },
499 { SEEK_CUR, "SEEK_CUR" },
500 { SEEK_END, "SEEK_END" },
501 { 0, NULL },
502};
503
H.J. Luc933f272012-04-16 17:41:13 +0200504#if defined(LINUX_MIPSN32) || defined(X32)
Roland McGrath542c2c62008-05-20 01:11:56 +0000505int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000506sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000507{
508 long long offset;
509 int _whence;
510
511 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300512 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200513 tprints(", ");
Roland McGrath542c2c62008-05-20 01:11:56 +0000514 offset = tcp->ext_arg[1];
515 _whence = tcp->u_arg[2];
516 if (_whence == SEEK_SET)
517 tprintf("%llu, ", offset);
518 else
519 tprintf("%lld, ", offset);
520 printxval(whence, _whence, "SEEK_???");
521 }
H.J. Ludd0130b2012-04-16 12:16:45 +0200522 return RVAL_LUDECIMAL;
Roland McGrath542c2c62008-05-20 01:11:56 +0000523}
H.J. Ludd0130b2012-04-16 12:16:45 +0200524#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000526sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000527{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000528 off_t offset;
529 int _whence;
530
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000531 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300532 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200533 tprints(", ");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000534 offset = tcp->u_arg[1];
535 _whence = tcp->u_arg[2];
536 if (_whence == SEEK_SET)
537 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000538 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000539 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000540 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000541 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000542 return RVAL_UDECIMAL;
543}
John Hughes5a826b82001-03-07 13:21:24 +0000544#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000545
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000546int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000547sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000548{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000549 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300550 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000551 /*
552 * This one call takes explicitly two 32-bit arguments hi, lo,
553 * rather than one 64-bit argument for which LONG_LONG works
554 * appropriate for the native byte order.
555 */
556 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300557 tprintf(", %llu, ",
558 ((long long int) tcp->u_arg[1]) << 32 |
559 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000560 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300561 tprintf(", %lld, ",
562 ((long long int) tcp->u_arg[1]) << 32 |
563 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000564 }
565 else {
566 long long int off;
567 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
568 tprintf("%#lx, ", tcp->u_arg[3]);
569 else
570 tprintf("[%llu], ", off);
571 printxval(whence, tcp->u_arg[4], "SEEK_???");
572 }
573 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000574}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000575
576int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000577sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000578{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000579 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100580 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300581 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200582 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100583 argn = printllval(tcp, "%lld", 1);
584 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000585 }
586 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000587}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000588
John Hughes70623be2001-03-08 13:59:00 +0000589#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000590int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000591sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000592{
593 if (entering(tcp)) {
594 printpath(tcp, tcp->u_arg[0]);
595 tprintf(", %lu", tcp->u_arg[1]);
596 }
597 return 0;
598}
John Hughes5a826b82001-03-07 13:21:24 +0000599#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000600
John Hughes70623be2001-03-08 13:59:00 +0000601#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000602int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000603sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000604{
605 if (entering(tcp)) {
606 printpath(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100607 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000608 }
609 return 0;
610}
611#endif
612
John Hughes70623be2001-03-08 13:59:00 +0000613#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000614int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000615sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000616{
617 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300618 printfd(tcp, tcp->u_arg[0]);
619 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000620 }
621 return 0;
622}
John Hughes5a826b82001-03-07 13:21:24 +0000623#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000624
John Hughes70623be2001-03-08 13:59:00 +0000625#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000626int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000627sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000628{
629 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300630 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200631 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100632 printllval(tcp, "%llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000633 }
634 return 0;
635}
636#endif
637
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000638/* several stats */
639
Roland McGrathd9f816f2004-09-04 03:39:20 +0000640static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000641 { S_IFREG, "S_IFREG" },
642 { S_IFSOCK, "S_IFSOCK" },
643 { S_IFIFO, "S_IFIFO" },
644 { S_IFLNK, "S_IFLNK" },
645 { S_IFDIR, "S_IFDIR" },
646 { S_IFBLK, "S_IFBLK" },
647 { S_IFCHR, "S_IFCHR" },
648 { 0, NULL },
649};
650
Roland McGrathf9c49b22004-10-06 22:11:54 +0000651static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000652sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000653{
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100654 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
655 + sizeof(int)*3
656 + /*paranoia:*/ 8];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000657 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000658
659 if ((mode & S_IFMT) == 0)
660 s = "";
661 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
662 sprintf(buf, "%#o", mode);
663 return buf;
664 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100665 s = buf + sprintf(buf, "%s%s%s%s", s,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000666 (mode & S_ISUID) ? "|S_ISUID" : "",
667 (mode & S_ISGID) ? "|S_ISGID" : "",
668 (mode & S_ISVTX) ? "|S_ISVTX" : "");
669 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
670 if (mode)
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100671 sprintf((char*)s, "|%#o", mode);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000672 s = (*buf == '|') ? buf + 1 : buf;
673 return *s ? s : "0";
674}
675
676static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000677sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000678{
679 struct tm *tmp;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100680 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000681
682 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000683 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000684 return buf;
685 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200686 tmp = localtime(&t);
687 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000688 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
689 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
690 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
691 else
692 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
693
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000694 return buf;
695}
696
697#ifdef LINUXSPARC
698typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000699 int tv_sec;
700 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000701} timestruct_t;
702
703struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000704 unsigned st_dev;
705 int st_pad1[3]; /* network id */
706 unsigned st_ino;
707 unsigned st_mode;
708 unsigned st_nlink;
709 unsigned st_uid;
710 unsigned st_gid;
711 unsigned st_rdev;
712 int st_pad2[2];
713 int st_size;
714 int st_pad3; /* st_size, off_t expansion */
715 timestruct_t st_atime;
716 timestruct_t st_mtime;
717 timestruct_t st_ctime;
718 int st_blksize;
719 int st_blocks;
720 char st_fstype[16];
721 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000722};
723
724static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000725printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000726{
727 struct solstat statbuf;
728
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000729 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200730 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000731 return;
732 }
733 if (!abbrev(tcp)) {
734 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
735 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
736 (unsigned long) (statbuf.st_dev & 0x3ffff),
737 (unsigned long) statbuf.st_ino,
738 sprintmode(statbuf.st_mode));
739 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
740 (unsigned long) statbuf.st_nlink,
741 (unsigned long) statbuf.st_uid,
742 (unsigned long) statbuf.st_gid);
743 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
744 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
745 }
746 else
747 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
748 switch (statbuf.st_mode & S_IFMT) {
749 case S_IFCHR: case S_IFBLK:
750 tprintf("st_rdev=makedev(%lu, %lu), ",
751 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
752 (unsigned long) (statbuf.st_rdev & 0x3ffff));
753 break;
754 default:
755 tprintf("st_size=%u, ", statbuf.st_size);
756 break;
757 }
758 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000759 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
760 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
761 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000762 }
763 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200764 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000765}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000766
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100767#if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000768static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000769printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000770{
771 struct stat_sparc64 statbuf;
772
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000773 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200774 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000775 return;
776 }
777
778 if (!abbrev(tcp)) {
779 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
780 (unsigned long) major(statbuf.st_dev),
781 (unsigned long) minor(statbuf.st_dev),
782 (unsigned long) statbuf.st_ino,
783 sprintmode(statbuf.st_mode));
784 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
785 (unsigned long) statbuf.st_nlink,
786 (unsigned long) statbuf.st_uid,
787 (unsigned long) statbuf.st_gid);
788 tprintf("st_blksize=%lu, ",
789 (unsigned long) statbuf.st_blksize);
790 tprintf("st_blocks=%lu, ",
791 (unsigned long) statbuf.st_blocks);
792 }
793 else
794 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
795 switch (statbuf.st_mode & S_IFMT) {
796 case S_IFCHR: case S_IFBLK:
797 tprintf("st_rdev=makedev(%lu, %lu), ",
798 (unsigned long) major(statbuf.st_rdev),
799 (unsigned long) minor(statbuf.st_rdev));
800 break;
801 default:
802 tprintf("st_size=%lu, ", statbuf.st_size);
803 break;
804 }
805 if (!abbrev(tcp)) {
806 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
807 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100808 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000809 }
810 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200811 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000812}
813#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000814#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000815
Denys Vlasenko84703742012-02-25 02:38:52 +0100816#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200817struct stat_powerpc32 {
818 unsigned int st_dev;
819 unsigned int st_ino;
820 unsigned int st_mode;
821 unsigned short st_nlink;
822 unsigned int st_uid;
823 unsigned int st_gid;
824 unsigned int st_rdev;
825 unsigned int st_size;
826 unsigned int st_blksize;
827 unsigned int st_blocks;
828 unsigned int st_atime;
829 unsigned int st_atime_nsec;
830 unsigned int st_mtime;
831 unsigned int st_mtime_nsec;
832 unsigned int st_ctime;
833 unsigned int st_ctime_nsec;
834 unsigned int __unused4;
835 unsigned int __unused5;
836};
837
838static void
839printstat_powerpc32(struct tcb *tcp, long addr)
840{
841 struct stat_powerpc32 statbuf;
842
843 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200844 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200845 return;
846 }
847
848 if (!abbrev(tcp)) {
849 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
850 major(statbuf.st_dev), minor(statbuf.st_dev),
851 statbuf.st_ino,
852 sprintmode(statbuf.st_mode));
853 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
854 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
855 tprintf("st_blksize=%u, ", statbuf.st_blksize);
856 tprintf("st_blocks=%u, ", statbuf.st_blocks);
857 }
858 else
859 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
860 switch (statbuf.st_mode & S_IFMT) {
861 case S_IFCHR: case S_IFBLK:
862 tprintf("st_rdev=makedev(%lu, %lu), ",
863 (unsigned long) major(statbuf.st_rdev),
864 (unsigned long) minor(statbuf.st_rdev));
865 break;
866 default:
867 tprintf("st_size=%u, ", statbuf.st_size);
868 break;
869 }
870 if (!abbrev(tcp)) {
871 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
872 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100873 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200874 }
875 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200876 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200877}
Denys Vlasenko84703742012-02-25 02:38:52 +0100878#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200879
Roland McGratha4d48532005-06-08 20:45:28 +0000880static const struct xlat fileflags[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000881 { 0, NULL },
882};
883
John Hughes70623be2001-03-08 13:59:00 +0000884#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000885static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000886realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000887{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000888 if (!abbrev(tcp)) {
889 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
890 (unsigned long) major(statbuf->st_dev),
891 (unsigned long) minor(statbuf->st_dev),
892 (unsigned long) statbuf->st_ino,
893 sprintmode(statbuf->st_mode));
894 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
895 (unsigned long) statbuf->st_nlink,
896 (unsigned long) statbuf->st_uid,
897 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000898#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000899 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
900#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000901#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000902 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
903#endif
904 }
905 else
906 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
907 switch (statbuf->st_mode & S_IFMT) {
908 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000909#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000910 tprintf("st_rdev=makedev(%lu, %lu), ",
911 (unsigned long) major(statbuf->st_rdev),
912 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000913#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000914 tprintf("st_size=makedev(%lu, %lu), ",
915 (unsigned long) major(statbuf->st_size),
916 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000917#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000918 break;
919 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000920 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000921 break;
922 }
923 if (!abbrev(tcp)) {
924 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
925 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
926 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000927#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200928 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000929 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000930#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000931#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000932 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
933#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000934#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000935 tprintf(", st_level=%ld", statbuf->st_level);
936#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000937#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000938 tprintf(", st_fstype=%.*s",
939 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
940#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000941#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000942 tprintf(", st_gen=%u", statbuf->st_gen);
943#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200944 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000945 }
946 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200947 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000948}
949
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000950static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000951printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000952{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000953 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000954
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000955 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200956 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000957 return;
958 }
959 if (syserror(tcp) || !verbose(tcp)) {
960 tprintf("%#lx", addr);
961 return;
962 }
963
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000964#ifdef LINUXSPARC
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000965 if (current_personality == 1) {
966 printstatsol(tcp, addr);
967 return;
968 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000969#ifdef SPARC64
970 else if (current_personality == 2) {
971 printstat_sparc64(tcp, addr);
972 return;
973 }
974#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000975#endif /* LINUXSPARC */
976
Denys Vlasenko84703742012-02-25 02:38:52 +0100977#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200978 if (current_personality == 1) {
979 printstat_powerpc32(tcp, addr);
980 return;
981 }
982#endif
983
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000984 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200985 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000986 return;
987 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000988
989 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000990}
John Hughes70623be2001-03-08 13:59:00 +0000991#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000992
Denys Vlasenko84703742012-02-25 02:38:52 +0100993#if !defined HAVE_STAT64 && defined X86_64
Roland McGrathe6d0f712007-08-07 01:22:49 +0000994/*
995 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
996 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
997 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
998 * __GNUC__ is needed for the required __attribute__ below.
999 */
1000struct stat64 {
1001 unsigned long long st_dev;
1002 unsigned char __pad0[4];
1003 unsigned int __st_ino;
1004 unsigned int st_mode;
1005 unsigned int st_nlink;
1006 unsigned int st_uid;
1007 unsigned int st_gid;
1008 unsigned long long st_rdev;
1009 unsigned char __pad3[4];
1010 long long st_size;
1011 unsigned int st_blksize;
1012 unsigned long long st_blocks;
1013 unsigned int st_atime;
1014 unsigned int st_atime_nsec;
1015 unsigned int st_mtime;
1016 unsigned int st_mtime_nsec;
1017 unsigned int st_ctime;
1018 unsigned int st_ctime_nsec;
1019 unsigned long long st_ino;
1020} __attribute__((packed));
1021# define HAVE_STAT64 1
1022# define STAT64_SIZE 96
1023#endif
1024
Wichert Akkermanc7926982000-04-10 22:22:31 +00001025#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001026static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001027printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001028{
1029 struct stat64 statbuf;
1030
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001031#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001032 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1033#endif
1034
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001035 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001036 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001037 return;
1038 }
1039 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001040 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001041 return;
1042 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001043
1044#ifdef LINUXSPARC
1045 if (current_personality == 1) {
1046 printstatsol(tcp, addr);
1047 return;
1048 }
1049# ifdef SPARC64
1050 else if (current_personality == 2) {
1051 printstat_sparc64(tcp, addr);
1052 return;
1053 }
1054# endif
1055#endif /* LINUXSPARC */
1056
Denys Vlasenko84703742012-02-25 02:38:52 +01001057#if defined X86_64
H.J. Lu35be5812012-04-16 13:00:01 +02001058 if (current_personality != 1) {
Andreas Schwab61b74352009-10-16 11:37:13 +02001059 printstat(tcp, addr);
1060 return;
1061 }
1062#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +00001063
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001064 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001065 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001066 return;
1067 }
1068
1069 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001070#ifdef HAVE_LONG_LONG
1071 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1072#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001073 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001074#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001075 (unsigned long) major(statbuf.st_dev),
1076 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001077#ifdef HAVE_LONG_LONG
1078 (unsigned long long) statbuf.st_ino,
1079#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001080 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001081#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001082 sprintmode(statbuf.st_mode));
1083 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1084 (unsigned long) statbuf.st_nlink,
1085 (unsigned long) statbuf.st_uid,
1086 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001087#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001088 tprintf("st_blksize=%lu, ",
1089 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001090#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1091#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001092 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001093#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001094 }
1095 else
1096 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1097 switch (statbuf.st_mode & S_IFMT) {
1098 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001099#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001100 tprintf("st_rdev=makedev(%lu, %lu), ",
1101 (unsigned long) major(statbuf.st_rdev),
1102 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001103#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001104 tprintf("st_size=makedev(%lu, %lu), ",
1105 (unsigned long) major(statbuf.st_size),
1106 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001107#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001108 break;
1109 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001110#ifdef HAVE_LONG_LONG
1111 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1112#else
1113 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1114#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001115 break;
1116 }
1117 if (!abbrev(tcp)) {
1118 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1119 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001120 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001121#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001122 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001123 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001124#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001125#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001126 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1127#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001128#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001129 tprintf(", st_level=%ld", statbuf.st_level);
1130#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001131#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001132 tprintf(", st_fstype=%.*s",
1133 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1134#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001135#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001136 tprintf(", st_gen=%u", statbuf.st_gen);
1137#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001138 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001139 }
1140 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001141 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001142}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001143#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001144
Denys Vlasenko84703742012-02-25 02:38:52 +01001145#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001146static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001147convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001148{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001149 newbuf->st_dev = oldbuf->st_dev;
1150 newbuf->st_ino = oldbuf->st_ino;
1151 newbuf->st_mode = oldbuf->st_mode;
1152 newbuf->st_nlink = oldbuf->st_nlink;
1153 newbuf->st_uid = oldbuf->st_uid;
1154 newbuf->st_gid = oldbuf->st_gid;
1155 newbuf->st_rdev = oldbuf->st_rdev;
1156 newbuf->st_size = oldbuf->st_size;
1157 newbuf->st_atime = oldbuf->st_atime;
1158 newbuf->st_mtime = oldbuf->st_mtime;
1159 newbuf->st_ctime = oldbuf->st_ctime;
1160 newbuf->st_blksize = 0; /* not supported in old_stat */
1161 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001162}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001163
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001164static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001165printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001166{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001167 struct __old_kernel_stat statbuf;
1168 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001169
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001170 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001171 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001172 return;
1173 }
1174 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001175 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001176 return;
1177 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001178
Denys Vlasenko84703742012-02-25 02:38:52 +01001179# ifdef LINUXSPARC
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001180 if (current_personality == 1) {
1181 printstatsol(tcp, addr);
1182 return;
1183 }
Denys Vlasenko84703742012-02-25 02:38:52 +01001184# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001185
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001186 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001187 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001188 return;
1189 }
1190
1191 convertoldstat(&statbuf, &newstatbuf);
1192 realprintstat(tcp, &newstatbuf);
1193}
Denys Vlasenko84703742012-02-25 02:38:52 +01001194#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001195
John Hughes70623be2001-03-08 13:59:00 +00001196#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001197int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001198sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001199{
1200 if (entering(tcp)) {
1201 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001202 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001203 } else {
1204 printstat(tcp, tcp->u_arg[1]);
1205 }
1206 return 0;
1207}
John Hughesb8c9f772001-03-07 16:53:07 +00001208#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001209
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001210int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001211sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001212{
1213#ifdef HAVE_STAT64
1214 if (entering(tcp)) {
1215 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001216 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001217 } else {
1218 printstat64(tcp, tcp->u_arg[1]);
1219 }
1220 return 0;
1221#else
1222 return printargs(tcp);
1223#endif
1224}
1225
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001226#ifndef AT_SYMLINK_NOFOLLOW
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001227# define AT_SYMLINK_NOFOLLOW 0x100
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001228#endif
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001229#ifndef AT_REMOVEDIR
1230# define AT_REMOVEDIR 0x200
1231#endif
1232#ifndef AT_SYMLINK_FOLLOW
1233# define AT_SYMLINK_FOLLOW 0x400
1234#endif
1235#ifndef AT_NO_AUTOMOUNT
1236# define AT_NO_AUTOMOUNT 0x800
1237#endif
1238#ifndef AT_EMPTY_PATH
1239# define AT_EMPTY_PATH 0x1000
1240#endif
1241
1242static const struct xlat at_flags[] = {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001243 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001244 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1245 { AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" },
1246 { AT_NO_AUTOMOUNT, "AT_NO_AUTOMOUNT" },
1247 { AT_EMPTY_PATH, "AT_EMPTY_PATH" },
1248 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001249};
1250
1251int
1252sys_newfstatat(struct tcb *tcp)
1253{
1254 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001255 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001256 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001257 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001258 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001259#ifdef POWERPC64
1260 if (current_personality == 0)
1261 printstat(tcp, tcp->u_arg[2]);
1262 else
1263 printstat64(tcp, tcp->u_arg[2]);
1264#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001265 printstat64(tcp, tcp->u_arg[2]);
1266#else
1267 printstat(tcp, tcp->u_arg[2]);
1268#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001269 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001270 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001271 }
1272 return 0;
1273}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001274
Denys Vlasenko84703742012-02-25 02:38:52 +01001275#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001276int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001277sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001278{
1279 if (entering(tcp)) {
1280 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001281 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001282 } else {
1283 printoldstat(tcp, tcp->u_arg[1]);
1284 }
1285 return 0;
1286}
Denys Vlasenko84703742012-02-25 02:38:52 +01001287#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001288
John Hughes70623be2001-03-08 13:59:00 +00001289#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001290int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001291sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001293 if (entering(tcp)) {
1294 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001295 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001296 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001297 printstat(tcp, tcp->u_arg[1]);
1298 }
1299 return 0;
1300}
John Hughesb8c9f772001-03-07 16:53:07 +00001301#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001302
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001303int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001304sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001305{
1306#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001307 if (entering(tcp)) {
1308 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001309 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001310 } else {
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001311 printstat64(tcp, tcp->u_arg[1]);
1312 }
1313 return 0;
1314#else
1315 return printargs(tcp);
1316#endif
1317}
1318
Denys Vlasenko84703742012-02-25 02:38:52 +01001319#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001320int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001321sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001322{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001323 if (entering(tcp)) {
1324 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001325 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001326 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001327 printoldstat(tcp, tcp->u_arg[1]);
1328 }
1329 return 0;
1330}
Denys Vlasenko84703742012-02-25 02:38:52 +01001331#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001332
John Hughes70623be2001-03-08 13:59:00 +00001333#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001334int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001335sys_lstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001336{
1337 if (entering(tcp)) {
1338 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001339 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001340 } else {
1341 printstat(tcp, tcp->u_arg[1]);
1342 }
1343 return 0;
1344}
John Hughesb8c9f772001-03-07 16:53:07 +00001345#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001346
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001347int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001348sys_lstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001349{
1350#ifdef HAVE_STAT64
1351 if (entering(tcp)) {
1352 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001353 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001354 } else {
1355 printstat64(tcp, tcp->u_arg[1]);
1356 }
1357 return 0;
1358#else
1359 return printargs(tcp);
1360#endif
1361}
1362
Denys Vlasenko84703742012-02-25 02:38:52 +01001363#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001364int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001365sys_oldlstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001366{
1367 if (entering(tcp)) {
1368 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001369 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001370 } else {
1371 printoldstat(tcp, tcp->u_arg[1]);
1372 }
1373 return 0;
1374}
Denys Vlasenko84703742012-02-25 02:38:52 +01001375#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001376
Denys Vlasenko84703742012-02-25 02:38:52 +01001377#if defined(LINUXSPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001378
1379int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001380sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001381{
1382 if (entering(tcp)) {
1383 tprintf("%ld, ", tcp->u_arg[0]);
1384 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001385 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001386 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001387# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001388 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001389 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001390 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001391# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001392 printstat(tcp, tcp->u_arg[2]);
1393 }
1394 return 0;
1395}
1396
1397int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001398sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001399{
1400 if (entering(tcp))
1401 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1402 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001403# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001404 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001405 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001406 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001407# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001408 printstat(tcp, tcp->u_arg[2]);
1409 }
1410 return 0;
1411}
1412
1413int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001414sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001415{
1416 if (entering(tcp)) {
1417 tprintf("%ld, ", tcp->u_arg[0]);
1418 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001419 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001420 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001421# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001422 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001423 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001424 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001425# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001426 printstat(tcp, tcp->u_arg[2]);
1427 }
1428 return 0;
1429}
1430
1431int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001432sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001433{
1434 int mode = tcp->u_arg[2];
1435
1436 if (entering(tcp)) {
1437 tprintf("%ld, ", tcp->u_arg[0]);
1438 printpath(tcp, tcp->u_arg[1]);
1439 tprintf(", %s", sprintmode(mode));
1440 switch (mode & S_IFMT) {
1441 case S_IFCHR: case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001442 tprintf(", makedev(%lu, %lu)",
1443 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1444 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001445 break;
1446 default:
1447 break;
1448 }
1449 }
1450 return 0;
1451}
1452
Denys Vlasenko84703742012-02-25 02:38:52 +01001453# ifdef HAVE_SYS_ACL_H
Wichert Akkerman8829a551999-06-11 13:18:40 +00001454
Denys Vlasenko84703742012-02-25 02:38:52 +01001455# include <sys/acl.h>
Wichert Akkerman8829a551999-06-11 13:18:40 +00001456
Roland McGratha4d48532005-06-08 20:45:28 +00001457static const struct xlat aclcmds[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001458# ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001459 { SETACL, "SETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001460# endif
1461# ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001462 { GETACL, "GETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001463# endif
1464# ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001465 { GETACLCNT, "GETACLCNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001466# endif
1467# ifdef ACL_GET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001468 { ACL_GET, "ACL_GET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001469# endif
1470# ifdef ACL_SET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001471 { ACL_SET, "ACL_SET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001472# endif
1473# ifdef ACL_CNT
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001474 { ACL_CNT, "ACL_CNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001475# endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001476 { 0, NULL },
1477};
1478
1479int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001480sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001481{
1482 if (entering(tcp)) {
1483 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001484 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001485 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1486 tprintf(", %ld", tcp->u_arg[2]);
1487 /*
1488 * FIXME - dump out the list of aclent_t's pointed to
1489 * by "tcp->u_arg[3]" if it's not NULL.
1490 */
1491 if (tcp->u_arg[3])
1492 tprintf(", %#lx", tcp->u_arg[3]);
1493 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001494 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001495 }
1496 return 0;
1497}
1498
Wichert Akkerman8829a551999-06-11 13:18:40 +00001499int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001500sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001501{
1502 if (entering(tcp)) {
1503 tprintf("%ld, ", tcp->u_arg[0]);
1504 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1505 tprintf(", %ld", tcp->u_arg[2]);
1506 /*
1507 * FIXME - dump out the list of aclent_t's pointed to
1508 * by "tcp->u_arg[3]" if it's not NULL.
1509 */
1510 if (tcp->u_arg[3])
1511 tprintf(", %#lx", tcp->u_arg[3]);
1512 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001513 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001514 }
1515 return 0;
1516}
1517
Roland McGratha4d48532005-06-08 20:45:28 +00001518static const struct xlat aclipc[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001519# ifdef IPC_SHM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001520 { IPC_SHM, "IPC_SHM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001521# endif
1522# ifdef IPC_SEM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001523 { IPC_SEM, "IPC_SEM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001524# endif
1525# ifdef IPC_MSG
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001526 { IPC_MSG, "IPC_MSG" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001527# endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001528 { 0, NULL },
1529};
1530
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001531int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001532sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001533{
1534 if (entering(tcp)) {
1535 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1536 tprintf(", %#lx, ", tcp->u_arg[1]);
1537 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1538 tprintf(", %ld", tcp->u_arg[3]);
1539 /*
1540 * FIXME - dump out the list of aclent_t's pointed to
1541 * by "tcp->u_arg[4]" if it's not NULL.
1542 */
1543 if (tcp->u_arg[4])
1544 tprintf(", %#lx", tcp->u_arg[4]);
1545 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001546 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001547 }
1548 return 0;
1549}
1550
Denys Vlasenko84703742012-02-25 02:38:52 +01001551# endif /* HAVE_SYS_ACL_H */
Wichert Akkerman8829a551999-06-11 13:18:40 +00001552
Denys Vlasenko84703742012-02-25 02:38:52 +01001553#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001554
Roland McGrathd9f816f2004-09-04 03:39:20 +00001555static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001556 { 0x73757245, "CODA_SUPER_MAGIC" },
1557 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1558 { 0x1373, "DEVFS_SUPER_MAGIC" },
1559 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1560 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001561 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1562 { 0xef53, "EXT2_SUPER_MAGIC" },
1563 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001564 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001565 { 0x9660, "ISOFS_SUPER_MAGIC" },
1566 { 0x137f, "MINIX_SUPER_MAGIC" },
1567 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001568 { 0x2468, "MINIX2_SUPER_MAGIC" },
1569 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001570 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001571 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001572 { 0x6969, "NFS_SUPER_MAGIC" },
1573 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001574 { 0x002f, "QNX4_SUPER_MAGIC" },
1575 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1576 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1577 { 0x517b, "SMB_SUPER_MAGIC" },
1578 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1579 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1580 { 0x00011954, "UFS_MAGIC" },
1581 { 0x54190100, "UFS_CIGAM" },
1582 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001583 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001584 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001585 { 0, NULL },
1586};
1587
Roland McGrathf9c49b22004-10-06 22:11:54 +00001588static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001589sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001590{
1591 static char buf[32];
Roland McGrathf9c49b22004-10-06 22:11:54 +00001592 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001593
1594 s = xlookup(fsmagic, magic);
1595 if (s) {
1596 sprintf(buf, "\"%s\"", s);
1597 return buf;
1598 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001599 sprintf(buf, "%#x", magic);
1600 return buf;
1601}
1602
1603static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001604printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001605{
1606 struct statfs statbuf;
1607
1608 if (syserror(tcp) || !verbose(tcp)) {
1609 tprintf("%#lx", addr);
1610 return;
1611 }
1612 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001613 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001614 return;
1615 }
1616#ifdef ALPHA
1617
1618 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1619 sprintfstype(statbuf.f_type),
1620 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001621 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001622 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001623 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1624 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001625#else /* !ALPHA */
1626 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1627 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001628 (unsigned long)statbuf.f_bsize,
1629 (unsigned long)statbuf.f_blocks,
1630 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001631 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1632 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001633 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001634 (unsigned long)statbuf.f_ffree,
1635 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001636 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001637#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001638#ifdef _STATFS_F_FRSIZE
1639 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1640#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001641 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001642}
1643
1644int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001645sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001646{
1647 if (entering(tcp)) {
1648 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001649 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001650 } else {
1651 printstatfs(tcp, tcp->u_arg[1]);
1652 }
1653 return 0;
1654}
1655
1656int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001657sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001658{
1659 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001660 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001661 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001662 } else {
1663 printstatfs(tcp, tcp->u_arg[1]);
1664 }
1665 return 0;
1666}
1667
Denys Vlasenko84703742012-02-25 02:38:52 +01001668#if defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001669static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001670printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001671{
1672 struct statfs64 statbuf;
1673
1674 if (syserror(tcp) || !verbose(tcp)) {
1675 tprintf("%#lx", addr);
1676 return;
1677 }
1678 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001679 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001680 return;
1681 }
Roland McGrath08738432005-06-03 02:40:39 +00001682 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001683 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001684 (unsigned long long)statbuf.f_bsize,
1685 (unsigned long long)statbuf.f_blocks,
1686 (unsigned long long)statbuf.f_bfree);
1687 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1688 (unsigned long long)statbuf.f_bavail,
1689 (unsigned long long)statbuf.f_files,
1690 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001691 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1692 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001693#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001694 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001695#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001696#ifdef _STATFS_F_FLAGS
1697 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1698#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001699 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001700}
1701
Andreas Schwab7d558012012-01-17 18:14:22 +01001702struct compat_statfs64 {
1703 uint32_t f_type;
1704 uint32_t f_bsize;
1705 uint64_t f_blocks;
1706 uint64_t f_bfree;
1707 uint64_t f_bavail;
1708 uint64_t f_files;
1709 uint64_t f_ffree;
1710 fsid_t f_fsid;
1711 uint32_t f_namelen;
1712 uint32_t f_frsize;
1713 uint32_t f_flags;
1714 uint32_t f_spare[4];
1715}
1716#if defined(X86_64) || defined(IA64)
1717 __attribute__ ((packed, aligned(4)))
1718#endif
1719;
1720
1721static void
1722printcompat_statfs64(struct tcb *tcp, long addr)
1723{
1724 struct compat_statfs64 statbuf;
1725
1726 if (syserror(tcp) || !verbose(tcp)) {
1727 tprintf("%#lx", addr);
1728 return;
1729 }
1730 if (umove(tcp, addr, &statbuf) < 0) {
1731 tprints("{...}");
1732 return;
1733 }
1734 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1735 sprintfstype(statbuf.f_type),
1736 (unsigned long)statbuf.f_bsize,
1737 (unsigned long long)statbuf.f_blocks,
1738 (unsigned long long)statbuf.f_bfree);
1739 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1740 (unsigned long long)statbuf.f_bavail,
1741 (unsigned long long)statbuf.f_files,
1742 (unsigned long long)statbuf.f_ffree,
1743 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1744 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1745 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001746 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
Andreas Schwab7d558012012-01-17 18:14:22 +01001747}
1748
Roland McGrathab147c52003-07-17 09:03:02 +00001749int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001750sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001751{
1752 if (entering(tcp)) {
1753 printpath(tcp, tcp->u_arg[0]);
1754 tprintf(", %lu, ", tcp->u_arg[1]);
1755 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001756 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001757 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001758 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1759 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001760 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001761 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001762 }
1763 return 0;
1764}
1765
1766int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001767sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001768{
1769 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001770 printfd(tcp, tcp->u_arg[0]);
1771 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001772 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001773 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001774 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001775 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1776 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001777 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001778 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001779 }
1780 return 0;
1781}
1782#endif
1783
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001784#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001785int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001786osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001787{
1788 if (entering(tcp)) {
1789 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001790 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001791 } else {
1792 printstatfs(tcp, tcp->u_arg[1]);
1793 tprintf(", %lu", tcp->u_arg[2]);
1794 }
1795 return 0;
1796}
1797
1798int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001799osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001800{
1801 if (entering(tcp)) {
1802 tprintf("%lu, ", tcp->u_arg[0]);
1803 } else {
1804 printstatfs(tcp, tcp->u_arg[1]);
1805 tprintf(", %lu", tcp->u_arg[2]);
1806 }
1807 return 0;
1808}
Denys Vlasenko84703742012-02-25 02:38:52 +01001809#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001810
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001811/* directory */
1812int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001813sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001814{
1815 if (entering(tcp)) {
1816 printpath(tcp, tcp->u_arg[0]);
1817 }
1818 return 0;
1819}
1820
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001821static int
1822decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001823{
1824 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001825 printpath(tcp, tcp->u_arg[offset]);
1826 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001827 }
1828 return 0;
1829}
1830
1831int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001832sys_mkdir(struct tcb *tcp)
1833{
1834 return decode_mkdir(tcp, 0);
1835}
1836
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001837int
1838sys_mkdirat(struct tcb *tcp)
1839{
1840 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001841 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001842 return decode_mkdir(tcp, 1);
1843}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001844
1845int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001846sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001847{
1848 if (entering(tcp)) {
1849 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001850 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001851 printpath(tcp, tcp->u_arg[1]);
1852 }
1853 return 0;
1854}
1855
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001856int
1857sys_linkat(struct tcb *tcp)
1858{
1859 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001860 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001861 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001862 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001863 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001864 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001865 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001866 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001867 }
1868 return 0;
1869}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001870
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001871int
1872sys_unlinkat(struct tcb *tcp)
1873{
1874 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001875 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001876 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001877 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001878 printflags(at_flags, tcp->u_arg[2], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001879 }
1880 return 0;
1881}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001882
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001883int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001884sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001885{
1886 if (entering(tcp)) {
1887 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001888 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001889 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001890 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001891 }
1892 return 0;
1893}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001894
1895static int
1896decode_readlink(struct tcb *tcp, int offset)
1897{
1898 if (entering(tcp)) {
1899 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001900 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001901 } else {
1902 if (syserror(tcp))
1903 tprintf("%#lx", tcp->u_arg[offset + 1]);
1904 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001905 /* Used to use printpathn(), but readlink
1906 * neither includes NUL in the returned count,
1907 * nor actually writes it into memory.
1908 * printpathn() would decide on printing
1909 * "..." continuation based on garbage
1910 * past return buffer's end.
1911 */
1912 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001913 tprintf(", %lu", tcp->u_arg[offset + 2]);
1914 }
1915 return 0;
1916}
1917
1918int
1919sys_readlink(struct tcb *tcp)
1920{
1921 return decode_readlink(tcp, 0);
1922}
1923
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001924int
1925sys_readlinkat(struct tcb *tcp)
1926{
1927 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001928 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001929 return decode_readlink(tcp, 1);
1930}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001931
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001932int
1933sys_renameat(struct tcb *tcp)
1934{
1935 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001936 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001937 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001938 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001939 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001940 printpath(tcp, tcp->u_arg[3]);
1941 }
1942 return 0;
1943}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001944
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001945int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001946sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001947{
1948 if (entering(tcp)) {
1949 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001950 printuid(", ", tcp->u_arg[1]);
1951 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001952 }
1953 return 0;
1954}
1955
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001956int
1957sys_fchownat(struct tcb *tcp)
1958{
1959 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001960 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001961 printpath(tcp, tcp->u_arg[1]);
1962 printuid(", ", tcp->u_arg[2]);
1963 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001964 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001965 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001966 }
1967 return 0;
1968}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001969
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001970int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001971sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001972{
1973 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001974 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001975 printuid(", ", tcp->u_arg[1]);
1976 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001977 }
1978 return 0;
1979}
1980
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001981static int
1982decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001983{
1984 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001985 printpath(tcp, tcp->u_arg[offset]);
1986 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001987 }
1988 return 0;
1989}
1990
1991int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001992sys_chmod(struct tcb *tcp)
1993{
1994 return decode_chmod(tcp, 0);
1995}
1996
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001997int
1998sys_fchmodat(struct tcb *tcp)
1999{
2000 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002001 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002002 return decode_chmod(tcp, 1);
2003}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002004
2005int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002006sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002007{
2008 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002009 printfd(tcp, tcp->u_arg[0]);
2010 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002011 }
2012 return 0;
2013}
2014
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002015#ifdef ALPHA
2016int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002017sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002018{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002019 if (entering(tcp)) {
2020 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002021 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002022 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2023 }
2024 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002025}
2026#endif
2027
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002028static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002029decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002030{
2031 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002032 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002033 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002034 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002035 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00002036 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002037 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00002038 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2039 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002040 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002041 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002042 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00002043 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002044 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00002045 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002046 }
2047 return 0;
2048}
2049
2050int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002051sys_utimes(struct tcb *tcp)
2052{
Roland McGrath6afc5652007-07-24 01:57:11 +00002053 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002054}
2055
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002056int
2057sys_futimesat(struct tcb *tcp)
2058{
2059 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002060 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002061 return decode_utimes(tcp, 1, 0);
2062}
2063
2064int
2065sys_utimensat(struct tcb *tcp)
2066{
2067 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002068 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002069 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002070 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00002071 printflags(at_flags, tcp->u_arg[3], "AT_???");
Roland McGrath6afc5652007-07-24 01:57:11 +00002072 }
2073 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002074}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002075
2076int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002077sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002078{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002079 union {
2080 long utl[2];
2081 int uti[2];
2082 } u;
Denys Vlasenko9fd4f962012-03-19 09:36:42 +01002083 unsigned wordsize = current_wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002084
2085 if (entering(tcp)) {
2086 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002087 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002088 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002089 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002090 else if (!verbose(tcp))
2091 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002092 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002093 tprints("[?, ?]");
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002094 else if (wordsize == sizeof u.utl[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002095 tprintf("[%s,", sprinttime(u.utl[0]));
2096 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002097 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002098 else if (wordsize == sizeof u.uti[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002099 tprintf("[%s,", sprinttime(u.uti[0]));
2100 tprintf(" %s]", sprinttime(u.uti[1]));
2101 }
2102 else
2103 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002104 }
2105 return 0;
2106}
2107
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002108static int
2109decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002110{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002111 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002112
2113 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002114 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002115 tprintf(", %s", sprintmode(mode));
2116 switch (mode & S_IFMT) {
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002117 case S_IFCHR:
2118 case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002119#ifdef LINUXSPARC
2120 if (current_personality == 1)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002121 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002122 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2123 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002124 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002125#endif
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002126 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002127 (unsigned long) major(tcp->u_arg[offset + 2]),
2128 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002129 break;
2130 default:
2131 break;
2132 }
2133 }
2134 return 0;
2135}
2136
2137int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002138sys_mknod(struct tcb *tcp)
2139{
2140 return decode_mknod(tcp, 0);
2141}
2142
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002143int
2144sys_mknodat(struct tcb *tcp)
2145{
2146 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002147 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002148 return decode_mknod(tcp, 1);
2149}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002150
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002151static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002152printdir(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002153{
2154 struct dirent d;
2155
2156 if (!verbose(tcp)) {
2157 tprintf("%#lx", addr);
2158 return;
2159 }
2160 if (umove(tcp, addr, &d) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002161 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002162 return;
2163 }
2164 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002165 tprints("d_name=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002166 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002167 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002168}
2169
2170int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002171sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002172{
2173 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002174 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002175 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002176 } else {
2177 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2178 tprintf("%#lx", tcp->u_arg[1]);
2179 else
2180 printdir(tcp, tcp->u_arg[1]);
2181 /* Not much point in printing this out, it is always 1. */
2182 if (tcp->u_arg[2] != 1)
2183 tprintf(", %lu", tcp->u_arg[2]);
2184 }
2185 return 0;
2186}
2187
Roland McGratha4d48532005-06-08 20:45:28 +00002188static const struct xlat direnttypes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002189 { DT_UNKNOWN, "DT_UNKNOWN" },
2190 { DT_FIFO, "DT_FIFO" },
2191 { DT_CHR, "DT_CHR" },
2192 { DT_DIR, "DT_DIR" },
2193 { DT_BLK, "DT_BLK" },
2194 { DT_REG, "DT_REG" },
2195 { DT_LNK, "DT_LNK" },
2196 { DT_SOCK, "DT_SOCK" },
2197 { DT_WHT, "DT_WHT" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002198 { 0, NULL },
2199};
2200
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002201int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002202sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002203{
2204 int i, len, dents = 0;
2205 char *buf;
2206
2207 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002208 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002209 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002210 return 0;
2211 }
2212 if (syserror(tcp) || !verbose(tcp)) {
2213 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2214 return 0;
2215 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002216 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002217 /* Beware of insanely large or negative values in tcp->u_rval */
2218 if (tcp->u_rval > 1024*1024)
2219 len = 1024*1024;
2220 if (tcp->u_rval < 0)
2221 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002222 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002223 if (len && !buf)
2224 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002225 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002226 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002227 free(buf);
2228 return 0;
2229 }
2230 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002231 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002232 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002233 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002234 if (!abbrev(tcp)) {
2235 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2236 i ? " " : "", d->d_ino, d->d_off);
2237 tprintf("d_reclen=%u, d_name=\"%s\"}",
2238 d->d_reclen, d->d_name);
2239 }
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002240 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002241 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002242 break;
2243 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002244 i += d->d_reclen;
2245 dents++;
2246 }
2247 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002248 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002249 else
2250 tprintf("/* %u entries */", dents);
2251 tprintf(", %lu", tcp->u_arg[2]);
2252 free(buf);
2253 return 0;
2254}
2255
John Hughesbdf48f52001-03-06 15:08:09 +00002256#if _LFS64_LARGEFILE
2257int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002258sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002259{
2260 int i, len, dents = 0;
2261 char *buf;
2262
2263 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002264 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002265 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002266 return 0;
2267 }
2268 if (syserror(tcp) || !verbose(tcp)) {
2269 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2270 return 0;
2271 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002272
John Hughesbdf48f52001-03-06 15:08:09 +00002273 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002274 /* Beware of insanely large or negative tcp->u_rval */
2275 if (tcp->u_rval > 1024*1024)
2276 len = 1024*1024;
2277 if (tcp->u_rval < 0)
2278 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002279 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002280 if (len && !buf)
2281 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002282
John Hughesbdf48f52001-03-06 15:08:09 +00002283 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002284 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002285 free(buf);
2286 return 0;
2287 }
2288 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002289 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002290 for (i = 0; i < len;) {
2291 struct dirent64 *d = (struct dirent64 *) &buf[i];
John Hughesbdf48f52001-03-06 15:08:09 +00002292 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002293 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002294 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002295 d->d_ino,
2296 d->d_off);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002297 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002298 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002299 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002300 tprintf("d_reclen=%u, d_name=\"%s\"}",
2301 d->d_reclen, d->d_name);
2302 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002303 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002304 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002305 break;
2306 }
John Hughesbdf48f52001-03-06 15:08:09 +00002307 i += d->d_reclen;
2308 dents++;
2309 }
2310 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002311 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002312 else
2313 tprintf("/* %u entries */", dents);
2314 tprintf(", %lu", tcp->u_arg[2]);
2315 free(buf);
2316 return 0;
2317}
2318#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002319
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002320int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002321sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002322{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002323 if (exiting(tcp)) {
2324 if (syserror(tcp))
2325 tprintf("%#lx", tcp->u_arg[0]);
2326 else
2327 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2328 tprintf(", %lu", tcp->u_arg[1]);
2329 }
2330 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002331}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002332
2333#ifdef HAVE_SYS_ASYNCH_H
2334
2335int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002336sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002337{
2338 struct aio_result_t res;
2339
2340 if (entering(tcp)) {
2341 tprintf("%lu, ", tcp->u_arg[0]);
2342 } else {
2343 if (syserror(tcp))
2344 tprintf("%#lx", tcp->u_arg[1]);
2345 else
2346 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2347 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2348 printxval(whence, tcp->u_arg[4], "L_???");
2349 if (syserror(tcp) || tcp->u_arg[5] == 0
2350 || umove(tcp, tcp->u_arg[5], &res) < 0)
2351 tprintf(", %#lx", tcp->u_arg[5]);
2352 else
2353 tprintf(", {aio_return %d aio_errno %d}",
2354 res.aio_return, res.aio_errno);
2355 }
2356 return 0;
2357}
2358
2359int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002360sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002361{
2362 struct aio_result_t res;
2363
2364 if (entering(tcp)) {
2365 tprintf("%lu, ", tcp->u_arg[0]);
2366 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2367 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2368 printxval(whence, tcp->u_arg[4], "L_???");
2369 }
2370 else {
2371 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002372 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002373 else if (syserror(tcp)
2374 || umove(tcp, tcp->u_arg[5], &res) < 0)
2375 tprintf(", %#lx", tcp->u_arg[5]);
2376 else
2377 tprintf(", {aio_return %d aio_errno %d}",
2378 res.aio_return, res.aio_errno);
2379 }
2380 return 0;
2381}
2382
2383int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002384sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002385{
2386 if (entering(tcp))
2387 printtv(tcp, tcp->u_arg[0]);
2388 return 0;
2389}
2390
2391int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002392sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002393{
2394 struct aio_result_t res;
2395
2396 if (exiting(tcp)) {
2397 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002398 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002399 else if (syserror(tcp)
2400 || umove(tcp, tcp->u_arg[0], &res) < 0)
2401 tprintf("%#lx", tcp->u_arg[0]);
2402 else
2403 tprintf("{aio_return %d aio_errno %d}",
2404 res.aio_return, res.aio_errno);
2405 }
2406 return 0;
2407}
2408
2409#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002410
Roland McGratha4d48532005-06-08 20:45:28 +00002411static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002412#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002413 { XATTR_CREATE, "XATTR_CREATE" },
2414 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002415#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002416 { 0, NULL }
2417};
2418
Roland McGrath3292e222004-08-31 06:30:48 +00002419static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002420print_xattr_val(struct tcb *tcp, int failed,
2421 unsigned long arg,
2422 unsigned long insize,
2423 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002424{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002425 if (!failed) {
2426 unsigned long capacity = 4 * size + 1;
2427 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2428 if (buf == NULL || /* probably a bogus size argument */
2429 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2430 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002431 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002432 else {
2433 unsigned char *out = buf;
2434 unsigned char *in = &buf[3 * size];
2435 size_t i;
2436 for (i = 0; i < size; ++i) {
2437 if (isprint(in[i]))
2438 *out++ = in[i];
2439 else {
2440#define tohex(n) "0123456789abcdef"[n]
2441 *out++ = '\\';
2442 *out++ = 'x';
2443 *out++ = tohex(in[i] / 16);
2444 *out++ = tohex(in[i] % 16);
2445 }
2446 }
2447 /* Don't print terminating NUL if there is one. */
2448 if (i > 0 && in[i - 1] == '\0')
2449 out -= 4;
2450 *out = '\0';
2451 tprintf(", \"%s\", %ld", buf, insize);
2452 }
2453 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002454 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002455 if (failed)
2456 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002457}
2458
Roland McGrath186c5ac2002-12-15 23:58:23 +00002459int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002460sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002461{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002462 if (entering(tcp)) {
2463 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002464 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002465 printstr(tcp, tcp->u_arg[1], -1);
2466 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002467 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002468 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2469 }
2470 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002471}
2472
2473int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002474sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002475{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002476 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002477 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002478 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002479 printstr(tcp, tcp->u_arg[1], -1);
2480 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002481 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002482 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2483 }
2484 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002485}
2486
2487int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002488sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002489{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002490 if (entering(tcp)) {
2491 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002492 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002493 printstr(tcp, tcp->u_arg[1], -1);
2494 } else {
2495 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2496 tcp->u_rval);
2497 }
2498 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002499}
2500
2501int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002502sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002503{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002504 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002505 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002506 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002507 printstr(tcp, tcp->u_arg[1], -1);
2508 } else {
2509 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2510 tcp->u_rval);
2511 }
2512 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002513}
2514
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002515static void
2516print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2517{
2518 if (syserror(tcp)) {
2519 tprintf("%#lx", addr);
2520 } else {
2521 if (!addr) {
2522 tprints("NULL");
2523 } else {
2524 unsigned long len =
2525 (size < tcp->u_rval) ? size : tcp->u_rval;
2526 printstr(tcp, addr, len);
2527 }
2528 }
2529 tprintf(", %lu", size);
2530}
2531
Roland McGrath186c5ac2002-12-15 23:58:23 +00002532int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002533sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002534{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002535 if (entering(tcp)) {
2536 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002537 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002538 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002539 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002540 }
2541 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002542}
2543
2544int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002545sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002546{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002547 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002548 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002549 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002550 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002551 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002552 }
2553 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002554}
2555
2556int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002557sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002558{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002559 if (entering(tcp)) {
2560 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002561 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002562 printstr(tcp, tcp->u_arg[1], -1);
2563 }
2564 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002565}
2566
2567int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002568sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002569{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002570 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002571 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002572 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002573 printstr(tcp, tcp->u_arg[1], -1);
2574 }
2575 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002576}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002577
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002578static const struct xlat advise[] = {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002579 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2580 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2581 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2582 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2583 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2584 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2585 { 0, NULL }
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002586};
2587
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002588int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002589sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002590{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002591 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002592 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002593 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002594 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002595 argn = printllval(tcp, "%lld", 1);
2596 tprintf(", %ld, ", tcp->u_arg[argn++]);
2597 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002598 }
2599 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002600}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002601
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002602int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002603sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002604{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002605 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002606 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002607 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002608 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002609#if defined ARM || defined POWERPC
2610 argn = printllval(tcp, "%lld, ", 2);
2611#else
2612 argn = printllval(tcp, "%lld, ", 1);
2613#endif
2614 argn = printllval(tcp, "%lld, ", argn);
2615#if defined ARM || defined POWERPC
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002616 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002617#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002618 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002619#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002620 }
2621 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002622}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002623
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002624static const struct xlat inotify_modes[] = {
Dmitry V. Levind475c062011-03-03 01:02:41 +00002625 { 0x00000001, "IN_ACCESS" },
2626 { 0x00000002, "IN_MODIFY" },
2627 { 0x00000004, "IN_ATTRIB" },
2628 { 0x00000008, "IN_CLOSE_WRITE"},
2629 { 0x00000010, "IN_CLOSE_NOWRITE"},
2630 { 0x00000020, "IN_OPEN" },
2631 { 0x00000040, "IN_MOVED_FROM" },
2632 { 0x00000080, "IN_MOVED_TO" },
2633 { 0x00000100, "IN_CREATE" },
2634 { 0x00000200, "IN_DELETE" },
2635 { 0x00000400, "IN_DELETE_SELF"},
2636 { 0x00000800, "IN_MOVE_SELF" },
2637 { 0x00002000, "IN_UNMOUNT" },
2638 { 0x00004000, "IN_Q_OVERFLOW" },
2639 { 0x00008000, "IN_IGNORED" },
2640 { 0x01000000, "IN_ONLYDIR" },
2641 { 0x02000000, "IN_DONT_FOLLOW"},
2642 { 0x20000000, "IN_MASK_ADD" },
2643 { 0x40000000, "IN_ISDIR" },
2644 { 0x80000000, "IN_ONESHOT" },
2645 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002646};
2647
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002648static const struct xlat inotify_init_flags[] = {
2649 { 0x00000800, "IN_NONBLOCK" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002650 { 0x00080000, "IN_CLOEXEC" },
2651 { 0, NULL }
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002652};
2653
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002654int
2655sys_inotify_add_watch(struct tcb *tcp)
2656{
2657 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002658 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002659 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002660 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002661 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002662 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2663 }
2664 return 0;
2665}
2666
2667int
2668sys_inotify_rm_watch(struct tcb *tcp)
2669{
2670 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002671 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levinab1a70c2012-03-11 15:33:34 +00002672 tprintf(", %d", (int) tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002673 }
2674 return 0;
2675}
Roland McGrath96a96612008-05-20 04:56:18 +00002676
2677int
Mark Wielaardbab89402010-03-21 14:41:26 +01002678sys_inotify_init1(struct tcb *tcp)
2679{
2680 if (entering(tcp))
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002681 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
Mark Wielaardbab89402010-03-21 14:41:26 +01002682 return 0;
2683}
2684
2685int
Roland McGrath96a96612008-05-20 04:56:18 +00002686sys_fallocate(struct tcb *tcp)
2687{
2688 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002689 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002690 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002691 tprints(", ");
Roland McGrath96a96612008-05-20 04:56:18 +00002692 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002693 argn = printllval(tcp, "%llu, ", 2); /* offset */
2694 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002695 }
2696 return 0;
2697}
Dmitry V. Levin88293652012-03-09 21:02:19 +00002698
Dmitry V. Levinad0c01e2012-03-15 00:52:22 +00002699#ifndef SWAP_FLAG_PREFER
2700# define SWAP_FLAG_PREFER 0x8000
2701#endif
2702#ifndef SWAP_FLAG_DISCARD
2703# define SWAP_FLAG_DISCARD 0x10000
2704#endif
Dmitry V. Levin88293652012-03-09 21:02:19 +00002705static const struct xlat swap_flags[] = {
2706 { SWAP_FLAG_PREFER, "SWAP_FLAG_PREFER" },
2707 { SWAP_FLAG_DISCARD, "SWAP_FLAG_DISCARD" },
2708 { 0, NULL }
2709};
2710
2711int
2712sys_swapon(struct tcb *tcp)
2713{
2714 if (entering(tcp)) {
2715 int flags = tcp->u_arg[1];
2716 printpath(tcp, tcp->u_arg[0]);
2717 tprints(", ");
2718 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2719 "SWAP_FLAG_???");
2720 if (flags & SWAP_FLAG_PREFER)
2721 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);
2722 }
2723 return 0;
2724}