blob: fa4b3149b63d3bed1cacc2f3ed9fa1b1909f444f [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include <dirent.h>
Dmitry V. Levin88293652012-03-09 21:02:19 +000033#include <sys/swap.h>
Roland McGrathc531e572008-08-01 01:13:10 +000034
Denys Vlasenko84703742012-02-25 02:38:52 +010035#ifdef LINUXSPARC
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000036struct stat {
37 unsigned short st_dev;
38 unsigned int st_ino;
39 unsigned short st_mode;
40 short st_nlink;
41 unsigned short st_uid;
42 unsigned short st_gid;
43 unsigned short st_rdev;
44 unsigned int st_size;
45 int st_atime;
46 unsigned int __unused1;
47 int st_mtime;
48 unsigned int __unused2;
49 int st_ctime;
50 unsigned int __unused3;
51 int st_blksize;
52 int st_blocks;
53 unsigned int __unused4[2];
54};
Denys Vlasenko84703742012-02-25 02:38:52 +010055# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +000056struct stat_sparc64 {
57 unsigned int st_dev;
58 unsigned long st_ino;
59 unsigned int st_mode;
60 unsigned int st_nlink;
61 unsigned int st_uid;
62 unsigned int st_gid;
63 unsigned int st_rdev;
64 long st_size;
65 long st_atime;
66 long st_mtime;
67 long st_ctime;
68 long st_blksize;
69 long st_blocks;
70 unsigned long __unused4[2];
71};
Denys Vlasenko84703742012-02-25 02:38:52 +010072# endif /* SPARC64 */
73# define stat kernel_stat
74# include <asm/stat.h>
75# undef stat
76#else
77# undef dev_t
78# undef ino_t
79# undef mode_t
80# undef nlink_t
81# undef uid_t
82# undef gid_t
83# undef off_t
84# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +010085# define dev_t __kernel_dev_t
86# define ino_t __kernel_ino_t
87# define mode_t __kernel_mode_t
88# define nlink_t __kernel_nlink_t
89# define uid_t __kernel_uid_t
90# define gid_t __kernel_gid_t
91# define off_t __kernel_off_t
92# define loff_t __kernel_loff_t
Wichert Akkermana6013701999-07-08 14:00:58 +000093
Denys Vlasenko84703742012-02-25 02:38:52 +010094# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +000095
Denys Vlasenko84703742012-02-25 02:38:52 +010096# undef dev_t
97# undef ino_t
98# undef mode_t
99# undef nlink_t
100# undef uid_t
101# undef gid_t
102# undef off_t
103# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100104# define dev_t dev_t
105# define ino_t ino_t
106# define mode_t mode_t
107# define nlink_t nlink_t
108# define uid_t uid_t
109# define gid_t gid_t
110# define off_t off_t
111# define loff_t loff_t
112#endif
113
114#ifdef HPPA /* asm-parisc/stat.h defines stat64 */
115# undef stat64
116#endif
117#define stat libc_stat
118#define stat64 libc_stat64
119#include <sys/stat.h>
120#undef stat
121#undef stat64
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100122/* These might be macros. */
Denys Vlasenko84703742012-02-25 02:38:52 +0100123#undef st_atime
124#undef st_mtime
125#undef st_ctime
126#ifdef HPPA
127# define stat64 hpux_stat64
128#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000129
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000130#include <fcntl.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000131#ifdef HAVE_SYS_VFS_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100132# include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000133#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +0000134#ifdef HAVE_LINUX_XATTR_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100135# include <linux/xattr.h>
Denys Vlasenkoed720fd2012-02-25 02:24:03 +0100136#else
Denys Vlasenko84703742012-02-25 02:38:52 +0100137# define XATTR_CREATE 1
138# define XATTR_REPLACE 2
Roland McGrath186c5ac2002-12-15 23:58:23 +0000139#endif
140
John Hughes70623be2001-03-08 13:59:00 +0000141#if HAVE_LONG_LONG_OFF_T
142/*
143 * Ugly hacks for systems that have typedef long long off_t
144 */
Denys Vlasenko84703742012-02-25 02:38:52 +0100145# define stat64 stat
146# define HAVE_STAT64 1 /* Ugly hack */
Denys Vlasenko84703742012-02-25 02:38:52 +0100147# define sys_stat64 sys_stat
148# define sys_fstat64 sys_fstat
149# define sys_lstat64 sys_lstat
Denys Vlasenko84703742012-02-25 02:38:52 +0100150# define sys_truncate64 sys_truncate
151# define sys_ftruncate64 sys_ftruncate
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000152#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000153
154#ifdef MAJOR_IN_SYSMACROS
Denys Vlasenko84703742012-02-25 02:38:52 +0100155# include <sys/sysmacros.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000156#endif
157
158#ifdef MAJOR_IN_MKDEV
Denys Vlasenko84703742012-02-25 02:38:52 +0100159# include <sys/mkdev.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000160#endif
161
162#ifdef HAVE_SYS_ASYNCH_H
Denys Vlasenko84703742012-02-25 02:38:52 +0100163# include <sys/asynch.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000164#endif
165
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100166struct kernel_dirent {
167 unsigned long d_ino;
168 unsigned long d_off;
169 unsigned short d_reclen;
170 char d_name[1];
171};
172
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000173const struct xlat open_access_modes[] = {
174 { O_RDONLY, "O_RDONLY" },
175 { O_WRONLY, "O_WRONLY" },
176 { O_RDWR, "O_RDWR" },
177#ifdef O_ACCMODE
178 { O_ACCMODE, "O_ACCMODE" },
179#endif
180 { 0, NULL },
181};
182
183const struct xlat open_mode_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000184 { O_CREAT, "O_CREAT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000185 { O_EXCL, "O_EXCL" },
186 { O_NOCTTY, "O_NOCTTY" },
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000187 { O_TRUNC, "O_TRUNC" },
188 { O_APPEND, "O_APPEND" },
189 { O_NONBLOCK, "O_NONBLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000190#ifdef O_SYNC
191 { O_SYNC, "O_SYNC" },
192#endif
193#ifdef O_ASYNC
194 { O_ASYNC, "O_ASYNC" },
195#endif
196#ifdef O_DSYNC
197 { O_DSYNC, "O_DSYNC" },
198#endif
199#ifdef O_RSYNC
200 { O_RSYNC, "O_RSYNC" },
201#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000202#if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000203 { O_NDELAY, "O_NDELAY" },
204#endif
205#ifdef O_PRIV
206 { O_PRIV, "O_PRIV" },
207#endif
208#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000209 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000210#endif
211#ifdef O_LARGEFILE
Roland McGrathfee836e2005-02-02 22:11:32 +0000212# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
213# undef O_LARGEFILE
214# ifdef SPARC64
215# define O_LARGEFILE 0x40000
216# elif defined X86_64 || defined S390X
217# define O_LARGEFILE 0100000
218# endif
219# endif
Roland McGrath663a8a02005-02-04 09:49:56 +0000220# ifdef O_LARGEFILE
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200221 { O_LARGEFILE, "O_LARGEFILE" },
Roland McGrath663a8a02005-02-04 09:49:56 +0000222# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000223#endif
224#ifdef O_DIRECTORY
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200225 { O_DIRECTORY, "O_DIRECTORY" },
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000226#endif
227#ifdef O_NOFOLLOW
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200228 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000229#endif
Roland McGrath1025c3e2005-05-09 07:40:35 +0000230#ifdef O_NOATIME
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200231 { O_NOATIME, "O_NOATIME" },
Roland McGrath1025c3e2005-05-09 07:40:35 +0000232#endif
Roland McGrath71d3d662007-08-07 01:00:26 +0000233#ifdef O_CLOEXEC
234 { O_CLOEXEC, "O_CLOEXEC" },
235#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000236#ifdef FNDELAY
237 { FNDELAY, "FNDELAY" },
238#endif
239#ifdef FAPPEND
240 { FAPPEND, "FAPPEND" },
241#endif
242#ifdef FMARK
243 { FMARK, "FMARK" },
244#endif
245#ifdef FDEFER
246 { FDEFER, "FDEFER" },
247#endif
248#ifdef FASYNC
249 { FASYNC, "FASYNC" },
250#endif
251#ifdef FSHLOCK
252 { FSHLOCK, "FSHLOCK" },
253#endif
254#ifdef FEXLOCK
255 { FEXLOCK, "FEXLOCK" },
256#endif
257#ifdef FCREAT
258 { FCREAT, "FCREAT" },
259#endif
260#ifdef FTRUNC
261 { FTRUNC, "FTRUNC" },
262#endif
263#ifdef FEXCL
264 { FEXCL, "FEXCL" },
265#endif
266#ifdef FNBIO
267 { FNBIO, "FNBIO" },
268#endif
269#ifdef FSYNC
270 { FSYNC, "FSYNC" },
271#endif
272#ifdef FNOCTTY
273 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000274#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000275#ifdef O_SHLOCK
276 { O_SHLOCK, "O_SHLOCK" },
277#endif
278#ifdef O_EXLOCK
279 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000280#endif
281 { 0, NULL },
282};
283
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000284#ifndef AT_FDCWD
285# define AT_FDCWD -100
286#endif
287
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000288/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
289 * extension to get the right value. We do this by declaring fd as int here.
290 */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000291static void
Dmitry V. Levin31382132011-03-04 05:08:02 +0300292print_dirfd(struct tcb *tcp, int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000293{
294 if (fd == AT_FDCWD)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200295 tprints("AT_FDCWD, ");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200296 else {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300297 printfd(tcp, fd);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200298 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300299 }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000300}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000301
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000302/*
303 * low bits of the open(2) flags define access mode,
304 * other bits are real flags.
305 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000306const char *
307sprint_open_modes(mode_t flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000308{
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100309 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000310 char *p;
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100311 char sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000312 const char *str;
313 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000314
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100315 sep = ' ';
316 p = stpcpy(outstr, "flags");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000317 str = xlookup(open_access_modes, flags & 3);
318 if (str) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100319 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200320 p = stpcpy(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000321 flags &= ~3;
322 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000323 return outstr;
324 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000325 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000326
327 for (x = open_mode_flags; x->str; x++) {
328 if ((flags & x->val) == x->val) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100329 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200330 p = stpcpy(p, x->str);
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000331 flags &= ~x->val;
332 if (!flags)
333 return outstr;
334 sep = '|';
335 }
336 }
337 /* flags is still nonzero */
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100338 *p++ = sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000339 sprintf(p, "%#x", flags);
340 return outstr;
341}
342
343void
344tprint_open_modes(mode_t flags)
345{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200346 tprints(sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000347}
348
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000349static int
350decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000351{
352 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000353 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200354 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000355 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000356 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000357 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000358 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000359 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000360 }
361 }
362 return 0;
363}
364
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000365int
366sys_open(struct tcb *tcp)
367{
368 return decode_open(tcp, 0);
369}
370
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000371int
372sys_openat(struct tcb *tcp)
373{
374 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300375 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000376 return decode_open(tcp, 1);
377}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000378
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000379#ifdef LINUXSPARC
Roland McGratha4d48532005-06-08 20:45:28 +0000380static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000381 { 0, "O_RDWR" },
382 { 1, "O_RDONLY" },
383 { 2, "O_WRONLY" },
384 { 0x80, "O_NONBLOCK" },
385 { 8, "O_APPEND" },
386 { 0x100, "O_CREAT" },
387 { 0x200, "O_TRUNC" },
388 { 0x400, "O_EXCL" },
389 { 0x800, "O_NOCTTY" },
390 { 0x10, "O_SYNC" },
391 { 0x40, "O_DSYNC" },
392 { 0x8000, "O_RSYNC" },
393 { 4, "O_NDELAY" },
394 { 0x1000, "O_PRIV" },
395 { 0, NULL },
396};
397
398int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000399solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000400{
401 if (entering(tcp)) {
402 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200403 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000404 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000405 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406 if (tcp->u_arg[1] & 0x100) {
407 /* mode */
408 tprintf(", %#lo", tcp->u_arg[2]);
409 }
410 }
411 return 0;
412}
413
414#endif
415
416int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000417sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000418{
419 if (entering(tcp)) {
420 printpath(tcp, tcp->u_arg[0]);
421 tprintf(", %#lo", tcp->u_arg[1]);
422 }
423 return 0;
424}
425
Roland McGrathd9f816f2004-09-04 03:39:20 +0000426static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000427 { F_OK, "F_OK", },
428 { R_OK, "R_OK" },
429 { W_OK, "W_OK" },
430 { X_OK, "X_OK" },
431#ifdef EFF_ONLY_OK
432 { EFF_ONLY_OK, "EFF_ONLY_OK" },
433#endif
434#ifdef EX_OK
435 { EX_OK, "EX_OK" },
436#endif
437 { 0, NULL },
438};
439
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000440static int
441decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000442{
443 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000444 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200445 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000446 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000447 }
448 return 0;
449}
450
451int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000452sys_access(struct tcb *tcp)
453{
454 return decode_access(tcp, 0);
455}
456
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000457int
458sys_faccessat(struct tcb *tcp)
459{
460 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300461 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000462 return decode_access(tcp, 1);
463}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000464
465int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000466sys_umask(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000467{
468 if (entering(tcp)) {
469 tprintf("%#lo", tcp->u_arg[0]);
470 }
471 return RVAL_OCTAL;
472}
473
Roland McGrathd9f816f2004-09-04 03:39:20 +0000474static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000475 { SEEK_SET, "SEEK_SET" },
476 { SEEK_CUR, "SEEK_CUR" },
477 { SEEK_END, "SEEK_END" },
478 { 0, NULL },
479};
480
H.J. Ludd0130b2012-04-16 12:16:45 +0200481#if defined(LINUX_MIPSN32)
Roland McGrath542c2c62008-05-20 01:11:56 +0000482int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000483sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000484{
485 long long offset;
486 int _whence;
487
488 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300489 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200490 tprints(", ");
Roland McGrath542c2c62008-05-20 01:11:56 +0000491 offset = tcp->ext_arg[1];
492 _whence = tcp->u_arg[2];
493 if (_whence == SEEK_SET)
494 tprintf("%llu, ", offset);
495 else
496 tprintf("%lld, ", offset);
497 printxval(whence, _whence, "SEEK_???");
498 }
H.J. Ludd0130b2012-04-16 12:16:45 +0200499 return RVAL_LUDECIMAL;
Roland McGrath542c2c62008-05-20 01:11:56 +0000500}
H.J. Ludd0130b2012-04-16 12:16:45 +0200501#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000502int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000503sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000504{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000505 off_t offset;
506 int _whence;
507
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000508 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300509 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200510 tprints(", ");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000511 offset = tcp->u_arg[1];
512 _whence = tcp->u_arg[2];
513 if (_whence == SEEK_SET)
514 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000515 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000516 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000517 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000518 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000519 return RVAL_UDECIMAL;
520}
John Hughes5a826b82001-03-07 13:21:24 +0000521#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000523int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000524sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000526 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300527 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000528 /*
529 * This one call takes explicitly two 32-bit arguments hi, lo,
530 * rather than one 64-bit argument for which LONG_LONG works
531 * appropriate for the native byte order.
532 */
533 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300534 tprintf(", %llu, ",
535 ((long long int) tcp->u_arg[1]) << 32 |
536 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000537 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300538 tprintf(", %lld, ",
539 ((long long int) tcp->u_arg[1]) << 32 |
540 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000541 }
542 else {
543 long long int off;
544 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
545 tprintf("%#lx, ", tcp->u_arg[3]);
546 else
547 tprintf("[%llu], ", off);
548 printxval(whence, tcp->u_arg[4], "SEEK_???");
549 }
550 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000551}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000552
553int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000554sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000555{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000556 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100557 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300558 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200559 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100560 argn = printllval(tcp, "%lld", 1);
561 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000562 }
563 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000564}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000565
John Hughes70623be2001-03-08 13:59:00 +0000566#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000567int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000568sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000569{
570 if (entering(tcp)) {
571 printpath(tcp, tcp->u_arg[0]);
572 tprintf(", %lu", tcp->u_arg[1]);
573 }
574 return 0;
575}
John Hughes5a826b82001-03-07 13:21:24 +0000576#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000577
John Hughes70623be2001-03-08 13:59:00 +0000578#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000579int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000580sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000581{
582 if (entering(tcp)) {
583 printpath(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100584 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000585 }
586 return 0;
587}
588#endif
589
John Hughes70623be2001-03-08 13:59:00 +0000590#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000591int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000592sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000593{
594 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300595 printfd(tcp, tcp->u_arg[0]);
596 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000597 }
598 return 0;
599}
John Hughes5a826b82001-03-07 13:21:24 +0000600#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000601
John Hughes70623be2001-03-08 13:59:00 +0000602#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000603int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000604sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000605{
606 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300607 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200608 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100609 printllval(tcp, "%llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000610 }
611 return 0;
612}
613#endif
614
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000615/* several stats */
616
Roland McGrathd9f816f2004-09-04 03:39:20 +0000617static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000618 { S_IFREG, "S_IFREG" },
619 { S_IFSOCK, "S_IFSOCK" },
620 { S_IFIFO, "S_IFIFO" },
621 { S_IFLNK, "S_IFLNK" },
622 { S_IFDIR, "S_IFDIR" },
623 { S_IFBLK, "S_IFBLK" },
624 { S_IFCHR, "S_IFCHR" },
625 { 0, NULL },
626};
627
Roland McGrathf9c49b22004-10-06 22:11:54 +0000628static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000629sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000630{
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100631 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
632 + sizeof(int)*3
633 + /*paranoia:*/ 8];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000634 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000635
636 if ((mode & S_IFMT) == 0)
637 s = "";
638 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
639 sprintf(buf, "%#o", mode);
640 return buf;
641 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100642 s = buf + sprintf(buf, "%s%s%s%s", s,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000643 (mode & S_ISUID) ? "|S_ISUID" : "",
644 (mode & S_ISGID) ? "|S_ISGID" : "",
645 (mode & S_ISVTX) ? "|S_ISVTX" : "");
646 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
647 if (mode)
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100648 sprintf((char*)s, "|%#o", mode);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000649 s = (*buf == '|') ? buf + 1 : buf;
650 return *s ? s : "0";
651}
652
653static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000654sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000655{
656 struct tm *tmp;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100657 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000658
659 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000660 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000661 return buf;
662 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200663 tmp = localtime(&t);
664 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000665 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
666 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
667 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
668 else
669 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
670
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000671 return buf;
672}
673
674#ifdef LINUXSPARC
675typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000676 int tv_sec;
677 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000678} timestruct_t;
679
680struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000681 unsigned st_dev;
682 int st_pad1[3]; /* network id */
683 unsigned st_ino;
684 unsigned st_mode;
685 unsigned st_nlink;
686 unsigned st_uid;
687 unsigned st_gid;
688 unsigned st_rdev;
689 int st_pad2[2];
690 int st_size;
691 int st_pad3; /* st_size, off_t expansion */
692 timestruct_t st_atime;
693 timestruct_t st_mtime;
694 timestruct_t st_ctime;
695 int st_blksize;
696 int st_blocks;
697 char st_fstype[16];
698 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000699};
700
701static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000702printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000703{
704 struct solstat statbuf;
705
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000706 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200707 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000708 return;
709 }
710 if (!abbrev(tcp)) {
711 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
712 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
713 (unsigned long) (statbuf.st_dev & 0x3ffff),
714 (unsigned long) statbuf.st_ino,
715 sprintmode(statbuf.st_mode));
716 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
717 (unsigned long) statbuf.st_nlink,
718 (unsigned long) statbuf.st_uid,
719 (unsigned long) statbuf.st_gid);
720 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
721 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
722 }
723 else
724 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
725 switch (statbuf.st_mode & S_IFMT) {
726 case S_IFCHR: case S_IFBLK:
727 tprintf("st_rdev=makedev(%lu, %lu), ",
728 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
729 (unsigned long) (statbuf.st_rdev & 0x3ffff));
730 break;
731 default:
732 tprintf("st_size=%u, ", statbuf.st_size);
733 break;
734 }
735 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000736 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
737 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
738 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000739 }
740 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200741 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000742}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000743
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100744#if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000745static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000746printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000747{
748 struct stat_sparc64 statbuf;
749
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000750 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200751 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000752 return;
753 }
754
755 if (!abbrev(tcp)) {
756 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
757 (unsigned long) major(statbuf.st_dev),
758 (unsigned long) minor(statbuf.st_dev),
759 (unsigned long) statbuf.st_ino,
760 sprintmode(statbuf.st_mode));
761 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
762 (unsigned long) statbuf.st_nlink,
763 (unsigned long) statbuf.st_uid,
764 (unsigned long) statbuf.st_gid);
765 tprintf("st_blksize=%lu, ",
766 (unsigned long) statbuf.st_blksize);
767 tprintf("st_blocks=%lu, ",
768 (unsigned long) statbuf.st_blocks);
769 }
770 else
771 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
772 switch (statbuf.st_mode & S_IFMT) {
773 case S_IFCHR: case S_IFBLK:
774 tprintf("st_rdev=makedev(%lu, %lu), ",
775 (unsigned long) major(statbuf.st_rdev),
776 (unsigned long) minor(statbuf.st_rdev));
777 break;
778 default:
779 tprintf("st_size=%lu, ", statbuf.st_size);
780 break;
781 }
782 if (!abbrev(tcp)) {
783 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
784 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100785 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000786 }
787 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200788 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000789}
790#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000791#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000792
Denys Vlasenko84703742012-02-25 02:38:52 +0100793#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200794struct stat_powerpc32 {
795 unsigned int st_dev;
796 unsigned int st_ino;
797 unsigned int st_mode;
798 unsigned short st_nlink;
799 unsigned int st_uid;
800 unsigned int st_gid;
801 unsigned int st_rdev;
802 unsigned int st_size;
803 unsigned int st_blksize;
804 unsigned int st_blocks;
805 unsigned int st_atime;
806 unsigned int st_atime_nsec;
807 unsigned int st_mtime;
808 unsigned int st_mtime_nsec;
809 unsigned int st_ctime;
810 unsigned int st_ctime_nsec;
811 unsigned int __unused4;
812 unsigned int __unused5;
813};
814
815static void
816printstat_powerpc32(struct tcb *tcp, long addr)
817{
818 struct stat_powerpc32 statbuf;
819
820 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200821 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200822 return;
823 }
824
825 if (!abbrev(tcp)) {
826 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
827 major(statbuf.st_dev), minor(statbuf.st_dev),
828 statbuf.st_ino,
829 sprintmode(statbuf.st_mode));
830 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
831 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
832 tprintf("st_blksize=%u, ", statbuf.st_blksize);
833 tprintf("st_blocks=%u, ", statbuf.st_blocks);
834 }
835 else
836 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
837 switch (statbuf.st_mode & S_IFMT) {
838 case S_IFCHR: case S_IFBLK:
839 tprintf("st_rdev=makedev(%lu, %lu), ",
840 (unsigned long) major(statbuf.st_rdev),
841 (unsigned long) minor(statbuf.st_rdev));
842 break;
843 default:
844 tprintf("st_size=%u, ", statbuf.st_size);
845 break;
846 }
847 if (!abbrev(tcp)) {
848 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
849 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100850 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200851 }
852 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200853 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200854}
Denys Vlasenko84703742012-02-25 02:38:52 +0100855#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200856
Roland McGratha4d48532005-06-08 20:45:28 +0000857static const struct xlat fileflags[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000858 { 0, NULL },
859};
860
John Hughes70623be2001-03-08 13:59:00 +0000861#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000862static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000863realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000864{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000865 if (!abbrev(tcp)) {
866 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
867 (unsigned long) major(statbuf->st_dev),
868 (unsigned long) minor(statbuf->st_dev),
869 (unsigned long) statbuf->st_ino,
870 sprintmode(statbuf->st_mode));
871 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
872 (unsigned long) statbuf->st_nlink,
873 (unsigned long) statbuf->st_uid,
874 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000875#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000876 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
877#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000878#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000879 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
880#endif
881 }
882 else
883 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
884 switch (statbuf->st_mode & S_IFMT) {
885 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000886#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000887 tprintf("st_rdev=makedev(%lu, %lu), ",
888 (unsigned long) major(statbuf->st_rdev),
889 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000890#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000891 tprintf("st_size=makedev(%lu, %lu), ",
892 (unsigned long) major(statbuf->st_size),
893 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000894#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000895 break;
896 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000897 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000898 break;
899 }
900 if (!abbrev(tcp)) {
901 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
902 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
903 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000904#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200905 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000906 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000907#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000908#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000909 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
910#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000911#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000912 tprintf(", st_level=%ld", statbuf->st_level);
913#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000914#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000915 tprintf(", st_fstype=%.*s",
916 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
917#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000918#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000919 tprintf(", st_gen=%u", statbuf->st_gen);
920#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200921 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000922 }
923 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200924 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000925}
926
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000927static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000928printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000929{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000930 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000931
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000932 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200933 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000934 return;
935 }
936 if (syserror(tcp) || !verbose(tcp)) {
937 tprintf("%#lx", addr);
938 return;
939 }
940
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000941#ifdef LINUXSPARC
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000942 if (current_personality == 1) {
943 printstatsol(tcp, addr);
944 return;
945 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000946#ifdef SPARC64
947 else if (current_personality == 2) {
948 printstat_sparc64(tcp, addr);
949 return;
950 }
951#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000952#endif /* LINUXSPARC */
953
Denys Vlasenko84703742012-02-25 02:38:52 +0100954#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200955 if (current_personality == 1) {
956 printstat_powerpc32(tcp, addr);
957 return;
958 }
959#endif
960
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000961 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200962 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000963 return;
964 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000965
966 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000967}
John Hughes70623be2001-03-08 13:59:00 +0000968#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000969
Denys Vlasenko84703742012-02-25 02:38:52 +0100970#if !defined HAVE_STAT64 && defined X86_64
Roland McGrathe6d0f712007-08-07 01:22:49 +0000971/*
972 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
973 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
974 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
975 * __GNUC__ is needed for the required __attribute__ below.
976 */
977struct stat64 {
978 unsigned long long st_dev;
979 unsigned char __pad0[4];
980 unsigned int __st_ino;
981 unsigned int st_mode;
982 unsigned int st_nlink;
983 unsigned int st_uid;
984 unsigned int st_gid;
985 unsigned long long st_rdev;
986 unsigned char __pad3[4];
987 long long st_size;
988 unsigned int st_blksize;
989 unsigned long long st_blocks;
990 unsigned int st_atime;
991 unsigned int st_atime_nsec;
992 unsigned int st_mtime;
993 unsigned int st_mtime_nsec;
994 unsigned int st_ctime;
995 unsigned int st_ctime_nsec;
996 unsigned long long st_ino;
997} __attribute__((packed));
998# define HAVE_STAT64 1
999# define STAT64_SIZE 96
1000#endif
1001
Wichert Akkermanc7926982000-04-10 22:22:31 +00001002#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001003static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001004printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001005{
1006 struct stat64 statbuf;
1007
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001008#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001009 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1010#endif
1011
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001012 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001013 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001014 return;
1015 }
1016 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001017 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001018 return;
1019 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001020
1021#ifdef LINUXSPARC
1022 if (current_personality == 1) {
1023 printstatsol(tcp, addr);
1024 return;
1025 }
1026# ifdef SPARC64
1027 else if (current_personality == 2) {
1028 printstat_sparc64(tcp, addr);
1029 return;
1030 }
1031# endif
1032#endif /* LINUXSPARC */
1033
Denys Vlasenko84703742012-02-25 02:38:52 +01001034#if defined X86_64
Andreas Schwab61b74352009-10-16 11:37:13 +02001035 if (current_personality == 0) {
1036 printstat(tcp, addr);
1037 return;
1038 }
1039#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +00001040
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001041 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001042 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001043 return;
1044 }
1045
1046 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001047#ifdef HAVE_LONG_LONG
1048 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1049#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001050 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001051#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001052 (unsigned long) major(statbuf.st_dev),
1053 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001054#ifdef HAVE_LONG_LONG
1055 (unsigned long long) statbuf.st_ino,
1056#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001057 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001058#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001059 sprintmode(statbuf.st_mode));
1060 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1061 (unsigned long) statbuf.st_nlink,
1062 (unsigned long) statbuf.st_uid,
1063 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001064#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001065 tprintf("st_blksize=%lu, ",
1066 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001067#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1068#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001069 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001070#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001071 }
1072 else
1073 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1074 switch (statbuf.st_mode & S_IFMT) {
1075 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001076#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001077 tprintf("st_rdev=makedev(%lu, %lu), ",
1078 (unsigned long) major(statbuf.st_rdev),
1079 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001080#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001081 tprintf("st_size=makedev(%lu, %lu), ",
1082 (unsigned long) major(statbuf.st_size),
1083 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001084#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001085 break;
1086 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001087#ifdef HAVE_LONG_LONG
1088 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1089#else
1090 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1091#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001092 break;
1093 }
1094 if (!abbrev(tcp)) {
1095 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1096 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001097 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001098#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001099 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001100 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001101#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001102#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001103 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1104#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001105#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001106 tprintf(", st_level=%ld", statbuf.st_level);
1107#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001108#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001109 tprintf(", st_fstype=%.*s",
1110 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1111#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001112#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001113 tprintf(", st_gen=%u", statbuf.st_gen);
1114#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001115 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001116 }
1117 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001118 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001119}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001120#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001121
Denys Vlasenko84703742012-02-25 02:38:52 +01001122#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001123static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001124convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001125{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001126 newbuf->st_dev = oldbuf->st_dev;
1127 newbuf->st_ino = oldbuf->st_ino;
1128 newbuf->st_mode = oldbuf->st_mode;
1129 newbuf->st_nlink = oldbuf->st_nlink;
1130 newbuf->st_uid = oldbuf->st_uid;
1131 newbuf->st_gid = oldbuf->st_gid;
1132 newbuf->st_rdev = oldbuf->st_rdev;
1133 newbuf->st_size = oldbuf->st_size;
1134 newbuf->st_atime = oldbuf->st_atime;
1135 newbuf->st_mtime = oldbuf->st_mtime;
1136 newbuf->st_ctime = oldbuf->st_ctime;
1137 newbuf->st_blksize = 0; /* not supported in old_stat */
1138 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001139}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001140
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001141static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001142printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001143{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001144 struct __old_kernel_stat statbuf;
1145 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001146
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001147 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001148 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001149 return;
1150 }
1151 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001152 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001153 return;
1154 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001155
Denys Vlasenko84703742012-02-25 02:38:52 +01001156# ifdef LINUXSPARC
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001157 if (current_personality == 1) {
1158 printstatsol(tcp, addr);
1159 return;
1160 }
Denys Vlasenko84703742012-02-25 02:38:52 +01001161# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001162
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001163 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001164 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001165 return;
1166 }
1167
1168 convertoldstat(&statbuf, &newstatbuf);
1169 realprintstat(tcp, &newstatbuf);
1170}
Denys Vlasenko84703742012-02-25 02:38:52 +01001171#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001172
John Hughes70623be2001-03-08 13:59:00 +00001173#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001174int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001175sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001176{
1177 if (entering(tcp)) {
1178 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001179 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001180 } else {
1181 printstat(tcp, tcp->u_arg[1]);
1182 }
1183 return 0;
1184}
John Hughesb8c9f772001-03-07 16:53:07 +00001185#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001186
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001187int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001188sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001189{
1190#ifdef HAVE_STAT64
1191 if (entering(tcp)) {
1192 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001193 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001194 } else {
1195 printstat64(tcp, tcp->u_arg[1]);
1196 }
1197 return 0;
1198#else
1199 return printargs(tcp);
1200#endif
1201}
1202
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001203#ifndef AT_SYMLINK_NOFOLLOW
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001204# define AT_SYMLINK_NOFOLLOW 0x100
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001205#endif
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001206#ifndef AT_REMOVEDIR
1207# define AT_REMOVEDIR 0x200
1208#endif
1209#ifndef AT_SYMLINK_FOLLOW
1210# define AT_SYMLINK_FOLLOW 0x400
1211#endif
1212#ifndef AT_NO_AUTOMOUNT
1213# define AT_NO_AUTOMOUNT 0x800
1214#endif
1215#ifndef AT_EMPTY_PATH
1216# define AT_EMPTY_PATH 0x1000
1217#endif
1218
1219static const struct xlat at_flags[] = {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001220 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001221 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1222 { AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" },
1223 { AT_NO_AUTOMOUNT, "AT_NO_AUTOMOUNT" },
1224 { AT_EMPTY_PATH, "AT_EMPTY_PATH" },
1225 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001226};
1227
1228int
1229sys_newfstatat(struct tcb *tcp)
1230{
1231 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001232 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001233 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001234 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001235 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001236#ifdef POWERPC64
1237 if (current_personality == 0)
1238 printstat(tcp, tcp->u_arg[2]);
1239 else
1240 printstat64(tcp, tcp->u_arg[2]);
1241#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001242 printstat64(tcp, tcp->u_arg[2]);
1243#else
1244 printstat(tcp, tcp->u_arg[2]);
1245#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001246 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001247 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001248 }
1249 return 0;
1250}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001251
Denys Vlasenko84703742012-02-25 02:38:52 +01001252#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001253int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001254sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001255{
1256 if (entering(tcp)) {
1257 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001258 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001259 } else {
1260 printoldstat(tcp, tcp->u_arg[1]);
1261 }
1262 return 0;
1263}
Denys Vlasenko84703742012-02-25 02:38:52 +01001264#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001265
John Hughes70623be2001-03-08 13:59:00 +00001266#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001267int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001268sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001269{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001270 if (entering(tcp)) {
1271 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001272 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001273 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001274 printstat(tcp, tcp->u_arg[1]);
1275 }
1276 return 0;
1277}
John Hughesb8c9f772001-03-07 16:53:07 +00001278#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001279
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001280int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001281sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001282{
1283#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001284 if (entering(tcp)) {
1285 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001286 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001287 } else {
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001288 printstat64(tcp, tcp->u_arg[1]);
1289 }
1290 return 0;
1291#else
1292 return printargs(tcp);
1293#endif
1294}
1295
Denys Vlasenko84703742012-02-25 02:38:52 +01001296#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001297int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001298sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001299{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001300 if (entering(tcp)) {
1301 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001302 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001303 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001304 printoldstat(tcp, tcp->u_arg[1]);
1305 }
1306 return 0;
1307}
Denys Vlasenko84703742012-02-25 02:38:52 +01001308#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001309
John Hughes70623be2001-03-08 13:59:00 +00001310#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001311int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001312sys_lstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001313{
1314 if (entering(tcp)) {
1315 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001316 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001317 } else {
1318 printstat(tcp, tcp->u_arg[1]);
1319 }
1320 return 0;
1321}
John Hughesb8c9f772001-03-07 16:53:07 +00001322#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001323
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001324int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001325sys_lstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001326{
1327#ifdef HAVE_STAT64
1328 if (entering(tcp)) {
1329 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001330 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001331 } else {
1332 printstat64(tcp, tcp->u_arg[1]);
1333 }
1334 return 0;
1335#else
1336 return printargs(tcp);
1337#endif
1338}
1339
Denys Vlasenko84703742012-02-25 02:38:52 +01001340#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001341int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001342sys_oldlstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001343{
1344 if (entering(tcp)) {
1345 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001346 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001347 } else {
1348 printoldstat(tcp, tcp->u_arg[1]);
1349 }
1350 return 0;
1351}
Denys Vlasenko84703742012-02-25 02:38:52 +01001352#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001353
Denys Vlasenko84703742012-02-25 02:38:52 +01001354#if defined(LINUXSPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001355
1356int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001357sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001358{
1359 if (entering(tcp)) {
1360 tprintf("%ld, ", tcp->u_arg[0]);
1361 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001362 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001363 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001364# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001365 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001366 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001367 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001368# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001369 printstat(tcp, tcp->u_arg[2]);
1370 }
1371 return 0;
1372}
1373
1374int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001375sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001376{
1377 if (entering(tcp))
1378 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1379 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001380# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001381 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001382 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001383 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001384# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001385 printstat(tcp, tcp->u_arg[2]);
1386 }
1387 return 0;
1388}
1389
1390int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001391sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001392{
1393 if (entering(tcp)) {
1394 tprintf("%ld, ", tcp->u_arg[0]);
1395 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001396 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001397 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001398# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001399 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001400 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001401 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001402# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001403 printstat(tcp, tcp->u_arg[2]);
1404 }
1405 return 0;
1406}
1407
1408int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001409sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001410{
1411 int mode = tcp->u_arg[2];
1412
1413 if (entering(tcp)) {
1414 tprintf("%ld, ", tcp->u_arg[0]);
1415 printpath(tcp, tcp->u_arg[1]);
1416 tprintf(", %s", sprintmode(mode));
1417 switch (mode & S_IFMT) {
1418 case S_IFCHR: case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001419 tprintf(", makedev(%lu, %lu)",
1420 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1421 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001422 break;
1423 default:
1424 break;
1425 }
1426 }
1427 return 0;
1428}
1429
Denys Vlasenko84703742012-02-25 02:38:52 +01001430# ifdef HAVE_SYS_ACL_H
Wichert Akkerman8829a551999-06-11 13:18:40 +00001431
Denys Vlasenko84703742012-02-25 02:38:52 +01001432# include <sys/acl.h>
Wichert Akkerman8829a551999-06-11 13:18:40 +00001433
Roland McGratha4d48532005-06-08 20:45:28 +00001434static const struct xlat aclcmds[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001435# ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001436 { SETACL, "SETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001437# endif
1438# ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001439 { GETACL, "GETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001440# endif
1441# ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001442 { GETACLCNT, "GETACLCNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001443# endif
1444# ifdef ACL_GET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001445 { ACL_GET, "ACL_GET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001446# endif
1447# ifdef ACL_SET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001448 { ACL_SET, "ACL_SET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001449# endif
1450# ifdef ACL_CNT
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001451 { ACL_CNT, "ACL_CNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001452# endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001453 { 0, NULL },
1454};
1455
1456int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001457sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001458{
1459 if (entering(tcp)) {
1460 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001461 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001462 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1463 tprintf(", %ld", tcp->u_arg[2]);
1464 /*
1465 * FIXME - dump out the list of aclent_t's pointed to
1466 * by "tcp->u_arg[3]" if it's not NULL.
1467 */
1468 if (tcp->u_arg[3])
1469 tprintf(", %#lx", tcp->u_arg[3]);
1470 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001471 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001472 }
1473 return 0;
1474}
1475
Wichert Akkerman8829a551999-06-11 13:18:40 +00001476int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001477sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001478{
1479 if (entering(tcp)) {
1480 tprintf("%ld, ", tcp->u_arg[0]);
1481 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1482 tprintf(", %ld", tcp->u_arg[2]);
1483 /*
1484 * FIXME - dump out the list of aclent_t's pointed to
1485 * by "tcp->u_arg[3]" if it's not NULL.
1486 */
1487 if (tcp->u_arg[3])
1488 tprintf(", %#lx", tcp->u_arg[3]);
1489 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001490 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001491 }
1492 return 0;
1493}
1494
Roland McGratha4d48532005-06-08 20:45:28 +00001495static const struct xlat aclipc[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001496# ifdef IPC_SHM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001497 { IPC_SHM, "IPC_SHM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001498# endif
1499# ifdef IPC_SEM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001500 { IPC_SEM, "IPC_SEM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001501# endif
1502# ifdef IPC_MSG
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001503 { IPC_MSG, "IPC_MSG" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001504# endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001505 { 0, NULL },
1506};
1507
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001508int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001509sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001510{
1511 if (entering(tcp)) {
1512 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1513 tprintf(", %#lx, ", tcp->u_arg[1]);
1514 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1515 tprintf(", %ld", tcp->u_arg[3]);
1516 /*
1517 * FIXME - dump out the list of aclent_t's pointed to
1518 * by "tcp->u_arg[4]" if it's not NULL.
1519 */
1520 if (tcp->u_arg[4])
1521 tprintf(", %#lx", tcp->u_arg[4]);
1522 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001523 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001524 }
1525 return 0;
1526}
1527
Denys Vlasenko84703742012-02-25 02:38:52 +01001528# endif /* HAVE_SYS_ACL_H */
Wichert Akkerman8829a551999-06-11 13:18:40 +00001529
Denys Vlasenko84703742012-02-25 02:38:52 +01001530#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001531
Roland McGrathd9f816f2004-09-04 03:39:20 +00001532static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001533 { 0x73757245, "CODA_SUPER_MAGIC" },
1534 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1535 { 0x1373, "DEVFS_SUPER_MAGIC" },
1536 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1537 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001538 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1539 { 0xef53, "EXT2_SUPER_MAGIC" },
1540 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001541 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001542 { 0x9660, "ISOFS_SUPER_MAGIC" },
1543 { 0x137f, "MINIX_SUPER_MAGIC" },
1544 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001545 { 0x2468, "MINIX2_SUPER_MAGIC" },
1546 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001547 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001548 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001549 { 0x6969, "NFS_SUPER_MAGIC" },
1550 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001551 { 0x002f, "QNX4_SUPER_MAGIC" },
1552 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1553 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1554 { 0x517b, "SMB_SUPER_MAGIC" },
1555 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1556 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1557 { 0x00011954, "UFS_MAGIC" },
1558 { 0x54190100, "UFS_CIGAM" },
1559 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001560 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001561 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001562 { 0, NULL },
1563};
1564
Roland McGrathf9c49b22004-10-06 22:11:54 +00001565static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001566sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001567{
1568 static char buf[32];
Roland McGrathf9c49b22004-10-06 22:11:54 +00001569 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001570
1571 s = xlookup(fsmagic, magic);
1572 if (s) {
1573 sprintf(buf, "\"%s\"", s);
1574 return buf;
1575 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001576 sprintf(buf, "%#x", magic);
1577 return buf;
1578}
1579
1580static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001581printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001582{
1583 struct statfs statbuf;
1584
1585 if (syserror(tcp) || !verbose(tcp)) {
1586 tprintf("%#lx", addr);
1587 return;
1588 }
1589 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001590 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001591 return;
1592 }
1593#ifdef ALPHA
1594
1595 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1596 sprintfstype(statbuf.f_type),
1597 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001598 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001599 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001600 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1601 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001602#else /* !ALPHA */
1603 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1604 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001605 (unsigned long)statbuf.f_bsize,
1606 (unsigned long)statbuf.f_blocks,
1607 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001608 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1609 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001610 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001611 (unsigned long)statbuf.f_ffree,
1612 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001613 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001614#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001615#ifdef _STATFS_F_FRSIZE
1616 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1617#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001618 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001619}
1620
1621int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001622sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001623{
1624 if (entering(tcp)) {
1625 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001626 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001627 } else {
1628 printstatfs(tcp, tcp->u_arg[1]);
1629 }
1630 return 0;
1631}
1632
1633int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001634sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001635{
1636 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001637 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001638 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001639 } else {
1640 printstatfs(tcp, tcp->u_arg[1]);
1641 }
1642 return 0;
1643}
1644
Denys Vlasenko84703742012-02-25 02:38:52 +01001645#if defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001646static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001647printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001648{
1649 struct statfs64 statbuf;
1650
1651 if (syserror(tcp) || !verbose(tcp)) {
1652 tprintf("%#lx", addr);
1653 return;
1654 }
1655 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001656 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001657 return;
1658 }
Roland McGrath08738432005-06-03 02:40:39 +00001659 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001660 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001661 (unsigned long long)statbuf.f_bsize,
1662 (unsigned long long)statbuf.f_blocks,
1663 (unsigned long long)statbuf.f_bfree);
1664 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1665 (unsigned long long)statbuf.f_bavail,
1666 (unsigned long long)statbuf.f_files,
1667 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001668 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1669 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001670#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001671 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001672#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001673#ifdef _STATFS_F_FLAGS
1674 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1675#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001676 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001677}
1678
Andreas Schwab7d558012012-01-17 18:14:22 +01001679struct compat_statfs64 {
1680 uint32_t f_type;
1681 uint32_t f_bsize;
1682 uint64_t f_blocks;
1683 uint64_t f_bfree;
1684 uint64_t f_bavail;
1685 uint64_t f_files;
1686 uint64_t f_ffree;
1687 fsid_t f_fsid;
1688 uint32_t f_namelen;
1689 uint32_t f_frsize;
1690 uint32_t f_flags;
1691 uint32_t f_spare[4];
1692}
1693#if defined(X86_64) || defined(IA64)
1694 __attribute__ ((packed, aligned(4)))
1695#endif
1696;
1697
1698static void
1699printcompat_statfs64(struct tcb *tcp, long addr)
1700{
1701 struct compat_statfs64 statbuf;
1702
1703 if (syserror(tcp) || !verbose(tcp)) {
1704 tprintf("%#lx", addr);
1705 return;
1706 }
1707 if (umove(tcp, addr, &statbuf) < 0) {
1708 tprints("{...}");
1709 return;
1710 }
1711 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1712 sprintfstype(statbuf.f_type),
1713 (unsigned long)statbuf.f_bsize,
1714 (unsigned long long)statbuf.f_blocks,
1715 (unsigned long long)statbuf.f_bfree);
1716 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1717 (unsigned long long)statbuf.f_bavail,
1718 (unsigned long long)statbuf.f_files,
1719 (unsigned long long)statbuf.f_ffree,
1720 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1721 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1722 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001723 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
Andreas Schwab7d558012012-01-17 18:14:22 +01001724}
1725
Roland McGrathab147c52003-07-17 09:03:02 +00001726int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001727sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001728{
1729 if (entering(tcp)) {
1730 printpath(tcp, tcp->u_arg[0]);
1731 tprintf(", %lu, ", tcp->u_arg[1]);
1732 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001733 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001734 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001735 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1736 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001737 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001738 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001739 }
1740 return 0;
1741}
1742
1743int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001744sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001745{
1746 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001747 printfd(tcp, tcp->u_arg[0]);
1748 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001749 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001750 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001751 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001752 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1753 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001754 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001755 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001756 }
1757 return 0;
1758}
1759#endif
1760
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001761#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001762int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001763osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001764{
1765 if (entering(tcp)) {
1766 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001767 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001768 } else {
1769 printstatfs(tcp, tcp->u_arg[1]);
1770 tprintf(", %lu", tcp->u_arg[2]);
1771 }
1772 return 0;
1773}
1774
1775int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001776osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001777{
1778 if (entering(tcp)) {
1779 tprintf("%lu, ", tcp->u_arg[0]);
1780 } else {
1781 printstatfs(tcp, tcp->u_arg[1]);
1782 tprintf(", %lu", tcp->u_arg[2]);
1783 }
1784 return 0;
1785}
Denys Vlasenko84703742012-02-25 02:38:52 +01001786#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001787
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001788/* directory */
1789int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001790sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001791{
1792 if (entering(tcp)) {
1793 printpath(tcp, tcp->u_arg[0]);
1794 }
1795 return 0;
1796}
1797
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001798static int
1799decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001800{
1801 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001802 printpath(tcp, tcp->u_arg[offset]);
1803 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001804 }
1805 return 0;
1806}
1807
1808int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001809sys_mkdir(struct tcb *tcp)
1810{
1811 return decode_mkdir(tcp, 0);
1812}
1813
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001814int
1815sys_mkdirat(struct tcb *tcp)
1816{
1817 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001818 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001819 return decode_mkdir(tcp, 1);
1820}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001821
1822int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001823sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001824{
1825 if (entering(tcp)) {
1826 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001827 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001828 printpath(tcp, tcp->u_arg[1]);
1829 }
1830 return 0;
1831}
1832
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001833int
1834sys_linkat(struct tcb *tcp)
1835{
1836 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001837 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001838 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001839 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001840 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001841 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001842 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001843 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001844 }
1845 return 0;
1846}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001847
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001848int
1849sys_unlinkat(struct tcb *tcp)
1850{
1851 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001852 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001853 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001854 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001855 printflags(at_flags, tcp->u_arg[2], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001856 }
1857 return 0;
1858}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001859
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001860int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001861sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001862{
1863 if (entering(tcp)) {
1864 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001865 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001866 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001867 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001868 }
1869 return 0;
1870}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001871
1872static int
1873decode_readlink(struct tcb *tcp, int offset)
1874{
1875 if (entering(tcp)) {
1876 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001877 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001878 } else {
1879 if (syserror(tcp))
1880 tprintf("%#lx", tcp->u_arg[offset + 1]);
1881 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001882 /* Used to use printpathn(), but readlink
1883 * neither includes NUL in the returned count,
1884 * nor actually writes it into memory.
1885 * printpathn() would decide on printing
1886 * "..." continuation based on garbage
1887 * past return buffer's end.
1888 */
1889 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001890 tprintf(", %lu", tcp->u_arg[offset + 2]);
1891 }
1892 return 0;
1893}
1894
1895int
1896sys_readlink(struct tcb *tcp)
1897{
1898 return decode_readlink(tcp, 0);
1899}
1900
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001901int
1902sys_readlinkat(struct tcb *tcp)
1903{
1904 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001905 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001906 return decode_readlink(tcp, 1);
1907}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001908
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001909int
1910sys_renameat(struct tcb *tcp)
1911{
1912 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001913 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001914 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001915 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001916 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001917 printpath(tcp, tcp->u_arg[3]);
1918 }
1919 return 0;
1920}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001921
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001922int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001923sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001924{
1925 if (entering(tcp)) {
1926 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001927 printuid(", ", tcp->u_arg[1]);
1928 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001929 }
1930 return 0;
1931}
1932
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001933int
1934sys_fchownat(struct tcb *tcp)
1935{
1936 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001937 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001938 printpath(tcp, tcp->u_arg[1]);
1939 printuid(", ", tcp->u_arg[2]);
1940 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001941 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001942 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001943 }
1944 return 0;
1945}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001946
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001947int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001948sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001949{
1950 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001951 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001952 printuid(", ", tcp->u_arg[1]);
1953 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001954 }
1955 return 0;
1956}
1957
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001958static int
1959decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001960{
1961 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001962 printpath(tcp, tcp->u_arg[offset]);
1963 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001964 }
1965 return 0;
1966}
1967
1968int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001969sys_chmod(struct tcb *tcp)
1970{
1971 return decode_chmod(tcp, 0);
1972}
1973
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001974int
1975sys_fchmodat(struct tcb *tcp)
1976{
1977 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001978 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001979 return decode_chmod(tcp, 1);
1980}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001981
1982int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001983sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001984{
1985 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001986 printfd(tcp, tcp->u_arg[0]);
1987 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001988 }
1989 return 0;
1990}
1991
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001992#ifdef ALPHA
1993int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001994sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001995{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001996 if (entering(tcp)) {
1997 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001998 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00001999 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2000 }
2001 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002002}
2003#endif
2004
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002005static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002006decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002007{
2008 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002009 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002010 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002011 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002012 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00002013 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002014 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00002015 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2016 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002017 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002018 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002019 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00002020 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002021 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00002022 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002023 }
2024 return 0;
2025}
2026
2027int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002028sys_utimes(struct tcb *tcp)
2029{
Roland McGrath6afc5652007-07-24 01:57:11 +00002030 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002031}
2032
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002033int
2034sys_futimesat(struct tcb *tcp)
2035{
2036 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002037 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002038 return decode_utimes(tcp, 1, 0);
2039}
2040
2041int
2042sys_utimensat(struct tcb *tcp)
2043{
2044 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002045 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002046 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002047 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00002048 printflags(at_flags, tcp->u_arg[3], "AT_???");
Roland McGrath6afc5652007-07-24 01:57:11 +00002049 }
2050 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002051}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002052
2053int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002054sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002055{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002056 union {
2057 long utl[2];
2058 int uti[2];
2059 } u;
Denys Vlasenko9fd4f962012-03-19 09:36:42 +01002060 unsigned wordsize = current_wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002061
2062 if (entering(tcp)) {
2063 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002064 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002065 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002066 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002067 else if (!verbose(tcp))
2068 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002069 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002070 tprints("[?, ?]");
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002071 else if (wordsize == sizeof u.utl[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002072 tprintf("[%s,", sprinttime(u.utl[0]));
2073 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002074 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002075 else if (wordsize == sizeof u.uti[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002076 tprintf("[%s,", sprinttime(u.uti[0]));
2077 tprintf(" %s]", sprinttime(u.uti[1]));
2078 }
2079 else
2080 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002081 }
2082 return 0;
2083}
2084
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002085static int
2086decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002087{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002088 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002089
2090 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002091 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002092 tprintf(", %s", sprintmode(mode));
2093 switch (mode & S_IFMT) {
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002094 case S_IFCHR:
2095 case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002096#ifdef LINUXSPARC
2097 if (current_personality == 1)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002098 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002099 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2100 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002101 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002102#endif
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002103 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002104 (unsigned long) major(tcp->u_arg[offset + 2]),
2105 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002106 break;
2107 default:
2108 break;
2109 }
2110 }
2111 return 0;
2112}
2113
2114int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002115sys_mknod(struct tcb *tcp)
2116{
2117 return decode_mknod(tcp, 0);
2118}
2119
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002120int
2121sys_mknodat(struct tcb *tcp)
2122{
2123 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002124 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002125 return decode_mknod(tcp, 1);
2126}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002127
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002128static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002129printdir(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002130{
2131 struct dirent d;
2132
2133 if (!verbose(tcp)) {
2134 tprintf("%#lx", addr);
2135 return;
2136 }
2137 if (umove(tcp, addr, &d) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002138 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002139 return;
2140 }
2141 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002142 tprints("d_name=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002143 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002144 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002145}
2146
2147int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002148sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002149{
2150 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002151 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002152 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002153 } else {
2154 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2155 tprintf("%#lx", tcp->u_arg[1]);
2156 else
2157 printdir(tcp, tcp->u_arg[1]);
2158 /* Not much point in printing this out, it is always 1. */
2159 if (tcp->u_arg[2] != 1)
2160 tprintf(", %lu", tcp->u_arg[2]);
2161 }
2162 return 0;
2163}
2164
Roland McGratha4d48532005-06-08 20:45:28 +00002165static const struct xlat direnttypes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002166 { DT_UNKNOWN, "DT_UNKNOWN" },
2167 { DT_FIFO, "DT_FIFO" },
2168 { DT_CHR, "DT_CHR" },
2169 { DT_DIR, "DT_DIR" },
2170 { DT_BLK, "DT_BLK" },
2171 { DT_REG, "DT_REG" },
2172 { DT_LNK, "DT_LNK" },
2173 { DT_SOCK, "DT_SOCK" },
2174 { DT_WHT, "DT_WHT" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002175 { 0, NULL },
2176};
2177
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002178int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002179sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002180{
2181 int i, len, dents = 0;
2182 char *buf;
2183
2184 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002185 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002186 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002187 return 0;
2188 }
2189 if (syserror(tcp) || !verbose(tcp)) {
2190 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2191 return 0;
2192 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002193 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002194 /* Beware of insanely large or negative values in tcp->u_rval */
2195 if (tcp->u_rval > 1024*1024)
2196 len = 1024*1024;
2197 if (tcp->u_rval < 0)
2198 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002199 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002200 if (len && !buf)
2201 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002202 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002203 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002204 free(buf);
2205 return 0;
2206 }
2207 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002208 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002209 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002210 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002211 if (!abbrev(tcp)) {
2212 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2213 i ? " " : "", d->d_ino, d->d_off);
2214 tprintf("d_reclen=%u, d_name=\"%s\"}",
2215 d->d_reclen, d->d_name);
2216 }
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002217 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002218 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002219 break;
2220 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002221 i += d->d_reclen;
2222 dents++;
2223 }
2224 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002225 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002226 else
2227 tprintf("/* %u entries */", dents);
2228 tprintf(", %lu", tcp->u_arg[2]);
2229 free(buf);
2230 return 0;
2231}
2232
John Hughesbdf48f52001-03-06 15:08:09 +00002233#if _LFS64_LARGEFILE
2234int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002235sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002236{
2237 int i, len, dents = 0;
2238 char *buf;
2239
2240 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002241 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002242 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002243 return 0;
2244 }
2245 if (syserror(tcp) || !verbose(tcp)) {
2246 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2247 return 0;
2248 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002249
John Hughesbdf48f52001-03-06 15:08:09 +00002250 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002251 /* Beware of insanely large or negative tcp->u_rval */
2252 if (tcp->u_rval > 1024*1024)
2253 len = 1024*1024;
2254 if (tcp->u_rval < 0)
2255 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002256 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002257 if (len && !buf)
2258 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002259
John Hughesbdf48f52001-03-06 15:08:09 +00002260 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002261 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002262 free(buf);
2263 return 0;
2264 }
2265 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002266 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002267 for (i = 0; i < len;) {
2268 struct dirent64 *d = (struct dirent64 *) &buf[i];
John Hughesbdf48f52001-03-06 15:08:09 +00002269 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002270 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002271 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002272 d->d_ino,
2273 d->d_off);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002274 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002275 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002276 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002277 tprintf("d_reclen=%u, d_name=\"%s\"}",
2278 d->d_reclen, d->d_name);
2279 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002280 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002281 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002282 break;
2283 }
John Hughesbdf48f52001-03-06 15:08:09 +00002284 i += d->d_reclen;
2285 dents++;
2286 }
2287 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002288 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002289 else
2290 tprintf("/* %u entries */", dents);
2291 tprintf(", %lu", tcp->u_arg[2]);
2292 free(buf);
2293 return 0;
2294}
2295#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002296
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002297int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002298sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002299{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002300 if (exiting(tcp)) {
2301 if (syserror(tcp))
2302 tprintf("%#lx", tcp->u_arg[0]);
2303 else
2304 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2305 tprintf(", %lu", tcp->u_arg[1]);
2306 }
2307 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002308}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002309
2310#ifdef HAVE_SYS_ASYNCH_H
2311
2312int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002313sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002314{
2315 struct aio_result_t res;
2316
2317 if (entering(tcp)) {
2318 tprintf("%lu, ", tcp->u_arg[0]);
2319 } else {
2320 if (syserror(tcp))
2321 tprintf("%#lx", tcp->u_arg[1]);
2322 else
2323 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2324 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2325 printxval(whence, tcp->u_arg[4], "L_???");
2326 if (syserror(tcp) || tcp->u_arg[5] == 0
2327 || umove(tcp, tcp->u_arg[5], &res) < 0)
2328 tprintf(", %#lx", tcp->u_arg[5]);
2329 else
2330 tprintf(", {aio_return %d aio_errno %d}",
2331 res.aio_return, res.aio_errno);
2332 }
2333 return 0;
2334}
2335
2336int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002337sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002338{
2339 struct aio_result_t res;
2340
2341 if (entering(tcp)) {
2342 tprintf("%lu, ", tcp->u_arg[0]);
2343 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2344 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2345 printxval(whence, tcp->u_arg[4], "L_???");
2346 }
2347 else {
2348 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002349 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002350 else if (syserror(tcp)
2351 || umove(tcp, tcp->u_arg[5], &res) < 0)
2352 tprintf(", %#lx", tcp->u_arg[5]);
2353 else
2354 tprintf(", {aio_return %d aio_errno %d}",
2355 res.aio_return, res.aio_errno);
2356 }
2357 return 0;
2358}
2359
2360int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002361sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002362{
2363 if (entering(tcp))
2364 printtv(tcp, tcp->u_arg[0]);
2365 return 0;
2366}
2367
2368int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002369sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002370{
2371 struct aio_result_t res;
2372
2373 if (exiting(tcp)) {
2374 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002375 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002376 else if (syserror(tcp)
2377 || umove(tcp, tcp->u_arg[0], &res) < 0)
2378 tprintf("%#lx", tcp->u_arg[0]);
2379 else
2380 tprintf("{aio_return %d aio_errno %d}",
2381 res.aio_return, res.aio_errno);
2382 }
2383 return 0;
2384}
2385
2386#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002387
Roland McGratha4d48532005-06-08 20:45:28 +00002388static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002389#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002390 { XATTR_CREATE, "XATTR_CREATE" },
2391 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002392#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002393 { 0, NULL }
2394};
2395
Roland McGrath3292e222004-08-31 06:30:48 +00002396static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002397print_xattr_val(struct tcb *tcp, int failed,
2398 unsigned long arg,
2399 unsigned long insize,
2400 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002401{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002402 if (!failed) {
2403 unsigned long capacity = 4 * size + 1;
2404 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2405 if (buf == NULL || /* probably a bogus size argument */
2406 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2407 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002408 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002409 else {
2410 unsigned char *out = buf;
2411 unsigned char *in = &buf[3 * size];
2412 size_t i;
2413 for (i = 0; i < size; ++i) {
2414 if (isprint(in[i]))
2415 *out++ = in[i];
2416 else {
2417#define tohex(n) "0123456789abcdef"[n]
2418 *out++ = '\\';
2419 *out++ = 'x';
2420 *out++ = tohex(in[i] / 16);
2421 *out++ = tohex(in[i] % 16);
2422 }
2423 }
2424 /* Don't print terminating NUL if there is one. */
2425 if (i > 0 && in[i - 1] == '\0')
2426 out -= 4;
2427 *out = '\0';
2428 tprintf(", \"%s\", %ld", buf, insize);
2429 }
2430 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002431 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002432 if (failed)
2433 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002434}
2435
Roland McGrath186c5ac2002-12-15 23:58:23 +00002436int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002437sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002438{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002439 if (entering(tcp)) {
2440 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002441 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002442 printstr(tcp, tcp->u_arg[1], -1);
2443 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002444 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002445 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2446 }
2447 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002448}
2449
2450int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002451sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002452{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002453 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002454 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002455 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002456 printstr(tcp, tcp->u_arg[1], -1);
2457 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002458 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002459 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2460 }
2461 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002462}
2463
2464int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002465sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002466{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002467 if (entering(tcp)) {
2468 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002469 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002470 printstr(tcp, tcp->u_arg[1], -1);
2471 } else {
2472 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2473 tcp->u_rval);
2474 }
2475 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002476}
2477
2478int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002479sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002480{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002481 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002482 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002483 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002484 printstr(tcp, tcp->u_arg[1], -1);
2485 } else {
2486 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2487 tcp->u_rval);
2488 }
2489 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002490}
2491
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002492static void
2493print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2494{
2495 if (syserror(tcp)) {
2496 tprintf("%#lx", addr);
2497 } else {
2498 if (!addr) {
2499 tprints("NULL");
2500 } else {
2501 unsigned long len =
2502 (size < tcp->u_rval) ? size : tcp->u_rval;
2503 printstr(tcp, addr, len);
2504 }
2505 }
2506 tprintf(", %lu", size);
2507}
2508
Roland McGrath186c5ac2002-12-15 23:58:23 +00002509int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002510sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002511{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002512 if (entering(tcp)) {
2513 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002514 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002515 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002516 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002517 }
2518 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002519}
2520
2521int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002522sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002523{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002524 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002525 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002526 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002527 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002528 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002529 }
2530 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002531}
2532
2533int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002534sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002535{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002536 if (entering(tcp)) {
2537 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002538 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002539 printstr(tcp, tcp->u_arg[1], -1);
2540 }
2541 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002542}
2543
2544int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002545sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002546{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002547 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002548 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002549 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002550 printstr(tcp, tcp->u_arg[1], -1);
2551 }
2552 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002553}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002554
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002555static const struct xlat advise[] = {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002556 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2557 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2558 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2559 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2560 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2561 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2562 { 0, NULL }
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002563};
2564
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002565int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002566sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002567{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002568 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002569 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002570 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002571 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002572 argn = printllval(tcp, "%lld", 1);
2573 tprintf(", %ld, ", tcp->u_arg[argn++]);
2574 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002575 }
2576 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002577}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002578
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002579int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002580sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002581{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002582 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002583 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002584 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002585 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002586#if defined ARM || defined POWERPC
2587 argn = printllval(tcp, "%lld, ", 2);
2588#else
2589 argn = printllval(tcp, "%lld, ", 1);
2590#endif
2591 argn = printllval(tcp, "%lld, ", argn);
2592#if defined ARM || defined POWERPC
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002593 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002594#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002595 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002596#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002597 }
2598 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002599}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002600
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002601static const struct xlat inotify_modes[] = {
Dmitry V. Levind475c062011-03-03 01:02:41 +00002602 { 0x00000001, "IN_ACCESS" },
2603 { 0x00000002, "IN_MODIFY" },
2604 { 0x00000004, "IN_ATTRIB" },
2605 { 0x00000008, "IN_CLOSE_WRITE"},
2606 { 0x00000010, "IN_CLOSE_NOWRITE"},
2607 { 0x00000020, "IN_OPEN" },
2608 { 0x00000040, "IN_MOVED_FROM" },
2609 { 0x00000080, "IN_MOVED_TO" },
2610 { 0x00000100, "IN_CREATE" },
2611 { 0x00000200, "IN_DELETE" },
2612 { 0x00000400, "IN_DELETE_SELF"},
2613 { 0x00000800, "IN_MOVE_SELF" },
2614 { 0x00002000, "IN_UNMOUNT" },
2615 { 0x00004000, "IN_Q_OVERFLOW" },
2616 { 0x00008000, "IN_IGNORED" },
2617 { 0x01000000, "IN_ONLYDIR" },
2618 { 0x02000000, "IN_DONT_FOLLOW"},
2619 { 0x20000000, "IN_MASK_ADD" },
2620 { 0x40000000, "IN_ISDIR" },
2621 { 0x80000000, "IN_ONESHOT" },
2622 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002623};
2624
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002625static const struct xlat inotify_init_flags[] = {
2626 { 0x00000800, "IN_NONBLOCK" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002627 { 0x00080000, "IN_CLOEXEC" },
2628 { 0, NULL }
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002629};
2630
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002631int
2632sys_inotify_add_watch(struct tcb *tcp)
2633{
2634 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002635 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002636 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002637 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002638 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002639 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2640 }
2641 return 0;
2642}
2643
2644int
2645sys_inotify_rm_watch(struct tcb *tcp)
2646{
2647 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002648 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levinab1a70c2012-03-11 15:33:34 +00002649 tprintf(", %d", (int) tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002650 }
2651 return 0;
2652}
Roland McGrath96a96612008-05-20 04:56:18 +00002653
2654int
Mark Wielaardbab89402010-03-21 14:41:26 +01002655sys_inotify_init1(struct tcb *tcp)
2656{
2657 if (entering(tcp))
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002658 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
Mark Wielaardbab89402010-03-21 14:41:26 +01002659 return 0;
2660}
2661
2662int
Roland McGrath96a96612008-05-20 04:56:18 +00002663sys_fallocate(struct tcb *tcp)
2664{
2665 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002666 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002667 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002668 tprints(", ");
Roland McGrath96a96612008-05-20 04:56:18 +00002669 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002670 argn = printllval(tcp, "%llu, ", 2); /* offset */
2671 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002672 }
2673 return 0;
2674}
Dmitry V. Levin88293652012-03-09 21:02:19 +00002675
Dmitry V. Levinad0c01e2012-03-15 00:52:22 +00002676#ifndef SWAP_FLAG_PREFER
2677# define SWAP_FLAG_PREFER 0x8000
2678#endif
2679#ifndef SWAP_FLAG_DISCARD
2680# define SWAP_FLAG_DISCARD 0x10000
2681#endif
Dmitry V. Levin88293652012-03-09 21:02:19 +00002682static const struct xlat swap_flags[] = {
2683 { SWAP_FLAG_PREFER, "SWAP_FLAG_PREFER" },
2684 { SWAP_FLAG_DISCARD, "SWAP_FLAG_DISCARD" },
2685 { 0, NULL }
2686};
2687
2688int
2689sys_swapon(struct tcb *tcp)
2690{
2691 if (entering(tcp)) {
2692 int flags = tcp->u_arg[1];
2693 printpath(tcp, tcp->u_arg[0]);
2694 tprints(", ");
2695 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2696 "SWAP_FLAG_???");
2697 if (flags & SWAP_FLAG_PREFER)
2698 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);
2699 }
2700 return 0;
2701}