blob: 35f2b710f0347055c91bca9a0979e665a8960ff8 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include <dirent.h>
Dmitry V. Levin88293652012-03-09 21:02:19 +000033#include <sys/swap.h>
Roland McGrathc531e572008-08-01 01:13:10 +000034
Denys Vlasenko9472a272013-02-12 11:43:46 +010035#if defined(SPARC) || defined(SPARC64)
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000036struct stat {
37 unsigned short st_dev;
38 unsigned int st_ino;
39 unsigned short st_mode;
40 short st_nlink;
41 unsigned short st_uid;
42 unsigned short st_gid;
43 unsigned short st_rdev;
44 unsigned int st_size;
45 int st_atime;
46 unsigned int __unused1;
47 int st_mtime;
48 unsigned int __unused2;
49 int st_ctime;
50 unsigned int __unused3;
51 int st_blksize;
52 int st_blocks;
53 unsigned int __unused4[2];
54};
Denys Vlasenko84703742012-02-25 02:38:52 +010055# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +000056struct stat_sparc64 {
57 unsigned int st_dev;
58 unsigned long st_ino;
59 unsigned int st_mode;
60 unsigned int st_nlink;
61 unsigned int st_uid;
62 unsigned int st_gid;
63 unsigned int st_rdev;
64 long st_size;
65 long st_atime;
66 long st_mtime;
67 long st_ctime;
68 long st_blksize;
69 long st_blocks;
70 unsigned long __unused4[2];
71};
Denys Vlasenko84703742012-02-25 02:38:52 +010072# endif /* SPARC64 */
73# define stat kernel_stat
74# include <asm/stat.h>
75# undef stat
H.J. Lu35be5812012-04-16 13:00:01 +020076#elif defined(X32)
77struct stat {
78 unsigned long long st_dev;
79 unsigned long long st_ino;
80 unsigned long long st_nlink;
81
82 unsigned int st_mode;
83 unsigned int st_uid;
84 unsigned int st_gid;
85 unsigned int __pad0;
86 unsigned long long st_rdev;
87 long long st_size;
88 long long st_blksize;
89 long long st_blocks;
90
91 unsigned long long st_atime;
92 unsigned long long st_atime_nsec;
93 unsigned long long st_mtime;
94 unsigned long long st_mtime_nsec;
95 unsigned long long st_ctime;
96 unsigned long long st_ctime_nsec;
97 long long __unused[3];
98};
H.J. Lu085e4282012-04-17 11:05:04 -070099
100struct stat64 {
101 unsigned long long st_dev;
102 unsigned char __pad0[4];
103 unsigned long __st_ino;
104 unsigned int st_mode;
105 unsigned int st_nlink;
106 unsigned long st_uid;
107 unsigned long st_gid;
108 unsigned long long st_rdev;
109 unsigned char __pad3[4];
110 long long st_size;
111 unsigned long st_blksize;
112 unsigned long long st_blocks;
113 unsigned long st_atime;
114 unsigned long st_atime_nsec;
115 unsigned long st_mtime;
116 unsigned int st_mtime_nsec;
117 unsigned long st_ctime;
118 unsigned long st_ctime_nsec;
119 unsigned long long st_ino;
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000120} __attribute__((packed));
121# define HAVE_STAT64 1
Dmitry V. Levinbd2e28a2013-05-01 15:14:25 +0000122
123struct __old_kernel_stat {
124 unsigned short st_dev;
125 unsigned short st_ino;
126 unsigned short st_mode;
127 unsigned short st_nlink;
128 unsigned short st_uid;
129 unsigned short st_gid;
130 unsigned short st_rdev;
131 unsigned int st_size;
132 unsigned int st_atime;
133 unsigned int st_mtime;
134 unsigned int st_ctime;
135};
Denys Vlasenko84703742012-02-25 02:38:52 +0100136#else
137# undef dev_t
138# undef ino_t
139# undef mode_t
140# undef nlink_t
141# undef uid_t
142# undef gid_t
143# undef off_t
144# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100145# define dev_t __kernel_dev_t
146# define ino_t __kernel_ino_t
147# define mode_t __kernel_mode_t
148# define nlink_t __kernel_nlink_t
149# define uid_t __kernel_uid_t
150# define gid_t __kernel_gid_t
151# define off_t __kernel_off_t
152# define loff_t __kernel_loff_t
Wichert Akkermana6013701999-07-08 14:00:58 +0000153
Denys Vlasenko84703742012-02-25 02:38:52 +0100154# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +0000155
Denys Vlasenko84703742012-02-25 02:38:52 +0100156# undef dev_t
157# undef ino_t
158# undef mode_t
159# undef nlink_t
160# undef uid_t
161# undef gid_t
162# undef off_t
163# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100164# define dev_t dev_t
165# define ino_t ino_t
166# define mode_t mode_t
167# define nlink_t nlink_t
168# define uid_t uid_t
169# define gid_t gid_t
170# define off_t off_t
171# define loff_t loff_t
172#endif
173
174#ifdef HPPA /* asm-parisc/stat.h defines stat64 */
175# undef stat64
176#endif
177#define stat libc_stat
178#define stat64 libc_stat64
179#include <sys/stat.h>
180#undef stat
181#undef stat64
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100182/* These might be macros. */
Denys Vlasenko84703742012-02-25 02:38:52 +0100183#undef st_atime
184#undef st_mtime
185#undef st_ctime
186#ifdef HPPA
187# define stat64 hpux_stat64
188#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000189
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000190#include <fcntl.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000191#ifdef HAVE_SYS_VFS_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100192# include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000193#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +0000194#ifdef HAVE_LINUX_XATTR_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100195# include <linux/xattr.h>
Denys Vlasenkoed720fd2012-02-25 02:24:03 +0100196#else
Denys Vlasenko84703742012-02-25 02:38:52 +0100197# define XATTR_CREATE 1
198# define XATTR_REPLACE 2
Roland McGrath186c5ac2002-12-15 23:58:23 +0000199#endif
200
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000201#ifdef MAJOR_IN_SYSMACROS
Denys Vlasenko84703742012-02-25 02:38:52 +0100202# include <sys/sysmacros.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000203#endif
204
205#ifdef MAJOR_IN_MKDEV
Denys Vlasenko84703742012-02-25 02:38:52 +0100206# include <sys/mkdev.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000207#endif
208
209#ifdef HAVE_SYS_ASYNCH_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100210# include <sys/asynch.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000211#endif
212
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100213struct kernel_dirent {
214 unsigned long d_ino;
215 unsigned long d_off;
216 unsigned short d_reclen;
217 char d_name[1];
218};
219
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000220const struct xlat open_access_modes[] = {
221 { O_RDONLY, "O_RDONLY" },
222 { O_WRONLY, "O_WRONLY" },
223 { O_RDWR, "O_RDWR" },
224#ifdef O_ACCMODE
225 { O_ACCMODE, "O_ACCMODE" },
226#endif
227 { 0, NULL },
228};
229
230const struct xlat open_mode_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000231 { O_CREAT, "O_CREAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000232 { O_EXCL, "O_EXCL" },
233 { O_NOCTTY, "O_NOCTTY" },
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000234 { O_TRUNC, "O_TRUNC" },
235 { O_APPEND, "O_APPEND" },
236 { O_NONBLOCK, "O_NONBLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000237#ifdef O_SYNC
238 { O_SYNC, "O_SYNC" },
239#endif
240#ifdef O_ASYNC
241 { O_ASYNC, "O_ASYNC" },
242#endif
243#ifdef O_DSYNC
244 { O_DSYNC, "O_DSYNC" },
245#endif
246#ifdef O_RSYNC
247 { O_RSYNC, "O_RSYNC" },
248#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000249#if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000250 { O_NDELAY, "O_NDELAY" },
251#endif
252#ifdef O_PRIV
253 { O_PRIV, "O_PRIV" },
254#endif
255#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000256 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000257#endif
258#ifdef O_LARGEFILE
Roland McGrathfee836e2005-02-02 22:11:32 +0000259# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
260# undef O_LARGEFILE
261# ifdef SPARC64
262# define O_LARGEFILE 0x40000
263# elif defined X86_64 || defined S390X
264# define O_LARGEFILE 0100000
265# endif
266# endif
Roland McGrath663a8a02005-02-04 09:49:56 +0000267# ifdef O_LARGEFILE
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200268 { O_LARGEFILE, "O_LARGEFILE" },
Roland McGrath663a8a02005-02-04 09:49:56 +0000269# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000270#endif
271#ifdef O_DIRECTORY
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200272 { O_DIRECTORY, "O_DIRECTORY" },
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000273#endif
274#ifdef O_NOFOLLOW
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200275 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000276#endif
Roland McGrath1025c3e2005-05-09 07:40:35 +0000277#ifdef O_NOATIME
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200278 { O_NOATIME, "O_NOATIME" },
Roland McGrath1025c3e2005-05-09 07:40:35 +0000279#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000280#ifdef O_CLOEXEC
281 { O_CLOEXEC, "O_CLOEXEC" },
282#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000283#ifdef FNDELAY
284 { FNDELAY, "FNDELAY" },
285#endif
286#ifdef FAPPEND
287 { FAPPEND, "FAPPEND" },
288#endif
289#ifdef FMARK
290 { FMARK, "FMARK" },
291#endif
292#ifdef FDEFER
293 { FDEFER, "FDEFER" },
294#endif
295#ifdef FASYNC
296 { FASYNC, "FASYNC" },
297#endif
298#ifdef FSHLOCK
299 { FSHLOCK, "FSHLOCK" },
300#endif
301#ifdef FEXLOCK
302 { FEXLOCK, "FEXLOCK" },
303#endif
304#ifdef FCREAT
305 { FCREAT, "FCREAT" },
306#endif
307#ifdef FTRUNC
308 { FTRUNC, "FTRUNC" },
309#endif
310#ifdef FEXCL
311 { FEXCL, "FEXCL" },
312#endif
313#ifdef FNBIO
314 { FNBIO, "FNBIO" },
315#endif
316#ifdef FSYNC
317 { FSYNC, "FSYNC" },
318#endif
319#ifdef FNOCTTY
320 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000321#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000322#ifdef O_SHLOCK
323 { O_SHLOCK, "O_SHLOCK" },
324#endif
325#ifdef O_EXLOCK
326 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000327#endif
328 { 0, NULL },
329};
330
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000331#ifndef AT_FDCWD
332# define AT_FDCWD -100
333#endif
334
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000335/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
336 * extension to get the right value. We do this by declaring fd as int here.
337 */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000338static void
Dmitry V. Levin31382132011-03-04 05:08:02 +0300339print_dirfd(struct tcb *tcp, int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000340{
341 if (fd == AT_FDCWD)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200342 tprints("AT_FDCWD, ");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200343 else {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300344 printfd(tcp, fd);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200345 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300346 }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000347}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000348
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000349/*
350 * low bits of the open(2) flags define access mode,
351 * other bits are real flags.
352 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000353const char *
354sprint_open_modes(mode_t flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000355{
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100356 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000357 char *p;
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100358 char sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000359 const char *str;
360 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000361
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100362 sep = ' ';
363 p = stpcpy(outstr, "flags");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000364 str = xlookup(open_access_modes, flags & 3);
365 if (str) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100366 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200367 p = stpcpy(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000368 flags &= ~3;
369 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000370 return outstr;
371 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000372 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000373
374 for (x = open_mode_flags; x->str; x++) {
375 if ((flags & x->val) == x->val) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100376 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200377 p = stpcpy(p, x->str);
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000378 flags &= ~x->val;
379 if (!flags)
380 return outstr;
381 sep = '|';
382 }
383 }
384 /* flags is still nonzero */
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100385 *p++ = sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000386 sprintf(p, "%#x", flags);
387 return outstr;
388}
389
390void
391tprint_open_modes(mode_t flags)
392{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200393 tprints(sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000394}
395
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000396static int
397decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000398{
399 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000400 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200401 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000402 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000403 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000404 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000405 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000406 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000407 }
408 }
409 return 0;
410}
411
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000412int
413sys_open(struct tcb *tcp)
414{
415 return decode_open(tcp, 0);
416}
417
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000418int
419sys_openat(struct tcb *tcp)
420{
421 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300422 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000423 return decode_open(tcp, 1);
424}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000425
Denys Vlasenko9472a272013-02-12 11:43:46 +0100426#if defined(SPARC) || defined(SPARC64)
Roland McGratha4d48532005-06-08 20:45:28 +0000427static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000428 { 0, "O_RDWR" },
429 { 1, "O_RDONLY" },
430 { 2, "O_WRONLY" },
431 { 0x80, "O_NONBLOCK" },
432 { 8, "O_APPEND" },
433 { 0x100, "O_CREAT" },
434 { 0x200, "O_TRUNC" },
435 { 0x400, "O_EXCL" },
436 { 0x800, "O_NOCTTY" },
437 { 0x10, "O_SYNC" },
438 { 0x40, "O_DSYNC" },
439 { 0x8000, "O_RSYNC" },
440 { 4, "O_NDELAY" },
441 { 0x1000, "O_PRIV" },
442 { 0, NULL },
443};
444
445int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000446solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000447{
448 if (entering(tcp)) {
449 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200450 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000451 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000452 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000453 if (tcp->u_arg[1] & 0x100) {
454 /* mode */
455 tprintf(", %#lo", tcp->u_arg[2]);
456 }
457 }
458 return 0;
459}
460
461#endif
462
463int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000464sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000465{
466 if (entering(tcp)) {
467 printpath(tcp, tcp->u_arg[0]);
468 tprintf(", %#lo", tcp->u_arg[1]);
469 }
470 return 0;
471}
472
Roland McGrathd9f816f2004-09-04 03:39:20 +0000473static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000474 { F_OK, "F_OK", },
475 { R_OK, "R_OK" },
476 { W_OK, "W_OK" },
477 { X_OK, "X_OK" },
478#ifdef EFF_ONLY_OK
479 { EFF_ONLY_OK, "EFF_ONLY_OK" },
480#endif
481#ifdef EX_OK
482 { EX_OK, "EX_OK" },
483#endif
484 { 0, NULL },
485};
486
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000487static int
488decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000489{
490 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000491 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200492 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000493 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000494 }
495 return 0;
496}
497
498int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000499sys_access(struct tcb *tcp)
500{
501 return decode_access(tcp, 0);
502}
503
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000504int
505sys_faccessat(struct tcb *tcp)
506{
507 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300508 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000509 return decode_access(tcp, 1);
510}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000511
512int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000513sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000514{
515 if (entering(tcp)) {
516 tprintf("%#lo", tcp->u_arg[0]);
517 }
518 return RVAL_OCTAL;
519}
520
Denys Vlasenko86738a22013-02-17 14:31:55 +0100521const struct xlat whence_codes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522 { SEEK_SET, "SEEK_SET" },
523 { SEEK_CUR, "SEEK_CUR" },
524 { SEEK_END, "SEEK_END" },
Denys Vlasenko86738a22013-02-17 14:31:55 +0100525#ifdef SEEK_DATA
526 { SEEK_DATA, "SEEK_DATA" },
527#endif
528#ifdef SEEK_HOLE
529 { SEEK_HOLE, "SEEK_HOLE" },
530#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000531 { 0, NULL },
532};
533
Denys Vlasenko386b8712013-02-17 01:38:14 +0100534/* Linux kernel has exactly one version of lseek:
535 * fs/read_write.c::SYSCALL_DEFINE3(lseek, unsigned, fd, off_t, offset, unsigned, origin)
536 * In kernel, off_t is always the same as (kernel's) long
537 * (see include/uapi/asm-generic/posix_types.h),
538 * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument.
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100539 * Use test/x32_lseek.c to test lseek decoding.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100540 */
H.J. Luc933f272012-04-16 17:41:13 +0200541#if defined(LINUX_MIPSN32) || defined(X32)
Roland McGrath542c2c62008-05-20 01:11:56 +0000542int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000543sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000544{
545 long long offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100546 int whence;
Roland McGrath542c2c62008-05-20 01:11:56 +0000547
548 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300549 printfd(tcp, tcp->u_arg[0]);
Roland McGrath542c2c62008-05-20 01:11:56 +0000550 offset = tcp->ext_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100551 whence = tcp->u_arg[2];
552 if (whence == SEEK_SET)
553 tprintf(", %llu, ", offset);
Roland McGrath542c2c62008-05-20 01:11:56 +0000554 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100555 tprintf(", %lld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100556 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath542c2c62008-05-20 01:11:56 +0000557 }
H.J. Ludd0130b2012-04-16 12:16:45 +0200558 return RVAL_LUDECIMAL;
Roland McGrath542c2c62008-05-20 01:11:56 +0000559}
H.J. Ludd0130b2012-04-16 12:16:45 +0200560#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000561int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000562sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000563{
Denys Vlasenko06121762013-02-17 20:08:50 +0100564 long offset;
Denys Vlasenko386b8712013-02-17 01:38:14 +0100565 int whence;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000566
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000567 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300568 printfd(tcp, tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000569 offset = tcp->u_arg[1];
Denys Vlasenko386b8712013-02-17 01:38:14 +0100570 whence = tcp->u_arg[2];
571 if (whence == SEEK_SET)
572 tprintf(", %lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000573 else
Denys Vlasenko386b8712013-02-17 01:38:14 +0100574 tprintf(", %ld, ", offset);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100575 printxval(whence_codes, whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000576 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000577 return RVAL_UDECIMAL;
578}
John Hughes5a826b82001-03-07 13:21:24 +0000579#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000580
Denys Vlasenko386b8712013-02-17 01:38:14 +0100581/* llseek syscall takes explicitly two ulong arguments hi, lo,
582 * rather than one 64-bit argument for which LONG_LONG works
583 * appropriate for the native byte order.
584 *
585 * See kernel's fs/read_write.c::SYSCALL_DEFINE5(llseek, ...)
586 *
587 * hi,lo are "unsigned longs" and combined exactly this way in kernel:
588 * ((loff_t) hi << 32) | lo
Denys Vlasenko09a87ae2013-02-17 13:17:49 +0100589 * Note that for architectures with kernel's long wider than userspace long
Denys Vlasenko386b8712013-02-17 01:38:14 +0100590 * (such as x32), combining code will use *kernel's*, i.e. *wide* longs
Denys Vlasenko06121762013-02-17 20:08:50 +0100591 * for hi and lo. We would need to use tcp->ext_arg[N] on x32...
592 * ...however, x32 (and x86_64) does not _have_ llseek syscall as such.
Denys Vlasenko386b8712013-02-17 01:38:14 +0100593 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000594int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000595sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000596{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000597 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300598 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000599 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300600 tprintf(", %llu, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100601 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300602 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000603 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300604 tprintf(", %lld, ",
Denys Vlasenko386b8712013-02-17 01:38:14 +0100605 ((long long) tcp->u_arg[1]) << 32 |
Dmitry V. Levin31382132011-03-04 05:08:02 +0300606 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000607 }
608 else {
Denys Vlasenko386b8712013-02-17 01:38:14 +0100609 long long off;
Denys Vlasenko1d632462009-04-14 12:51:00 +0000610 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
611 tprintf("%#lx, ", tcp->u_arg[3]);
612 else
613 tprintf("[%llu], ", off);
Denys Vlasenko782d90f2013-02-17 12:47:44 +0100614 printxval(whence_codes, tcp->u_arg[4], "SEEK_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000615 }
616 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000617}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000618
619int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000620sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000621{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000622 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100623 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300624 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +0200625 argn = printllval(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100626 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000627 }
628 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000629}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000630
631int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000632sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000633{
634 if (entering(tcp)) {
635 printpath(tcp, tcp->u_arg[0]);
636 tprintf(", %lu", tcp->u_arg[1]);
637 }
638 return 0;
639}
640
Denys Vlasenko8435d672013-02-18 15:47:57 +0100641#if _LFS64_LARGEFILE
John Hughes96f51472001-03-06 16:50:41 +0000642int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000643sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000644{
645 if (entering(tcp)) {
646 printpath(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100647 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000648 }
649 return 0;
650}
651#endif
652
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000653int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000654sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000655{
656 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300657 printfd(tcp, tcp->u_arg[0]);
658 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000659 }
660 return 0;
661}
662
Denys Vlasenko8435d672013-02-18 15:47:57 +0100663#if _LFS64_LARGEFILE
John Hughes96f51472001-03-06 16:50:41 +0000664int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000665sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000666{
667 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300668 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +0200669 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000670 }
671 return 0;
672}
673#endif
674
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000675/* several stats */
676
Roland McGrathd9f816f2004-09-04 03:39:20 +0000677static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000678 { S_IFREG, "S_IFREG" },
679 { S_IFSOCK, "S_IFSOCK" },
680 { S_IFIFO, "S_IFIFO" },
681 { S_IFLNK, "S_IFLNK" },
682 { S_IFDIR, "S_IFDIR" },
683 { S_IFBLK, "S_IFBLK" },
684 { S_IFCHR, "S_IFCHR" },
685 { 0, NULL },
686};
687
Roland McGrathf9c49b22004-10-06 22:11:54 +0000688static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000689sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000690{
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100691 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
692 + sizeof(int)*3
693 + /*paranoia:*/ 8];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000694 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000695
696 if ((mode & S_IFMT) == 0)
697 s = "";
698 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
699 sprintf(buf, "%#o", mode);
700 return buf;
701 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100702 s = buf + sprintf(buf, "%s%s%s%s", s,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000703 (mode & S_ISUID) ? "|S_ISUID" : "",
704 (mode & S_ISGID) ? "|S_ISGID" : "",
705 (mode & S_ISVTX) ? "|S_ISVTX" : "");
706 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
707 if (mode)
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100708 sprintf((char*)s, "|%#o", mode);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000709 s = (*buf == '|') ? buf + 1 : buf;
710 return *s ? s : "0";
711}
712
713static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000714sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000715{
716 struct tm *tmp;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100717 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000718
719 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000720 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000721 return buf;
722 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200723 tmp = localtime(&t);
724 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000725 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
726 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
727 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
728 else
729 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
730
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000731 return buf;
732}
733
Denys Vlasenko9472a272013-02-12 11:43:46 +0100734#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000735typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000736 int tv_sec;
737 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000738} timestruct_t;
739
740struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000741 unsigned st_dev;
742 int st_pad1[3]; /* network id */
743 unsigned st_ino;
744 unsigned st_mode;
745 unsigned st_nlink;
746 unsigned st_uid;
747 unsigned st_gid;
748 unsigned st_rdev;
749 int st_pad2[2];
750 int st_size;
751 int st_pad3; /* st_size, off_t expansion */
752 timestruct_t st_atime;
753 timestruct_t st_mtime;
754 timestruct_t st_ctime;
755 int st_blksize;
756 int st_blocks;
757 char st_fstype[16];
758 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000759};
760
761static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000762printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000763{
764 struct solstat statbuf;
765
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000766 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200767 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000768 return;
769 }
770 if (!abbrev(tcp)) {
771 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
772 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
773 (unsigned long) (statbuf.st_dev & 0x3ffff),
774 (unsigned long) statbuf.st_ino,
775 sprintmode(statbuf.st_mode));
776 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
777 (unsigned long) statbuf.st_nlink,
778 (unsigned long) statbuf.st_uid,
779 (unsigned long) statbuf.st_gid);
780 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
781 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
782 }
783 else
784 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
785 switch (statbuf.st_mode & S_IFMT) {
786 case S_IFCHR: case S_IFBLK:
787 tprintf("st_rdev=makedev(%lu, %lu), ",
788 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
789 (unsigned long) (statbuf.st_rdev & 0x3ffff));
790 break;
791 default:
792 tprintf("st_size=%u, ", statbuf.st_size);
793 break;
794 }
795 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000796 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
797 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
798 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000799 }
800 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200801 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000802}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000803
Denys Vlasenko9472a272013-02-12 11:43:46 +0100804# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000805static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000806printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000807{
808 struct stat_sparc64 statbuf;
809
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000810 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200811 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000812 return;
813 }
814
815 if (!abbrev(tcp)) {
816 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
817 (unsigned long) major(statbuf.st_dev),
818 (unsigned long) minor(statbuf.st_dev),
819 (unsigned long) statbuf.st_ino,
820 sprintmode(statbuf.st_mode));
821 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
822 (unsigned long) statbuf.st_nlink,
823 (unsigned long) statbuf.st_uid,
824 (unsigned long) statbuf.st_gid);
825 tprintf("st_blksize=%lu, ",
826 (unsigned long) statbuf.st_blksize);
827 tprintf("st_blocks=%lu, ",
828 (unsigned long) statbuf.st_blocks);
829 }
830 else
831 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
832 switch (statbuf.st_mode & S_IFMT) {
833 case S_IFCHR: case S_IFBLK:
834 tprintf("st_rdev=makedev(%lu, %lu), ",
835 (unsigned long) major(statbuf.st_rdev),
836 (unsigned long) minor(statbuf.st_rdev));
837 break;
838 default:
839 tprintf("st_size=%lu, ", statbuf.st_size);
840 break;
841 }
842 if (!abbrev(tcp)) {
843 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
844 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100845 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000846 }
847 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200848 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000849}
Denys Vlasenko9472a272013-02-12 11:43:46 +0100850# endif /* SPARC64 */
851#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000852
Denys Vlasenko84703742012-02-25 02:38:52 +0100853#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200854struct stat_powerpc32 {
855 unsigned int st_dev;
856 unsigned int st_ino;
857 unsigned int st_mode;
858 unsigned short st_nlink;
859 unsigned int st_uid;
860 unsigned int st_gid;
861 unsigned int st_rdev;
862 unsigned int st_size;
863 unsigned int st_blksize;
864 unsigned int st_blocks;
865 unsigned int st_atime;
866 unsigned int st_atime_nsec;
867 unsigned int st_mtime;
868 unsigned int st_mtime_nsec;
869 unsigned int st_ctime;
870 unsigned int st_ctime_nsec;
871 unsigned int __unused4;
872 unsigned int __unused5;
873};
874
875static void
876printstat_powerpc32(struct tcb *tcp, long addr)
877{
878 struct stat_powerpc32 statbuf;
879
880 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200881 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200882 return;
883 }
884
885 if (!abbrev(tcp)) {
886 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
887 major(statbuf.st_dev), minor(statbuf.st_dev),
888 statbuf.st_ino,
889 sprintmode(statbuf.st_mode));
890 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
891 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
892 tprintf("st_blksize=%u, ", statbuf.st_blksize);
893 tprintf("st_blocks=%u, ", statbuf.st_blocks);
894 }
895 else
896 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
897 switch (statbuf.st_mode & S_IFMT) {
898 case S_IFCHR: case S_IFBLK:
899 tprintf("st_rdev=makedev(%lu, %lu), ",
900 (unsigned long) major(statbuf.st_rdev),
901 (unsigned long) minor(statbuf.st_rdev));
902 break;
903 default:
904 tprintf("st_size=%u, ", statbuf.st_size);
905 break;
906 }
907 if (!abbrev(tcp)) {
908 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
909 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100910 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200911 }
912 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200913 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200914}
Denys Vlasenko84703742012-02-25 02:38:52 +0100915#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200916
Roland McGratha4d48532005-06-08 20:45:28 +0000917static const struct xlat fileflags[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000918 { 0, NULL },
919};
920
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000921static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000922realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000923{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000924 if (!abbrev(tcp)) {
925 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
926 (unsigned long) major(statbuf->st_dev),
927 (unsigned long) minor(statbuf->st_dev),
928 (unsigned long) statbuf->st_ino,
929 sprintmode(statbuf->st_mode));
930 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
931 (unsigned long) statbuf->st_nlink,
932 (unsigned long) statbuf->st_uid,
933 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000934#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000935 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
936#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000937#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000938 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
939#endif
940 }
941 else
942 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
943 switch (statbuf->st_mode & S_IFMT) {
944 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000945#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000946 tprintf("st_rdev=makedev(%lu, %lu), ",
947 (unsigned long) major(statbuf->st_rdev),
948 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000949#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000950 tprintf("st_size=makedev(%lu, %lu), ",
951 (unsigned long) major(statbuf->st_size),
952 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000953#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000954 break;
955 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000956 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000957 break;
958 }
959 if (!abbrev(tcp)) {
960 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
961 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
962 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000963#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200964 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000965 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000966#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000967#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000968 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
969#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000970#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000971 tprintf(", st_level=%ld", statbuf->st_level);
972#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000973#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000974 tprintf(", st_fstype=%.*s",
975 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
976#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000977#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000978 tprintf(", st_gen=%u", statbuf->st_gen);
979#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200980 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000981 }
982 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200983 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000984}
985
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000986#ifndef X32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000987static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000988printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000989{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000990 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000991
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000992 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200993 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000994 return;
995 }
996 if (syserror(tcp) || !verbose(tcp)) {
997 tprintf("%#lx", addr);
998 return;
999 }
1000
Denys Vlasenko9472a272013-02-12 11:43:46 +01001001#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +00001002 if (current_personality == 1) {
1003 printstatsol(tcp, addr);
1004 return;
1005 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +00001006#ifdef SPARC64
1007 else if (current_personality == 2) {
1008 printstat_sparc64(tcp, addr);
1009 return;
1010 }
1011#endif
Denys Vlasenko9472a272013-02-12 11:43:46 +01001012#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001013
Denys Vlasenko84703742012-02-25 02:38:52 +01001014#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +02001015 if (current_personality == 1) {
1016 printstat_powerpc32(tcp, addr);
1017 return;
1018 }
1019#endif
1020
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001021 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001022 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001023 return;
1024 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001025
1026 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001027}
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001028#else /* X32 */
1029# define printstat printstat64
1030#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001031
Denys Vlasenko84703742012-02-25 02:38:52 +01001032#if !defined HAVE_STAT64 && defined X86_64
Roland McGrathe6d0f712007-08-07 01:22:49 +00001033/*
1034 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1035 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1036 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1037 * __GNUC__ is needed for the required __attribute__ below.
1038 */
1039struct stat64 {
1040 unsigned long long st_dev;
1041 unsigned char __pad0[4];
1042 unsigned int __st_ino;
1043 unsigned int st_mode;
1044 unsigned int st_nlink;
1045 unsigned int st_uid;
1046 unsigned int st_gid;
1047 unsigned long long st_rdev;
1048 unsigned char __pad3[4];
1049 long long st_size;
1050 unsigned int st_blksize;
1051 unsigned long long st_blocks;
1052 unsigned int st_atime;
1053 unsigned int st_atime_nsec;
1054 unsigned int st_mtime;
1055 unsigned int st_mtime_nsec;
1056 unsigned int st_ctime;
1057 unsigned int st_ctime_nsec;
1058 unsigned long long st_ino;
1059} __attribute__((packed));
1060# define HAVE_STAT64 1
1061# define STAT64_SIZE 96
1062#endif
1063
Wichert Akkermanc7926982000-04-10 22:22:31 +00001064#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001065static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001066printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001067{
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001068#ifdef X32
1069 struct stat statbuf;
1070#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001071 struct stat64 statbuf;
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001072#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001073
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001074#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001075 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1076#endif
1077
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001078 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001079 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001080 return;
1081 }
1082 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001083 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001084 return;
1085 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001086
Denys Vlasenko9472a272013-02-12 11:43:46 +01001087#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001088 if (current_personality == 1) {
1089 printstatsol(tcp, addr);
1090 return;
1091 }
1092# ifdef SPARC64
1093 else if (current_personality == 2) {
1094 printstat_sparc64(tcp, addr);
1095 return;
1096 }
1097# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +01001098#endif /* SPARC[64] */
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001099
Denys Vlasenko84703742012-02-25 02:38:52 +01001100#if defined X86_64
H.J. Lu35be5812012-04-16 13:00:01 +02001101 if (current_personality != 1) {
Andreas Schwab61b74352009-10-16 11:37:13 +02001102 printstat(tcp, addr);
1103 return;
1104 }
1105#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +00001106
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001107 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001108 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001109 return;
1110 }
1111
1112 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001113#ifdef HAVE_LONG_LONG
1114 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1115#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001116 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001117#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001118 (unsigned long) major(statbuf.st_dev),
1119 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001120#ifdef HAVE_LONG_LONG
1121 (unsigned long long) statbuf.st_ino,
1122#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001123 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001124#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001125 sprintmode(statbuf.st_mode));
1126 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1127 (unsigned long) statbuf.st_nlink,
1128 (unsigned long) statbuf.st_uid,
1129 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001130#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001131 tprintf("st_blksize=%lu, ",
1132 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001133#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1134#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001135 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001136#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001137 }
1138 else
1139 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1140 switch (statbuf.st_mode & S_IFMT) {
1141 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001142#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001143 tprintf("st_rdev=makedev(%lu, %lu), ",
1144 (unsigned long) major(statbuf.st_rdev),
1145 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001146#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001147 tprintf("st_size=makedev(%lu, %lu), ",
1148 (unsigned long) major(statbuf.st_size),
1149 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001150#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001151 break;
1152 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001153#ifdef HAVE_LONG_LONG
1154 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1155#else
1156 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1157#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001158 break;
1159 }
1160 if (!abbrev(tcp)) {
1161 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1162 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001163 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001164#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001165 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001166 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001167#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001168#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001169 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1170#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001171#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001172 tprintf(", st_level=%ld", statbuf.st_level);
1173#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001174#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001175 tprintf(", st_fstype=%.*s",
1176 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1177#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001178#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001179 tprintf(", st_gen=%u", statbuf.st_gen);
1180#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001181 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001182 }
1183 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001184 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001185}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001186#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001187
Denys Vlasenko8435d672013-02-18 15:47:57 +01001188#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001189static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001190convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001191{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001192 newbuf->st_dev = oldbuf->st_dev;
1193 newbuf->st_ino = oldbuf->st_ino;
1194 newbuf->st_mode = oldbuf->st_mode;
1195 newbuf->st_nlink = oldbuf->st_nlink;
1196 newbuf->st_uid = oldbuf->st_uid;
1197 newbuf->st_gid = oldbuf->st_gid;
1198 newbuf->st_rdev = oldbuf->st_rdev;
1199 newbuf->st_size = oldbuf->st_size;
1200 newbuf->st_atime = oldbuf->st_atime;
1201 newbuf->st_mtime = oldbuf->st_mtime;
1202 newbuf->st_ctime = oldbuf->st_ctime;
1203 newbuf->st_blksize = 0; /* not supported in old_stat */
1204 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001205}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001206
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001207static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001208printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001209{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001210 struct __old_kernel_stat statbuf;
1211 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001212
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001213 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001214 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001215 return;
1216 }
1217 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001218 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001219 return;
1220 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001221
Denys Vlasenko9472a272013-02-12 11:43:46 +01001222# if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001223 if (current_personality == 1) {
1224 printstatsol(tcp, addr);
1225 return;
1226 }
Denys Vlasenko84703742012-02-25 02:38:52 +01001227# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001228
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001229 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001230 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001231 return;
1232 }
1233
1234 convertoldstat(&statbuf, &newstatbuf);
1235 realprintstat(tcp, &newstatbuf);
1236}
Denys Vlasenko84703742012-02-25 02:38:52 +01001237#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001238
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001239int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001240sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001241{
1242 if (entering(tcp)) {
1243 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001244 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001245 } else {
1246 printstat(tcp, tcp->u_arg[1]);
1247 }
1248 return 0;
1249}
1250
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001251#ifdef X32
1252static void
1253printstat64_x32(struct tcb *tcp, long addr)
1254{
1255 struct stat64 statbuf;
1256
1257 if (!addr) {
1258 tprints("NULL");
1259 return;
1260 }
1261 if (syserror(tcp) || !verbose(tcp)) {
1262 tprintf("%#lx", addr);
1263 return;
1264 }
1265
1266 if (umove(tcp, addr, &statbuf) < 0) {
1267 tprints("{...}");
1268 return;
1269 }
1270
1271 if (!abbrev(tcp)) {
1272 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1273 (unsigned long) major(statbuf.st_dev),
1274 (unsigned long) minor(statbuf.st_dev),
1275 (unsigned long long) statbuf.st_ino,
1276 sprintmode(statbuf.st_mode));
1277 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1278 (unsigned long) statbuf.st_nlink,
1279 (unsigned long) statbuf.st_uid,
1280 (unsigned long) statbuf.st_gid);
1281 tprintf("st_blksize=%lu, ",
1282 (unsigned long) statbuf.st_blksize);
1283 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1284 }
1285 else
1286 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1287 switch (statbuf.st_mode & S_IFMT) {
1288 case S_IFCHR: case S_IFBLK:
1289 tprintf("st_rdev=makedev(%lu, %lu), ",
1290 (unsigned long) major(statbuf.st_rdev),
1291 (unsigned long) minor(statbuf.st_rdev));
1292 break;
1293 default:
1294 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1295 break;
1296 }
1297 if (!abbrev(tcp)) {
1298 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1299 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1300 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1301 tprints("}");
1302 }
1303 else
1304 tprints("...}");
1305}
1306#endif /* X32 */
1307
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001308int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001309sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001310{
1311#ifdef HAVE_STAT64
1312 if (entering(tcp)) {
1313 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001314 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001315 } else {
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001316# ifdef X32
1317 printstat64_x32(tcp, tcp->u_arg[1]);
1318# else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001319 printstat64(tcp, tcp->u_arg[1]);
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001320# endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001321 }
1322 return 0;
1323#else
1324 return printargs(tcp);
1325#endif
1326}
1327
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001328#ifndef AT_SYMLINK_NOFOLLOW
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001329# define AT_SYMLINK_NOFOLLOW 0x100
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001330#endif
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001331#ifndef AT_REMOVEDIR
1332# define AT_REMOVEDIR 0x200
1333#endif
1334#ifndef AT_SYMLINK_FOLLOW
1335# define AT_SYMLINK_FOLLOW 0x400
1336#endif
1337#ifndef AT_NO_AUTOMOUNT
1338# define AT_NO_AUTOMOUNT 0x800
1339#endif
1340#ifndef AT_EMPTY_PATH
1341# define AT_EMPTY_PATH 0x1000
1342#endif
1343
1344static const struct xlat at_flags[] = {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001345 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001346 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1347 { AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" },
1348 { AT_NO_AUTOMOUNT, "AT_NO_AUTOMOUNT" },
1349 { AT_EMPTY_PATH, "AT_EMPTY_PATH" },
1350 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001351};
1352
1353int
1354sys_newfstatat(struct tcb *tcp)
1355{
1356 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001357 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001358 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001359 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001360 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001361#ifdef POWERPC64
1362 if (current_personality == 0)
1363 printstat(tcp, tcp->u_arg[2]);
1364 else
1365 printstat64(tcp, tcp->u_arg[2]);
1366#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001367 printstat64(tcp, tcp->u_arg[2]);
1368#else
1369 printstat(tcp, tcp->u_arg[2]);
1370#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001371 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001372 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001373 }
1374 return 0;
1375}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001376
Denys Vlasenko8435d672013-02-18 15:47:57 +01001377#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001378int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001379sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001380{
1381 if (entering(tcp)) {
1382 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001383 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001384 } else {
1385 printoldstat(tcp, tcp->u_arg[1]);
1386 }
1387 return 0;
1388}
Denys Vlasenko84703742012-02-25 02:38:52 +01001389#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001390
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001391int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001392sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001393{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001394 if (entering(tcp)) {
1395 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001396 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001397 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001398 printstat(tcp, tcp->u_arg[1]);
1399 }
1400 return 0;
1401}
1402
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001403int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001404sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001405{
1406#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001407 if (entering(tcp)) {
1408 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001409 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001410 } else {
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001411# ifdef X32
1412 printstat64_x32(tcp, tcp->u_arg[1]);
1413# else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001414 printstat64(tcp, tcp->u_arg[1]);
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +00001415# endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001416 }
1417 return 0;
1418#else
1419 return printargs(tcp);
1420#endif
1421}
1422
Denys Vlasenko8435d672013-02-18 15:47:57 +01001423#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001424int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001425sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001426{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001427 if (entering(tcp)) {
1428 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001429 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001430 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001431 printoldstat(tcp, tcp->u_arg[1]);
1432 }
1433 return 0;
1434}
Denys Vlasenko84703742012-02-25 02:38:52 +01001435#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001436
Denys Vlasenko9472a272013-02-12 11:43:46 +01001437#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001438
1439int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001440sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001441{
1442 if (entering(tcp)) {
1443 tprintf("%ld, ", tcp->u_arg[0]);
1444 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001445 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001446 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001447# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001448 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001449 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001450 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001451# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001452 printstat(tcp, tcp->u_arg[2]);
1453 }
1454 return 0;
1455}
1456
1457int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001458sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001459{
1460 if (entering(tcp))
1461 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1462 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001463# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001464 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001465 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001466 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001467# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001468 printstat(tcp, tcp->u_arg[2]);
1469 }
1470 return 0;
1471}
1472
1473int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001474sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001475{
1476 if (entering(tcp)) {
1477 tprintf("%ld, ", tcp->u_arg[0]);
1478 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001479 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001480 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001481# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001482 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001483 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001484 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001485# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001486 printstat(tcp, tcp->u_arg[2]);
1487 }
1488 return 0;
1489}
1490
1491int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001492sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001493{
1494 int mode = tcp->u_arg[2];
1495
1496 if (entering(tcp)) {
1497 tprintf("%ld, ", tcp->u_arg[0]);
1498 printpath(tcp, tcp->u_arg[1]);
1499 tprintf(", %s", sprintmode(mode));
1500 switch (mode & S_IFMT) {
1501 case S_IFCHR: case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001502 tprintf(", makedev(%lu, %lu)",
1503 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1504 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001505 break;
1506 default:
1507 break;
1508 }
1509 }
1510 return 0;
1511}
1512
Denys Vlasenko84703742012-02-25 02:38:52 +01001513# ifdef HAVE_SYS_ACL_H
Wichert Akkerman8829a551999-06-11 13:18:40 +00001514
Denys Vlasenko84703742012-02-25 02:38:52 +01001515# include <sys/acl.h>
Wichert Akkerman8829a551999-06-11 13:18:40 +00001516
Roland McGratha4d48532005-06-08 20:45:28 +00001517static const struct xlat aclcmds[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001518# ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001519 { SETACL, "SETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001520# endif
1521# ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001522 { GETACL, "GETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001523# endif
1524# ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001525 { GETACLCNT, "GETACLCNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001526# endif
1527# ifdef ACL_GET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001528 { ACL_GET, "ACL_GET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001529# endif
1530# ifdef ACL_SET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001531 { ACL_SET, "ACL_SET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001532# endif
1533# ifdef ACL_CNT
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001534 { ACL_CNT, "ACL_CNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001535# endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001536 { 0, NULL },
1537};
1538
1539int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001540sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001541{
1542 if (entering(tcp)) {
1543 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001544 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001545 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1546 tprintf(", %ld", tcp->u_arg[2]);
1547 /*
1548 * FIXME - dump out the list of aclent_t's pointed to
1549 * by "tcp->u_arg[3]" if it's not NULL.
1550 */
1551 if (tcp->u_arg[3])
1552 tprintf(", %#lx", tcp->u_arg[3]);
1553 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001554 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001555 }
1556 return 0;
1557}
1558
Wichert Akkerman8829a551999-06-11 13:18:40 +00001559int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001560sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001561{
1562 if (entering(tcp)) {
1563 tprintf("%ld, ", tcp->u_arg[0]);
1564 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1565 tprintf(", %ld", tcp->u_arg[2]);
1566 /*
1567 * FIXME - dump out the list of aclent_t's pointed to
1568 * by "tcp->u_arg[3]" if it's not NULL.
1569 */
1570 if (tcp->u_arg[3])
1571 tprintf(", %#lx", tcp->u_arg[3]);
1572 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001573 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001574 }
1575 return 0;
1576}
1577
Roland McGratha4d48532005-06-08 20:45:28 +00001578static const struct xlat aclipc[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001579# ifdef IPC_SHM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001580 { IPC_SHM, "IPC_SHM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001581# endif
1582# ifdef IPC_SEM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001583 { IPC_SEM, "IPC_SEM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001584# endif
1585# ifdef IPC_MSG
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001586 { IPC_MSG, "IPC_MSG" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001587# endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001588 { 0, NULL },
1589};
1590
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001591int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001592sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001593{
1594 if (entering(tcp)) {
1595 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1596 tprintf(", %#lx, ", tcp->u_arg[1]);
1597 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1598 tprintf(", %ld", tcp->u_arg[3]);
1599 /*
1600 * FIXME - dump out the list of aclent_t's pointed to
1601 * by "tcp->u_arg[4]" if it's not NULL.
1602 */
1603 if (tcp->u_arg[4])
1604 tprintf(", %#lx", tcp->u_arg[4]);
1605 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001606 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001607 }
1608 return 0;
1609}
1610
Denys Vlasenko84703742012-02-25 02:38:52 +01001611# endif /* HAVE_SYS_ACL_H */
Wichert Akkerman8829a551999-06-11 13:18:40 +00001612
Denys Vlasenko9472a272013-02-12 11:43:46 +01001613#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001614
Roland McGrathd9f816f2004-09-04 03:39:20 +00001615static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001616 { 0x73757245, "CODA_SUPER_MAGIC" },
1617 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1618 { 0x1373, "DEVFS_SUPER_MAGIC" },
1619 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1620 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001621 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1622 { 0xef53, "EXT2_SUPER_MAGIC" },
1623 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001624 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001625 { 0x9660, "ISOFS_SUPER_MAGIC" },
1626 { 0x137f, "MINIX_SUPER_MAGIC" },
1627 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001628 { 0x2468, "MINIX2_SUPER_MAGIC" },
1629 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001630 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001631 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001632 { 0x6969, "NFS_SUPER_MAGIC" },
1633 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001634 { 0x002f, "QNX4_SUPER_MAGIC" },
1635 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1636 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1637 { 0x517b, "SMB_SUPER_MAGIC" },
1638 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1639 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1640 { 0x00011954, "UFS_MAGIC" },
1641 { 0x54190100, "UFS_CIGAM" },
1642 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001643 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001644 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001645 { 0, NULL },
1646};
1647
Roland McGrathf9c49b22004-10-06 22:11:54 +00001648static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001649sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001650{
1651 static char buf[32];
Roland McGrathf9c49b22004-10-06 22:11:54 +00001652 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001653
1654 s = xlookup(fsmagic, magic);
1655 if (s) {
1656 sprintf(buf, "\"%s\"", s);
1657 return buf;
1658 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001659 sprintf(buf, "%#x", magic);
1660 return buf;
1661}
1662
1663static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001664printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001665{
1666 struct statfs statbuf;
1667
1668 if (syserror(tcp) || !verbose(tcp)) {
1669 tprintf("%#lx", addr);
1670 return;
1671 }
1672 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001673 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001674 return;
1675 }
1676#ifdef ALPHA
1677
1678 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1679 sprintfstype(statbuf.f_type),
1680 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001681 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001682 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001683 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1684 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001685#else /* !ALPHA */
1686 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1687 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001688 (unsigned long)statbuf.f_bsize,
1689 (unsigned long)statbuf.f_blocks,
1690 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001691 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1692 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001693 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001694 (unsigned long)statbuf.f_ffree,
1695 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001696 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001697#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001698#ifdef _STATFS_F_FRSIZE
1699 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1700#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001701 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001702}
1703
1704int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001705sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001706{
1707 if (entering(tcp)) {
1708 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001709 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001710 } else {
1711 printstatfs(tcp, tcp->u_arg[1]);
1712 }
1713 return 0;
1714}
1715
1716int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001717sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001718{
1719 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001720 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001721 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001722 } else {
1723 printstatfs(tcp, tcp->u_arg[1]);
1724 }
1725 return 0;
1726}
1727
Denys Vlasenko84703742012-02-25 02:38:52 +01001728#if defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001729static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001730printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001731{
1732 struct statfs64 statbuf;
1733
1734 if (syserror(tcp) || !verbose(tcp)) {
1735 tprintf("%#lx", addr);
1736 return;
1737 }
1738 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001739 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001740 return;
1741 }
Roland McGrath08738432005-06-03 02:40:39 +00001742 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001743 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001744 (unsigned long long)statbuf.f_bsize,
1745 (unsigned long long)statbuf.f_blocks,
1746 (unsigned long long)statbuf.f_bfree);
1747 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1748 (unsigned long long)statbuf.f_bavail,
1749 (unsigned long long)statbuf.f_files,
1750 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001751 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1752 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001753#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001754 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001755#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001756#ifdef _STATFS_F_FLAGS
1757 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1758#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001759 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001760}
1761
Andreas Schwab7d558012012-01-17 18:14:22 +01001762struct compat_statfs64 {
1763 uint32_t f_type;
1764 uint32_t f_bsize;
1765 uint64_t f_blocks;
1766 uint64_t f_bfree;
1767 uint64_t f_bavail;
1768 uint64_t f_files;
1769 uint64_t f_ffree;
1770 fsid_t f_fsid;
1771 uint32_t f_namelen;
1772 uint32_t f_frsize;
1773 uint32_t f_flags;
1774 uint32_t f_spare[4];
1775}
1776#if defined(X86_64) || defined(IA64)
1777 __attribute__ ((packed, aligned(4)))
1778#endif
1779;
1780
1781static void
1782printcompat_statfs64(struct tcb *tcp, long addr)
1783{
1784 struct compat_statfs64 statbuf;
1785
1786 if (syserror(tcp) || !verbose(tcp)) {
1787 tprintf("%#lx", addr);
1788 return;
1789 }
1790 if (umove(tcp, addr, &statbuf) < 0) {
1791 tprints("{...}");
1792 return;
1793 }
1794 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1795 sprintfstype(statbuf.f_type),
1796 (unsigned long)statbuf.f_bsize,
1797 (unsigned long long)statbuf.f_blocks,
1798 (unsigned long long)statbuf.f_bfree);
1799 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1800 (unsigned long long)statbuf.f_bavail,
1801 (unsigned long long)statbuf.f_files,
1802 (unsigned long long)statbuf.f_ffree,
1803 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1804 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1805 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001806 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
Andreas Schwab7d558012012-01-17 18:14:22 +01001807}
1808
Roland McGrathab147c52003-07-17 09:03:02 +00001809int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001810sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001811{
1812 if (entering(tcp)) {
1813 printpath(tcp, tcp->u_arg[0]);
1814 tprintf(", %lu, ", tcp->u_arg[1]);
1815 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001816 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001817 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001818 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1819 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001820 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001821 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001822 }
1823 return 0;
1824}
1825
1826int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001827sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001828{
1829 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001830 printfd(tcp, tcp->u_arg[0]);
1831 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001832 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001833 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001834 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001835 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1836 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001837 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001838 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001839 }
1840 return 0;
1841}
1842#endif
1843
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001844#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001845int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001846osf_statfs(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 } else {
1852 printstatfs(tcp, tcp->u_arg[1]);
1853 tprintf(", %lu", tcp->u_arg[2]);
1854 }
1855 return 0;
1856}
1857
1858int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001859osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001860{
1861 if (entering(tcp)) {
1862 tprintf("%lu, ", tcp->u_arg[0]);
1863 } else {
1864 printstatfs(tcp, tcp->u_arg[1]);
1865 tprintf(", %lu", tcp->u_arg[2]);
1866 }
1867 return 0;
1868}
Denys Vlasenko84703742012-02-25 02:38:52 +01001869#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001870
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001871/* directory */
1872int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001873sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001874{
1875 if (entering(tcp)) {
1876 printpath(tcp, tcp->u_arg[0]);
1877 }
1878 return 0;
1879}
1880
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001881static int
1882decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001883{
1884 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001885 printpath(tcp, tcp->u_arg[offset]);
1886 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001887 }
1888 return 0;
1889}
1890
1891int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001892sys_mkdir(struct tcb *tcp)
1893{
1894 return decode_mkdir(tcp, 0);
1895}
1896
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001897int
1898sys_mkdirat(struct tcb *tcp)
1899{
1900 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001901 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001902 return decode_mkdir(tcp, 1);
1903}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001904
1905int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001906sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001907{
1908 if (entering(tcp)) {
1909 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001910 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001911 printpath(tcp, tcp->u_arg[1]);
1912 }
1913 return 0;
1914}
1915
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001916int
1917sys_linkat(struct tcb *tcp)
1918{
1919 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001920 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001921 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001922 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001923 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001924 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001925 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001926 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001927 }
1928 return 0;
1929}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001930
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001931int
1932sys_unlinkat(struct tcb *tcp)
1933{
1934 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001935 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001936 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001937 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001938 printflags(at_flags, tcp->u_arg[2], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001939 }
1940 return 0;
1941}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001942
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001943int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001944sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001945{
1946 if (entering(tcp)) {
1947 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001948 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001949 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001950 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001951 }
1952 return 0;
1953}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001954
1955static int
1956decode_readlink(struct tcb *tcp, int offset)
1957{
1958 if (entering(tcp)) {
1959 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001960 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001961 } else {
1962 if (syserror(tcp))
1963 tprintf("%#lx", tcp->u_arg[offset + 1]);
1964 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001965 /* Used to use printpathn(), but readlink
1966 * neither includes NUL in the returned count,
1967 * nor actually writes it into memory.
1968 * printpathn() would decide on printing
1969 * "..." continuation based on garbage
1970 * past return buffer's end.
1971 */
1972 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001973 tprintf(", %lu", tcp->u_arg[offset + 2]);
1974 }
1975 return 0;
1976}
1977
1978int
1979sys_readlink(struct tcb *tcp)
1980{
1981 return decode_readlink(tcp, 0);
1982}
1983
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001984int
1985sys_readlinkat(struct tcb *tcp)
1986{
1987 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001988 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001989 return decode_readlink(tcp, 1);
1990}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001991
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001992int
1993sys_renameat(struct tcb *tcp)
1994{
1995 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001996 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001997 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001998 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001999 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002000 printpath(tcp, tcp->u_arg[3]);
2001 }
2002 return 0;
2003}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002004
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002005int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002006sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002007{
2008 if (entering(tcp)) {
2009 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002010 printuid(", ", tcp->u_arg[1]);
2011 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002012 }
2013 return 0;
2014}
2015
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002016int
2017sys_fchownat(struct tcb *tcp)
2018{
2019 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002020 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002021 printpath(tcp, tcp->u_arg[1]);
2022 printuid(", ", tcp->u_arg[2]);
2023 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002024 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00002025 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002026 }
2027 return 0;
2028}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002029
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002030int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002031sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002032{
2033 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002034 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00002035 printuid(", ", tcp->u_arg[1]);
2036 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002037 }
2038 return 0;
2039}
2040
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002041static int
2042decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002043{
2044 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002045 printpath(tcp, tcp->u_arg[offset]);
2046 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002047 }
2048 return 0;
2049}
2050
2051int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002052sys_chmod(struct tcb *tcp)
2053{
2054 return decode_chmod(tcp, 0);
2055}
2056
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002057int
2058sys_fchmodat(struct tcb *tcp)
2059{
2060 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002061 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002062 return decode_chmod(tcp, 1);
2063}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002064
2065int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002066sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002067{
2068 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002069 printfd(tcp, tcp->u_arg[0]);
2070 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002071 }
2072 return 0;
2073}
2074
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002075#ifdef ALPHA
2076int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002077sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002078{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002079 if (entering(tcp)) {
2080 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002081 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002082 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2083 }
2084 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002085}
2086#endif
2087
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002088static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002089decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002090{
2091 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002092 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002093 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002094 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002095 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00002096 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002097 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00002098 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2099 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002100 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002101 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002102 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00002103 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002104 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00002105 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002106 }
2107 return 0;
2108}
2109
2110int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002111sys_utimes(struct tcb *tcp)
2112{
Roland McGrath6afc5652007-07-24 01:57:11 +00002113 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002114}
2115
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002116int
2117sys_futimesat(struct tcb *tcp)
2118{
2119 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002120 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002121 return decode_utimes(tcp, 1, 0);
2122}
2123
2124int
2125sys_utimensat(struct tcb *tcp)
2126{
2127 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002128 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002129 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002130 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00002131 printflags(at_flags, tcp->u_arg[3], "AT_???");
Roland McGrath6afc5652007-07-24 01:57:11 +00002132 }
2133 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002134}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002135
2136int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002137sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002138{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002139 union {
2140 long utl[2];
2141 int uti[2];
Denys Vlasenko751acb32013-02-08 15:34:46 +01002142 long paranoia_for_huge_wordsize[4];
Roland McGrath7e9817c2007-07-05 20:31:58 +00002143 } u;
Denys Vlasenko751acb32013-02-08 15:34:46 +01002144 unsigned wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002145
2146 if (entering(tcp)) {
2147 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002148 tprints(", ");
Denys Vlasenko751acb32013-02-08 15:34:46 +01002149
2150 wordsize = current_wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002151 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002152 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002153 else if (!verbose(tcp))
2154 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002155 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002156 tprints("[?, ?]");
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002157 else if (wordsize == sizeof u.utl[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002158 tprintf("[%s,", sprinttime(u.utl[0]));
2159 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002160 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002161 else if (wordsize == sizeof u.uti[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002162 tprintf("[%s,", sprinttime(u.uti[0]));
2163 tprintf(" %s]", sprinttime(u.uti[1]));
2164 }
2165 else
Denys Vlasenko751acb32013-02-08 15:34:46 +01002166 tprintf("<decode error: unsupported wordsize %d>",
2167 wordsize);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002168 }
2169 return 0;
2170}
2171
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002172static int
2173decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002174{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002175 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002176
2177 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002178 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002179 tprintf(", %s", sprintmode(mode));
2180 switch (mode & S_IFMT) {
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002181 case S_IFCHR:
2182 case S_IFBLK:
Denys Vlasenko9472a272013-02-12 11:43:46 +01002183#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002184 if (current_personality == 1)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002185 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002186 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2187 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002188 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002189#endif
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002190 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002191 (unsigned long) major(tcp->u_arg[offset + 2]),
2192 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002193 break;
2194 default:
2195 break;
2196 }
2197 }
2198 return 0;
2199}
2200
2201int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002202sys_mknod(struct tcb *tcp)
2203{
2204 return decode_mknod(tcp, 0);
2205}
2206
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002207int
2208sys_mknodat(struct tcb *tcp)
2209{
2210 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002211 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002212 return decode_mknod(tcp, 1);
2213}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002214
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002215static void
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002216print_old_dirent(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002217{
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002218#ifdef SH64
2219 typedef struct kernel_dirent old_dirent_t;
2220#else
2221 typedef struct {
2222 uint32_t d_ino;
2223 uint32_t d_off;
2224 unsigned short d_reclen;
2225 char d_name[1];
2226 } old_dirent_t;
2227#endif
2228 old_dirent_t d;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002229
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002230 if (!verbose(tcp) || umove(tcp, addr, &d) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002231 tprintf("%#lx", addr);
2232 return;
2233 }
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002234
2235 tprintf("{d_ino=%lu, d_off=%lu, d_reclen=%u, d_name=\"",
2236 (unsigned long) d.d_ino, (unsigned long) d.d_off, d.d_reclen);
2237 if (d.d_reclen > 256)
2238 d.d_reclen = 256;
2239 printpathn(tcp, addr + offsetof(old_dirent_t, d_name), d.d_reclen);
2240 tprints("\"}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002241}
2242
2243int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002244sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002245{
2246 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002247 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002248 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002249 } else {
2250 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2251 tprintf("%#lx", tcp->u_arg[1]);
2252 else
Dmitry V. Levin68f80e62013-03-20 12:45:05 +00002253 print_old_dirent(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002254 /* Not much point in printing this out, it is always 1. */
2255 if (tcp->u_arg[2] != 1)
2256 tprintf(", %lu", tcp->u_arg[2]);
2257 }
2258 return 0;
2259}
2260
Roland McGratha4d48532005-06-08 20:45:28 +00002261static const struct xlat direnttypes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002262 { DT_UNKNOWN, "DT_UNKNOWN" },
2263 { DT_FIFO, "DT_FIFO" },
2264 { DT_CHR, "DT_CHR" },
2265 { DT_DIR, "DT_DIR" },
2266 { DT_BLK, "DT_BLK" },
2267 { DT_REG, "DT_REG" },
2268 { DT_LNK, "DT_LNK" },
2269 { DT_SOCK, "DT_SOCK" },
2270 { DT_WHT, "DT_WHT" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002271 { 0, NULL },
2272};
2273
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002274int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002275sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002276{
2277 int i, len, dents = 0;
2278 char *buf;
2279
2280 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002281 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002282 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002283 return 0;
2284 }
2285 if (syserror(tcp) || !verbose(tcp)) {
2286 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2287 return 0;
2288 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002289 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002290 /* Beware of insanely large or negative values in tcp->u_rval */
2291 if (tcp->u_rval > 1024*1024)
2292 len = 1024*1024;
2293 if (tcp->u_rval < 0)
2294 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002295 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002296 if (len && !buf)
2297 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002298 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002299 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002300 free(buf);
2301 return 0;
2302 }
2303 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002304 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002305 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002306 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002307 if (!abbrev(tcp)) {
2308 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2309 i ? " " : "", d->d_ino, d->d_off);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002310 tprintf("d_reclen=%u, d_name=\"%s\", d_type=",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002311 d->d_reclen, d->d_name);
Dmitry V. Levinad232c62012-08-16 19:29:55 +00002312 printxval(direnttypes, buf[i + d->d_reclen - 1], "DT_???");
2313 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002314 }
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002315 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002316 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002317 break;
2318 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002319 i += d->d_reclen;
2320 dents++;
2321 }
2322 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002323 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002324 else
2325 tprintf("/* %u entries */", dents);
2326 tprintf(", %lu", tcp->u_arg[2]);
2327 free(buf);
2328 return 0;
2329}
2330
John Hughesbdf48f52001-03-06 15:08:09 +00002331#if _LFS64_LARGEFILE
2332int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002333sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002334{
2335 int i, len, dents = 0;
2336 char *buf;
2337
2338 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002339 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002340 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002341 return 0;
2342 }
2343 if (syserror(tcp) || !verbose(tcp)) {
2344 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2345 return 0;
2346 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002347
John Hughesbdf48f52001-03-06 15:08:09 +00002348 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002349 /* Beware of insanely large or negative tcp->u_rval */
2350 if (tcp->u_rval > 1024*1024)
2351 len = 1024*1024;
2352 if (tcp->u_rval < 0)
2353 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002354 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002355 if (len && !buf)
2356 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002357
John Hughesbdf48f52001-03-06 15:08:09 +00002358 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002359 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002360 free(buf);
2361 return 0;
2362 }
2363 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002364 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002365 for (i = 0; i < len;) {
2366 struct dirent64 *d = (struct dirent64 *) &buf[i];
John Hughesbdf48f52001-03-06 15:08:09 +00002367 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002368 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002369 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002370 d->d_ino,
2371 d->d_off);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002372 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002373 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002374 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002375 tprintf("d_reclen=%u, d_name=\"%s\"}",
2376 d->d_reclen, d->d_name);
2377 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002378 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002379 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002380 break;
2381 }
John Hughesbdf48f52001-03-06 15:08:09 +00002382 i += d->d_reclen;
2383 dents++;
2384 }
2385 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002386 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002387 else
2388 tprintf("/* %u entries */", dents);
2389 tprintf(", %lu", tcp->u_arg[2]);
2390 free(buf);
2391 return 0;
2392}
2393#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002394
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002395int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002396sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002397{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002398 if (exiting(tcp)) {
2399 if (syserror(tcp))
2400 tprintf("%#lx", tcp->u_arg[0]);
2401 else
2402 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2403 tprintf(", %lu", tcp->u_arg[1]);
2404 }
2405 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002406}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002407
2408#ifdef HAVE_SYS_ASYNCH_H
2409
2410int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002411sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002412{
2413 struct aio_result_t res;
2414
2415 if (entering(tcp)) {
2416 tprintf("%lu, ", tcp->u_arg[0]);
2417 } else {
2418 if (syserror(tcp))
2419 tprintf("%#lx", tcp->u_arg[1]);
2420 else
2421 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2422 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2423 printxval(whence, tcp->u_arg[4], "L_???");
2424 if (syserror(tcp) || tcp->u_arg[5] == 0
2425 || umove(tcp, tcp->u_arg[5], &res) < 0)
2426 tprintf(", %#lx", tcp->u_arg[5]);
2427 else
2428 tprintf(", {aio_return %d aio_errno %d}",
2429 res.aio_return, res.aio_errno);
2430 }
2431 return 0;
2432}
2433
2434int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002435sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002436{
2437 struct aio_result_t res;
2438
2439 if (entering(tcp)) {
2440 tprintf("%lu, ", tcp->u_arg[0]);
2441 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2442 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2443 printxval(whence, tcp->u_arg[4], "L_???");
2444 }
2445 else {
2446 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002447 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002448 else if (syserror(tcp)
2449 || umove(tcp, tcp->u_arg[5], &res) < 0)
2450 tprintf(", %#lx", tcp->u_arg[5]);
2451 else
2452 tprintf(", {aio_return %d aio_errno %d}",
2453 res.aio_return, res.aio_errno);
2454 }
2455 return 0;
2456}
2457
2458int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002459sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002460{
2461 if (entering(tcp))
2462 printtv(tcp, tcp->u_arg[0]);
2463 return 0;
2464}
2465
2466int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002467sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002468{
2469 struct aio_result_t res;
2470
2471 if (exiting(tcp)) {
2472 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002473 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002474 else if (syserror(tcp)
2475 || umove(tcp, tcp->u_arg[0], &res) < 0)
2476 tprintf("%#lx", tcp->u_arg[0]);
2477 else
2478 tprintf("{aio_return %d aio_errno %d}",
2479 res.aio_return, res.aio_errno);
2480 }
2481 return 0;
2482}
2483
2484#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002485
Roland McGratha4d48532005-06-08 20:45:28 +00002486static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002487#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002488 { XATTR_CREATE, "XATTR_CREATE" },
2489 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002490#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002491 { 0, NULL }
2492};
2493
Roland McGrath3292e222004-08-31 06:30:48 +00002494static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002495print_xattr_val(struct tcb *tcp, int failed,
2496 unsigned long arg,
2497 unsigned long insize,
2498 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002499{
Dmitry V. Levin1f215132012-12-07 21:38:52 +00002500 if (insize == 0)
2501 failed = 1;
Denys Vlasenko1d632462009-04-14 12:51:00 +00002502 if (!failed) {
2503 unsigned long capacity = 4 * size + 1;
2504 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2505 if (buf == NULL || /* probably a bogus size argument */
2506 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2507 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002508 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002509 else {
2510 unsigned char *out = buf;
2511 unsigned char *in = &buf[3 * size];
2512 size_t i;
2513 for (i = 0; i < size; ++i) {
Denys Vlasenko5198ed42013-03-06 23:44:23 +01002514 if (in[i] >= ' ' && in[i] <= 0x7e)
Denys Vlasenko1d632462009-04-14 12:51:00 +00002515 *out++ = in[i];
2516 else {
2517#define tohex(n) "0123456789abcdef"[n]
2518 *out++ = '\\';
2519 *out++ = 'x';
2520 *out++ = tohex(in[i] / 16);
2521 *out++ = tohex(in[i] % 16);
2522 }
2523 }
2524 /* Don't print terminating NUL if there is one. */
2525 if (i > 0 && in[i - 1] == '\0')
2526 out -= 4;
2527 *out = '\0';
2528 tprintf(", \"%s\", %ld", buf, insize);
2529 }
2530 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002531 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002532 if (failed)
2533 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002534}
2535
Roland McGrath186c5ac2002-12-15 23:58:23 +00002536int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002537sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002538{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002539 if (entering(tcp)) {
2540 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002541 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002542 printstr(tcp, tcp->u_arg[1], -1);
2543 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002544 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002545 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2546 }
2547 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002548}
2549
2550int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002551sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002552{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002553 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002554 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002555 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002556 printstr(tcp, tcp->u_arg[1], -1);
2557 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002558 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002559 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2560 }
2561 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002562}
2563
2564int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002565sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002566{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002567 if (entering(tcp)) {
2568 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002569 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002570 printstr(tcp, tcp->u_arg[1], -1);
2571 } else {
2572 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2573 tcp->u_rval);
2574 }
2575 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002576}
2577
2578int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002579sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002580{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002581 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002582 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002583 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002584 printstr(tcp, tcp->u_arg[1], -1);
2585 } else {
2586 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2587 tcp->u_rval);
2588 }
2589 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002590}
2591
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002592static void
2593print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2594{
2595 if (syserror(tcp)) {
2596 tprintf("%#lx", addr);
2597 } else {
2598 if (!addr) {
2599 tprints("NULL");
2600 } else {
2601 unsigned long len =
2602 (size < tcp->u_rval) ? size : tcp->u_rval;
2603 printstr(tcp, addr, len);
2604 }
2605 }
2606 tprintf(", %lu", size);
2607}
2608
Roland McGrath186c5ac2002-12-15 23:58:23 +00002609int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002610sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002611{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002612 if (entering(tcp)) {
2613 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002614 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002615 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002616 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002617 }
2618 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002619}
2620
2621int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002622sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002623{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002624 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002625 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002626 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002627 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002628 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002629 }
2630 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002631}
2632
2633int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002634sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002635{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002636 if (entering(tcp)) {
2637 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002638 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002639 printstr(tcp, tcp->u_arg[1], -1);
2640 }
2641 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002642}
2643
2644int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002645sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002646{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002647 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002648 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002649 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002650 printstr(tcp, tcp->u_arg[1], -1);
2651 }
2652 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002653}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002654
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002655static const struct xlat advise[] = {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002656 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2657 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2658 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2659 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2660 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2661 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2662 { 0, NULL }
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002663};
2664
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002665int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002666sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002667{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002668 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002669 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002670 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002671 argn = printllval(tcp, ", %lld", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002672 tprintf(", %ld, ", tcp->u_arg[argn++]);
2673 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002674 }
2675 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002676}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002677
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002678int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002679sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002680{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002681 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002682 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002683 printfd(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002684#if defined ARM || defined POWERPC
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002685 argn = printllval(tcp, ", %lld, ", 2);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002686#else
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002687 argn = printllval(tcp, ", %lld, ", 1);
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002688#endif
2689 argn = printllval(tcp, "%lld, ", argn);
2690#if defined ARM || defined POWERPC
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002691 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002692#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002693 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002694#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002695 }
2696 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002697}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002698
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002699static const struct xlat inotify_modes[] = {
Dmitry V. Levind475c062011-03-03 01:02:41 +00002700 { 0x00000001, "IN_ACCESS" },
2701 { 0x00000002, "IN_MODIFY" },
2702 { 0x00000004, "IN_ATTRIB" },
2703 { 0x00000008, "IN_CLOSE_WRITE"},
2704 { 0x00000010, "IN_CLOSE_NOWRITE"},
2705 { 0x00000020, "IN_OPEN" },
2706 { 0x00000040, "IN_MOVED_FROM" },
2707 { 0x00000080, "IN_MOVED_TO" },
2708 { 0x00000100, "IN_CREATE" },
2709 { 0x00000200, "IN_DELETE" },
2710 { 0x00000400, "IN_DELETE_SELF"},
2711 { 0x00000800, "IN_MOVE_SELF" },
2712 { 0x00002000, "IN_UNMOUNT" },
2713 { 0x00004000, "IN_Q_OVERFLOW" },
2714 { 0x00008000, "IN_IGNORED" },
2715 { 0x01000000, "IN_ONLYDIR" },
2716 { 0x02000000, "IN_DONT_FOLLOW"},
2717 { 0x20000000, "IN_MASK_ADD" },
2718 { 0x40000000, "IN_ISDIR" },
2719 { 0x80000000, "IN_ONESHOT" },
2720 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002721};
2722
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002723static const struct xlat inotify_init_flags[] = {
2724 { 0x00000800, "IN_NONBLOCK" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002725 { 0x00080000, "IN_CLOEXEC" },
2726 { 0, NULL }
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002727};
2728
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002729int
2730sys_inotify_add_watch(struct tcb *tcp)
2731{
2732 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002733 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002734 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002735 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002736 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002737 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2738 }
2739 return 0;
2740}
2741
2742int
2743sys_inotify_rm_watch(struct tcb *tcp)
2744{
2745 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002746 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levinab1a70c2012-03-11 15:33:34 +00002747 tprintf(", %d", (int) tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002748 }
2749 return 0;
2750}
Roland McGrath96a96612008-05-20 04:56:18 +00002751
2752int
Mark Wielaardbab89402010-03-21 14:41:26 +01002753sys_inotify_init1(struct tcb *tcp)
2754{
2755 if (entering(tcp))
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002756 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
Mark Wielaardbab89402010-03-21 14:41:26 +01002757 return 0;
2758}
2759
2760int
Roland McGrath96a96612008-05-20 04:56:18 +00002761sys_fallocate(struct tcb *tcp)
2762{
2763 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002764 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002765 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenkod33e72a2012-05-18 02:03:24 +02002766 tprintf(", %#lo, ", tcp->u_arg[1]); /* mode */
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002767 argn = printllval(tcp, "%llu, ", 2); /* offset */
2768 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002769 }
2770 return 0;
2771}
Dmitry V. Levin88293652012-03-09 21:02:19 +00002772
Dmitry V. Levinad0c01e2012-03-15 00:52:22 +00002773#ifndef SWAP_FLAG_PREFER
2774# define SWAP_FLAG_PREFER 0x8000
2775#endif
2776#ifndef SWAP_FLAG_DISCARD
2777# define SWAP_FLAG_DISCARD 0x10000
2778#endif
Dmitry V. Levin88293652012-03-09 21:02:19 +00002779static const struct xlat swap_flags[] = {
2780 { SWAP_FLAG_PREFER, "SWAP_FLAG_PREFER" },
2781 { SWAP_FLAG_DISCARD, "SWAP_FLAG_DISCARD" },
2782 { 0, NULL }
2783};
2784
2785int
2786sys_swapon(struct tcb *tcp)
2787{
2788 if (entering(tcp)) {
2789 int flags = tcp->u_arg[1];
2790 printpath(tcp, tcp->u_arg[0]);
2791 tprints(", ");
2792 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2793 "SWAP_FLAG_???");
2794 if (flags & SWAP_FLAG_PREFER)
2795 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);
2796 }
2797 return 0;
2798}