blob: 1a448cde5dbcf63502c56c939ed19f9a4d6d8eab [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
Denys Vlasenko0c163c42012-03-17 16:26:47 +0100481#if !defined(HAVE_LONG_LONG_OFF_T)
482# if defined(LINUX_MIPSN32)
Roland McGrath542c2c62008-05-20 01:11:56 +0000483int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000484sys_lseek(struct tcb *tcp)
Roland McGrath542c2c62008-05-20 01:11:56 +0000485{
486 long long offset;
487 int _whence;
488
489 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300490 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200491 tprints(", ");
Roland McGrath542c2c62008-05-20 01:11:56 +0000492 offset = tcp->ext_arg[1];
493 _whence = tcp->u_arg[2];
494 if (_whence == SEEK_SET)
495 tprintf("%llu, ", offset);
496 else
497 tprintf("%lld, ", offset);
498 printxval(whence, _whence, "SEEK_???");
499 }
500 return RVAL_UDECIMAL;
501}
Denys Vlasenko0c163c42012-03-17 16:26:47 +0100502# else /* !LINUX_MIPSN32 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000503int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000504sys_lseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000505{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000506 off_t offset;
507 int _whence;
508
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000509 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300510 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200511 tprints(", ");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000512 offset = tcp->u_arg[1];
513 _whence = tcp->u_arg[2];
514 if (_whence == SEEK_SET)
515 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000516 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000517 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000518 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000519 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520 return RVAL_UDECIMAL;
521}
Denys Vlasenko0c163c42012-03-17 16:26:47 +0100522# endif
John Hughes5a826b82001-03-07 13:21:24 +0000523#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000524
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000526sys_llseek(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000527{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000528 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300529 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000530 /*
531 * This one call takes explicitly two 32-bit arguments hi, lo,
532 * rather than one 64-bit argument for which LONG_LONG works
533 * appropriate for the native byte order.
534 */
535 if (tcp->u_arg[4] == SEEK_SET)
Dmitry V. Levin31382132011-03-04 05:08:02 +0300536 tprintf(", %llu, ",
537 ((long long int) tcp->u_arg[1]) << 32 |
538 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000539 else
Dmitry V. Levin31382132011-03-04 05:08:02 +0300540 tprintf(", %lld, ",
541 ((long long int) tcp->u_arg[1]) << 32 |
542 (unsigned long long) (unsigned) tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000543 }
544 else {
545 long long int off;
546 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
547 tprintf("%#lx, ", tcp->u_arg[3]);
548 else
549 tprintf("[%llu], ", off);
550 printxval(whence, tcp->u_arg[4], "SEEK_???");
551 }
552 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000553}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000554
555int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000556sys_readahead(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000557{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000558 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100559 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +0300560 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200561 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100562 argn = printllval(tcp, "%lld", 1);
563 tprintf(", %ld", tcp->u_arg[argn]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000564 }
565 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000566}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000567
John Hughes70623be2001-03-08 13:59:00 +0000568#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000569int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000570sys_truncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000571{
572 if (entering(tcp)) {
573 printpath(tcp, tcp->u_arg[0]);
574 tprintf(", %lu", tcp->u_arg[1]);
575 }
576 return 0;
577}
John Hughes5a826b82001-03-07 13:21:24 +0000578#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000579
John Hughes70623be2001-03-08 13:59:00 +0000580#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000581int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000582sys_truncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000583{
584 if (entering(tcp)) {
585 printpath(tcp, tcp->u_arg[0]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100586 printllval(tcp, ", %llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000587 }
588 return 0;
589}
590#endif
591
John Hughes70623be2001-03-08 13:59:00 +0000592#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000593int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000594sys_ftruncate(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000595{
596 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300597 printfd(tcp, tcp->u_arg[0]);
598 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000599 }
600 return 0;
601}
John Hughes5a826b82001-03-07 13:21:24 +0000602#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000603
John Hughes70623be2001-03-08 13:59:00 +0000604#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000605int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000606sys_ftruncate64(struct tcb *tcp)
John Hughes96f51472001-03-06 16:50:41 +0000607{
608 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300609 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200610 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100611 printllval(tcp, "%llu", 1);
John Hughes96f51472001-03-06 16:50:41 +0000612 }
613 return 0;
614}
615#endif
616
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000617/* several stats */
618
Roland McGrathd9f816f2004-09-04 03:39:20 +0000619static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000620 { S_IFREG, "S_IFREG" },
621 { S_IFSOCK, "S_IFSOCK" },
622 { S_IFIFO, "S_IFIFO" },
623 { S_IFLNK, "S_IFLNK" },
624 { S_IFDIR, "S_IFDIR" },
625 { S_IFBLK, "S_IFBLK" },
626 { S_IFCHR, "S_IFCHR" },
627 { 0, NULL },
628};
629
Roland McGrathf9c49b22004-10-06 22:11:54 +0000630static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +0000631sprintmode(int mode)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000632{
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100633 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
634 + sizeof(int)*3
635 + /*paranoia:*/ 8];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000636 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000637
638 if ((mode & S_IFMT) == 0)
639 s = "";
640 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
641 sprintf(buf, "%#o", mode);
642 return buf;
643 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100644 s = buf + sprintf(buf, "%s%s%s%s", s,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000645 (mode & S_ISUID) ? "|S_ISUID" : "",
646 (mode & S_ISGID) ? "|S_ISGID" : "",
647 (mode & S_ISVTX) ? "|S_ISVTX" : "");
648 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
649 if (mode)
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100650 sprintf((char*)s, "|%#o", mode);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000651 s = (*buf == '|') ? buf + 1 : buf;
652 return *s ? s : "0";
653}
654
655static char *
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000656sprinttime(time_t t)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000657{
658 struct tm *tmp;
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100659 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000660
661 if (t == 0) {
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000662 strcpy(buf, "0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000663 return buf;
664 }
Denys Vlasenko5d645812011-08-20 12:48:18 +0200665 tmp = localtime(&t);
666 if (tmp)
Dmitry V. Levindc7715b2008-04-19 23:45:09 +0000667 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
668 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
669 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
670 else
671 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
672
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000673 return buf;
674}
675
676#ifdef LINUXSPARC
677typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000678 int tv_sec;
679 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000680} timestruct_t;
681
682struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000683 unsigned st_dev;
684 int st_pad1[3]; /* network id */
685 unsigned st_ino;
686 unsigned st_mode;
687 unsigned st_nlink;
688 unsigned st_uid;
689 unsigned st_gid;
690 unsigned st_rdev;
691 int st_pad2[2];
692 int st_size;
693 int st_pad3; /* st_size, off_t expansion */
694 timestruct_t st_atime;
695 timestruct_t st_mtime;
696 timestruct_t st_ctime;
697 int st_blksize;
698 int st_blocks;
699 char st_fstype[16];
700 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000701};
702
703static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000704printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000705{
706 struct solstat statbuf;
707
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000708 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200709 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000710 return;
711 }
712 if (!abbrev(tcp)) {
713 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
714 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
715 (unsigned long) (statbuf.st_dev & 0x3ffff),
716 (unsigned long) statbuf.st_ino,
717 sprintmode(statbuf.st_mode));
718 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
719 (unsigned long) statbuf.st_nlink,
720 (unsigned long) statbuf.st_uid,
721 (unsigned long) statbuf.st_gid);
722 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
723 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
724 }
725 else
726 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
727 switch (statbuf.st_mode & S_IFMT) {
728 case S_IFCHR: case S_IFBLK:
729 tprintf("st_rdev=makedev(%lu, %lu), ",
730 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
731 (unsigned long) (statbuf.st_rdev & 0x3ffff));
732 break;
733 default:
734 tprintf("st_size=%u, ", statbuf.st_size);
735 break;
736 }
737 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000738 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
739 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
740 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000741 }
742 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200743 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000744}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000745
Denys Vlasenkoc36c3522012-02-25 02:47:15 +0100746#if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000747static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000748printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000749{
750 struct stat_sparc64 statbuf;
751
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000752 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200753 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000754 return;
755 }
756
757 if (!abbrev(tcp)) {
758 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
759 (unsigned long) major(statbuf.st_dev),
760 (unsigned long) minor(statbuf.st_dev),
761 (unsigned long) statbuf.st_ino,
762 sprintmode(statbuf.st_mode));
763 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
764 (unsigned long) statbuf.st_nlink,
765 (unsigned long) statbuf.st_uid,
766 (unsigned long) statbuf.st_gid);
767 tprintf("st_blksize=%lu, ",
768 (unsigned long) statbuf.st_blksize);
769 tprintf("st_blocks=%lu, ",
770 (unsigned long) statbuf.st_blocks);
771 }
772 else
773 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
774 switch (statbuf.st_mode & S_IFMT) {
775 case S_IFCHR: case S_IFBLK:
776 tprintf("st_rdev=makedev(%lu, %lu), ",
777 (unsigned long) major(statbuf.st_rdev),
778 (unsigned long) minor(statbuf.st_rdev));
779 break;
780 default:
781 tprintf("st_size=%lu, ", statbuf.st_size);
782 break;
783 }
784 if (!abbrev(tcp)) {
785 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
786 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100787 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000788 }
789 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200790 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000791}
792#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000793#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000794
Denys Vlasenko84703742012-02-25 02:38:52 +0100795#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200796struct stat_powerpc32 {
797 unsigned int st_dev;
798 unsigned int st_ino;
799 unsigned int st_mode;
800 unsigned short st_nlink;
801 unsigned int st_uid;
802 unsigned int st_gid;
803 unsigned int st_rdev;
804 unsigned int st_size;
805 unsigned int st_blksize;
806 unsigned int st_blocks;
807 unsigned int st_atime;
808 unsigned int st_atime_nsec;
809 unsigned int st_mtime;
810 unsigned int st_mtime_nsec;
811 unsigned int st_ctime;
812 unsigned int st_ctime_nsec;
813 unsigned int __unused4;
814 unsigned int __unused5;
815};
816
817static void
818printstat_powerpc32(struct tcb *tcp, long addr)
819{
820 struct stat_powerpc32 statbuf;
821
822 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200823 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200824 return;
825 }
826
827 if (!abbrev(tcp)) {
828 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
829 major(statbuf.st_dev), minor(statbuf.st_dev),
830 statbuf.st_ino,
831 sprintmode(statbuf.st_mode));
832 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
833 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
834 tprintf("st_blksize=%u, ", statbuf.st_blksize);
835 tprintf("st_blocks=%u, ", statbuf.st_blocks);
836 }
837 else
838 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
839 switch (statbuf.st_mode & S_IFMT) {
840 case S_IFCHR: case S_IFBLK:
841 tprintf("st_rdev=makedev(%lu, %lu), ",
842 (unsigned long) major(statbuf.st_rdev),
843 (unsigned long) minor(statbuf.st_rdev));
844 break;
845 default:
846 tprintf("st_size=%u, ", statbuf.st_size);
847 break;
848 }
849 if (!abbrev(tcp)) {
850 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
851 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100852 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200853 }
854 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200855 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200856}
Denys Vlasenko84703742012-02-25 02:38:52 +0100857#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200858
Roland McGratha4d48532005-06-08 20:45:28 +0000859static const struct xlat fileflags[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000860 { 0, NULL },
861};
862
John Hughes70623be2001-03-08 13:59:00 +0000863#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000864static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000865realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000866{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000867 if (!abbrev(tcp)) {
868 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
869 (unsigned long) major(statbuf->st_dev),
870 (unsigned long) minor(statbuf->st_dev),
871 (unsigned long) statbuf->st_ino,
872 sprintmode(statbuf->st_mode));
873 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
874 (unsigned long) statbuf->st_nlink,
875 (unsigned long) statbuf->st_uid,
876 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000877#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000878 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
879#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000880#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000881 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
882#endif
883 }
884 else
885 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
886 switch (statbuf->st_mode & S_IFMT) {
887 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000888#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000889 tprintf("st_rdev=makedev(%lu, %lu), ",
890 (unsigned long) major(statbuf->st_rdev),
891 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000892#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000893 tprintf("st_size=makedev(%lu, %lu), ",
894 (unsigned long) major(statbuf->st_size),
895 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000896#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000897 break;
898 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000899 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000900 break;
901 }
902 if (!abbrev(tcp)) {
903 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
904 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
905 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000906#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200907 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000908 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000909#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000910#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000911 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
912#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000913#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000914 tprintf(", st_level=%ld", statbuf->st_level);
915#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000916#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000917 tprintf(", st_fstype=%.*s",
918 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
919#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000920#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000921 tprintf(", st_gen=%u", statbuf->st_gen);
922#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200923 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000924 }
925 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200926 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000927}
928
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000929static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000930printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000931{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000932 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000933
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000934 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200935 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000936 return;
937 }
938 if (syserror(tcp) || !verbose(tcp)) {
939 tprintf("%#lx", addr);
940 return;
941 }
942
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000943#ifdef LINUXSPARC
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000944 if (current_personality == 1) {
945 printstatsol(tcp, addr);
946 return;
947 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000948#ifdef SPARC64
949 else if (current_personality == 2) {
950 printstat_sparc64(tcp, addr);
951 return;
952 }
953#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000954#endif /* LINUXSPARC */
955
Denys Vlasenko84703742012-02-25 02:38:52 +0100956#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200957 if (current_personality == 1) {
958 printstat_powerpc32(tcp, addr);
959 return;
960 }
961#endif
962
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000963 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200964 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000965 return;
966 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000967
968 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000969}
John Hughes70623be2001-03-08 13:59:00 +0000970#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000971
Denys Vlasenko84703742012-02-25 02:38:52 +0100972#if !defined HAVE_STAT64 && defined X86_64
Roland McGrathe6d0f712007-08-07 01:22:49 +0000973/*
974 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
975 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
976 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
977 * __GNUC__ is needed for the required __attribute__ below.
978 */
979struct stat64 {
980 unsigned long long st_dev;
981 unsigned char __pad0[4];
982 unsigned int __st_ino;
983 unsigned int st_mode;
984 unsigned int st_nlink;
985 unsigned int st_uid;
986 unsigned int st_gid;
987 unsigned long long st_rdev;
988 unsigned char __pad3[4];
989 long long st_size;
990 unsigned int st_blksize;
991 unsigned long long st_blocks;
992 unsigned int st_atime;
993 unsigned int st_atime_nsec;
994 unsigned int st_mtime;
995 unsigned int st_mtime_nsec;
996 unsigned int st_ctime;
997 unsigned int st_ctime_nsec;
998 unsigned long long st_ino;
999} __attribute__((packed));
1000# define HAVE_STAT64 1
1001# define STAT64_SIZE 96
1002#endif
1003
Wichert Akkermanc7926982000-04-10 22:22:31 +00001004#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001005static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001006printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001007{
1008 struct stat64 statbuf;
1009
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001010#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +00001011 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1012#endif
1013
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001014 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001015 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001016 return;
1017 }
1018 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001019 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001020 return;
1021 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001022
1023#ifdef LINUXSPARC
1024 if (current_personality == 1) {
1025 printstatsol(tcp, addr);
1026 return;
1027 }
1028# ifdef SPARC64
1029 else if (current_personality == 2) {
1030 printstat_sparc64(tcp, addr);
1031 return;
1032 }
1033# endif
1034#endif /* LINUXSPARC */
1035
Denys Vlasenko84703742012-02-25 02:38:52 +01001036#if defined X86_64
Andreas Schwab61b74352009-10-16 11:37:13 +02001037 if (current_personality == 0) {
1038 printstat(tcp, addr);
1039 return;
1040 }
1041#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +00001042
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001043 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001044 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001045 return;
1046 }
1047
1048 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +00001049#ifdef HAVE_LONG_LONG
1050 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1051#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001052 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001053#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001054 (unsigned long) major(statbuf.st_dev),
1055 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001056#ifdef HAVE_LONG_LONG
1057 (unsigned long long) statbuf.st_ino,
1058#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001059 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001060#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001061 sprintmode(statbuf.st_mode));
1062 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1063 (unsigned long) statbuf.st_nlink,
1064 (unsigned long) statbuf.st_uid,
1065 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001066#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001067 tprintf("st_blksize=%lu, ",
1068 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001069#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1070#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001071 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001072#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001073 }
1074 else
1075 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1076 switch (statbuf.st_mode & S_IFMT) {
1077 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001078#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001079 tprintf("st_rdev=makedev(%lu, %lu), ",
1080 (unsigned long) major(statbuf.st_rdev),
1081 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001082#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001083 tprintf("st_size=makedev(%lu, %lu), ",
1084 (unsigned long) major(statbuf.st_size),
1085 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001086#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001087 break;
1088 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +00001089#ifdef HAVE_LONG_LONG
1090 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1091#else
1092 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1093#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001094 break;
1095 }
1096 if (!abbrev(tcp)) {
1097 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1098 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001099 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001100#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001101 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001102 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001103#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001104#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001105 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1106#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001107#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001108 tprintf(", st_level=%ld", statbuf.st_level);
1109#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001110#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001111 tprintf(", st_fstype=%.*s",
1112 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1113#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001114#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001115 tprintf(", st_gen=%u", statbuf.st_gen);
1116#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001117 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001118 }
1119 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001120 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001121}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001122#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001123
Denys Vlasenko84703742012-02-25 02:38:52 +01001124#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001125static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001126convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001127{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001128 newbuf->st_dev = oldbuf->st_dev;
1129 newbuf->st_ino = oldbuf->st_ino;
1130 newbuf->st_mode = oldbuf->st_mode;
1131 newbuf->st_nlink = oldbuf->st_nlink;
1132 newbuf->st_uid = oldbuf->st_uid;
1133 newbuf->st_gid = oldbuf->st_gid;
1134 newbuf->st_rdev = oldbuf->st_rdev;
1135 newbuf->st_size = oldbuf->st_size;
1136 newbuf->st_atime = oldbuf->st_atime;
1137 newbuf->st_mtime = oldbuf->st_mtime;
1138 newbuf->st_ctime = oldbuf->st_ctime;
1139 newbuf->st_blksize = 0; /* not supported in old_stat */
1140 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001141}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001142
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001143static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001144printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001145{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001146 struct __old_kernel_stat statbuf;
1147 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001148
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001149 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001150 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001151 return;
1152 }
1153 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001154 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001155 return;
1156 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001157
Denys Vlasenko84703742012-02-25 02:38:52 +01001158# ifdef LINUXSPARC
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001159 if (current_personality == 1) {
1160 printstatsol(tcp, addr);
1161 return;
1162 }
Denys Vlasenko84703742012-02-25 02:38:52 +01001163# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +00001164
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001165 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001166 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001167 return;
1168 }
1169
1170 convertoldstat(&statbuf, &newstatbuf);
1171 realprintstat(tcp, &newstatbuf);
1172}
Denys Vlasenko84703742012-02-25 02:38:52 +01001173#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001174
John Hughes70623be2001-03-08 13:59:00 +00001175#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001176int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001177sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001178{
1179 if (entering(tcp)) {
1180 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001181 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001182 } else {
1183 printstat(tcp, tcp->u_arg[1]);
1184 }
1185 return 0;
1186}
John Hughesb8c9f772001-03-07 16:53:07 +00001187#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001188
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001189int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001190sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001191{
1192#ifdef HAVE_STAT64
1193 if (entering(tcp)) {
1194 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001195 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001196 } else {
1197 printstat64(tcp, tcp->u_arg[1]);
1198 }
1199 return 0;
1200#else
1201 return printargs(tcp);
1202#endif
1203}
1204
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001205#ifndef AT_SYMLINK_NOFOLLOW
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001206# define AT_SYMLINK_NOFOLLOW 0x100
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001207#endif
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001208#ifndef AT_REMOVEDIR
1209# define AT_REMOVEDIR 0x200
1210#endif
1211#ifndef AT_SYMLINK_FOLLOW
1212# define AT_SYMLINK_FOLLOW 0x400
1213#endif
1214#ifndef AT_NO_AUTOMOUNT
1215# define AT_NO_AUTOMOUNT 0x800
1216#endif
1217#ifndef AT_EMPTY_PATH
1218# define AT_EMPTY_PATH 0x1000
1219#endif
1220
1221static const struct xlat at_flags[] = {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001222 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001223 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1224 { AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" },
1225 { AT_NO_AUTOMOUNT, "AT_NO_AUTOMOUNT" },
1226 { AT_EMPTY_PATH, "AT_EMPTY_PATH" },
1227 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001228};
1229
1230int
1231sys_newfstatat(struct tcb *tcp)
1232{
1233 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001234 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001235 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001236 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001237 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +02001238#ifdef POWERPC64
1239 if (current_personality == 0)
1240 printstat(tcp, tcp->u_arg[2]);
1241 else
1242 printstat64(tcp, tcp->u_arg[2]);
1243#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001244 printstat64(tcp, tcp->u_arg[2]);
1245#else
1246 printstat(tcp, tcp->u_arg[2]);
1247#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001248 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001249 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001250 }
1251 return 0;
1252}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001253
Denys Vlasenko84703742012-02-25 02:38:52 +01001254#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001255int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001256sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001257{
1258 if (entering(tcp)) {
1259 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001260 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001261 } else {
1262 printoldstat(tcp, tcp->u_arg[1]);
1263 }
1264 return 0;
1265}
Denys Vlasenko84703742012-02-25 02:38:52 +01001266#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001267
John Hughes70623be2001-03-08 13:59:00 +00001268#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001269int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001270sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001271{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001272 if (entering(tcp)) {
1273 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001274 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001275 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001276 printstat(tcp, tcp->u_arg[1]);
1277 }
1278 return 0;
1279}
John Hughesb8c9f772001-03-07 16:53:07 +00001280#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001281
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001282int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001283sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001284{
1285#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +03001286 if (entering(tcp)) {
1287 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001288 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001289 } else {
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001290 printstat64(tcp, tcp->u_arg[1]);
1291 }
1292 return 0;
1293#else
1294 return printargs(tcp);
1295#endif
1296}
1297
Denys Vlasenko84703742012-02-25 02:38:52 +01001298#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001299int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001300sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001301{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001302 if (entering(tcp)) {
1303 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001304 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001305 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001306 printoldstat(tcp, tcp->u_arg[1]);
1307 }
1308 return 0;
1309}
Denys Vlasenko84703742012-02-25 02:38:52 +01001310#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001311
John Hughes70623be2001-03-08 13:59:00 +00001312#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001313int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001314sys_lstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001315{
1316 if (entering(tcp)) {
1317 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001318 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001319 } else {
1320 printstat(tcp, tcp->u_arg[1]);
1321 }
1322 return 0;
1323}
John Hughesb8c9f772001-03-07 16:53:07 +00001324#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001325
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001326int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001327sys_lstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001328{
1329#ifdef HAVE_STAT64
1330 if (entering(tcp)) {
1331 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001332 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001333 } else {
1334 printstat64(tcp, tcp->u_arg[1]);
1335 }
1336 return 0;
1337#else
1338 return printargs(tcp);
1339#endif
1340}
1341
Denys Vlasenko84703742012-02-25 02:38:52 +01001342#if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001343int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001344sys_oldlstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001345{
1346 if (entering(tcp)) {
1347 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001348 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001349 } else {
1350 printoldstat(tcp, tcp->u_arg[1]);
1351 }
1352 return 0;
1353}
Denys Vlasenko84703742012-02-25 02:38:52 +01001354#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001355
Denys Vlasenko84703742012-02-25 02:38:52 +01001356#if defined(LINUXSPARC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001357
1358int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001359sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001360{
1361 if (entering(tcp)) {
1362 tprintf("%ld, ", tcp->u_arg[0]);
1363 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001364 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001365 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001366# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001367 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001368 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001369 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001370# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001371 printstat(tcp, tcp->u_arg[2]);
1372 }
1373 return 0;
1374}
1375
1376int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001377sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001378{
1379 if (entering(tcp))
1380 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1381 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001382# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001383 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001384 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001385 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001386# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001387 printstat(tcp, tcp->u_arg[2]);
1388 }
1389 return 0;
1390}
1391
1392int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001393sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001394{
1395 if (entering(tcp)) {
1396 tprintf("%ld, ", tcp->u_arg[0]);
1397 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001398 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001399 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001400# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001401 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001402 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001403 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001404# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001405 printstat(tcp, tcp->u_arg[2]);
1406 }
1407 return 0;
1408}
1409
1410int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001411sys_xmknod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001412{
1413 int mode = tcp->u_arg[2];
1414
1415 if (entering(tcp)) {
1416 tprintf("%ld, ", tcp->u_arg[0]);
1417 printpath(tcp, tcp->u_arg[1]);
1418 tprintf(", %s", sprintmode(mode));
1419 switch (mode & S_IFMT) {
1420 case S_IFCHR: case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001421 tprintf(", makedev(%lu, %lu)",
1422 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1423 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001424 break;
1425 default:
1426 break;
1427 }
1428 }
1429 return 0;
1430}
1431
Denys Vlasenko84703742012-02-25 02:38:52 +01001432# ifdef HAVE_SYS_ACL_H
Wichert Akkerman8829a551999-06-11 13:18:40 +00001433
Denys Vlasenko84703742012-02-25 02:38:52 +01001434# include <sys/acl.h>
Wichert Akkerman8829a551999-06-11 13:18:40 +00001435
Roland McGratha4d48532005-06-08 20:45:28 +00001436static const struct xlat aclcmds[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001437# ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001438 { SETACL, "SETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001439# endif
1440# ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001441 { GETACL, "GETACL" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001442# endif
1443# ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001444 { GETACLCNT, "GETACLCNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001445# endif
1446# ifdef ACL_GET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001447 { ACL_GET, "ACL_GET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001448# endif
1449# ifdef ACL_SET
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001450 { ACL_SET, "ACL_SET" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001451# endif
1452# ifdef ACL_CNT
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001453 { ACL_CNT, "ACL_CNT" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001454# endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001455 { 0, NULL },
1456};
1457
1458int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001459sys_acl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001460{
1461 if (entering(tcp)) {
1462 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001463 tprints(", ");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001464 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1465 tprintf(", %ld", tcp->u_arg[2]);
1466 /*
1467 * FIXME - dump out the list of aclent_t's pointed to
1468 * by "tcp->u_arg[3]" if it's not NULL.
1469 */
1470 if (tcp->u_arg[3])
1471 tprintf(", %#lx", tcp->u_arg[3]);
1472 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001473 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001474 }
1475 return 0;
1476}
1477
Wichert Akkerman8829a551999-06-11 13:18:40 +00001478int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001479sys_facl(struct tcb *tcp)
Wichert Akkerman8829a551999-06-11 13:18:40 +00001480{
1481 if (entering(tcp)) {
1482 tprintf("%ld, ", tcp->u_arg[0]);
1483 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1484 tprintf(", %ld", tcp->u_arg[2]);
1485 /*
1486 * FIXME - dump out the list of aclent_t's pointed to
1487 * by "tcp->u_arg[3]" if it's not NULL.
1488 */
1489 if (tcp->u_arg[3])
1490 tprintf(", %#lx", tcp->u_arg[3]);
1491 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001492 tprints(", NULL");
Wichert Akkerman8829a551999-06-11 13:18:40 +00001493 }
1494 return 0;
1495}
1496
Roland McGratha4d48532005-06-08 20:45:28 +00001497static const struct xlat aclipc[] = {
Denys Vlasenko84703742012-02-25 02:38:52 +01001498# ifdef IPC_SHM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001499 { IPC_SHM, "IPC_SHM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001500# endif
1501# ifdef IPC_SEM
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001502 { IPC_SEM, "IPC_SEM" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001503# endif
1504# ifdef IPC_MSG
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001505 { IPC_MSG, "IPC_MSG" },
Denys Vlasenko84703742012-02-25 02:38:52 +01001506# endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001507 { 0, NULL },
1508};
1509
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001510int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001511sys_aclipc(struct tcb *tcp)
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001512{
1513 if (entering(tcp)) {
1514 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1515 tprintf(", %#lx, ", tcp->u_arg[1]);
1516 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1517 tprintf(", %ld", tcp->u_arg[3]);
1518 /*
1519 * FIXME - dump out the list of aclent_t's pointed to
1520 * by "tcp->u_arg[4]" if it's not NULL.
1521 */
1522 if (tcp->u_arg[4])
1523 tprintf(", %#lx", tcp->u_arg[4]);
1524 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001525 tprints(", NULL");
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001526 }
1527 return 0;
1528}
1529
Denys Vlasenko84703742012-02-25 02:38:52 +01001530# endif /* HAVE_SYS_ACL_H */
Wichert Akkerman8829a551999-06-11 13:18:40 +00001531
Denys Vlasenko84703742012-02-25 02:38:52 +01001532#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001533
Roland McGrathd9f816f2004-09-04 03:39:20 +00001534static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001535 { 0x73757245, "CODA_SUPER_MAGIC" },
1536 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1537 { 0x1373, "DEVFS_SUPER_MAGIC" },
1538 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1539 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001540 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1541 { 0xef53, "EXT2_SUPER_MAGIC" },
1542 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001543 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001544 { 0x9660, "ISOFS_SUPER_MAGIC" },
1545 { 0x137f, "MINIX_SUPER_MAGIC" },
1546 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001547 { 0x2468, "MINIX2_SUPER_MAGIC" },
1548 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001549 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001550 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001551 { 0x6969, "NFS_SUPER_MAGIC" },
1552 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001553 { 0x002f, "QNX4_SUPER_MAGIC" },
1554 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1555 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1556 { 0x517b, "SMB_SUPER_MAGIC" },
1557 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1558 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1559 { 0x00011954, "UFS_MAGIC" },
1560 { 0x54190100, "UFS_CIGAM" },
1561 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001562 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001563 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001564 { 0, NULL },
1565};
1566
Roland McGrathf9c49b22004-10-06 22:11:54 +00001567static const char *
Denys Vlasenko1d632462009-04-14 12:51:00 +00001568sprintfstype(int magic)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001569{
1570 static char buf[32];
Roland McGrathf9c49b22004-10-06 22:11:54 +00001571 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001572
1573 s = xlookup(fsmagic, magic);
1574 if (s) {
1575 sprintf(buf, "\"%s\"", s);
1576 return buf;
1577 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001578 sprintf(buf, "%#x", magic);
1579 return buf;
1580}
1581
1582static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001583printstatfs(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001584{
1585 struct statfs statbuf;
1586
1587 if (syserror(tcp) || !verbose(tcp)) {
1588 tprintf("%#lx", addr);
1589 return;
1590 }
1591 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001592 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001593 return;
1594 }
1595#ifdef ALPHA
1596
1597 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1598 sprintfstype(statbuf.f_type),
1599 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001600 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001601 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001602 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1603 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001604#else /* !ALPHA */
1605 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1606 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001607 (unsigned long)statbuf.f_bsize,
1608 (unsigned long)statbuf.f_blocks,
1609 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001610 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1611 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001612 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001613 (unsigned long)statbuf.f_ffree,
1614 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001615 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001616#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001617#ifdef _STATFS_F_FRSIZE
1618 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1619#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001620 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001621}
1622
1623int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001624sys_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001625{
1626 if (entering(tcp)) {
1627 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001628 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001629 } else {
1630 printstatfs(tcp, tcp->u_arg[1]);
1631 }
1632 return 0;
1633}
1634
1635int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001636sys_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001637{
1638 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001639 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001640 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001641 } else {
1642 printstatfs(tcp, tcp->u_arg[1]);
1643 }
1644 return 0;
1645}
1646
Denys Vlasenko84703742012-02-25 02:38:52 +01001647#if defined HAVE_STATFS64
Roland McGrathab147c52003-07-17 09:03:02 +00001648static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00001649printstatfs64(struct tcb *tcp, long addr)
Roland McGrathab147c52003-07-17 09:03:02 +00001650{
1651 struct statfs64 statbuf;
1652
1653 if (syserror(tcp) || !verbose(tcp)) {
1654 tprintf("%#lx", addr);
1655 return;
1656 }
1657 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001658 tprints("{...}");
Roland McGrathab147c52003-07-17 09:03:02 +00001659 return;
1660 }
Roland McGrath08738432005-06-03 02:40:39 +00001661 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001662 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001663 (unsigned long long)statbuf.f_bsize,
1664 (unsigned long long)statbuf.f_blocks,
1665 (unsigned long long)statbuf.f_bfree);
1666 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1667 (unsigned long long)statbuf.f_bavail,
1668 (unsigned long long)statbuf.f_files,
1669 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001670 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1671 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001672#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001673 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001674#endif
Andreas Schwab000d66f2012-01-17 18:13:33 +01001675#ifdef _STATFS_F_FLAGS
1676 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1677#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001678 tprints("}");
Roland McGrathab147c52003-07-17 09:03:02 +00001679}
1680
Andreas Schwab7d558012012-01-17 18:14:22 +01001681struct compat_statfs64 {
1682 uint32_t f_type;
1683 uint32_t f_bsize;
1684 uint64_t f_blocks;
1685 uint64_t f_bfree;
1686 uint64_t f_bavail;
1687 uint64_t f_files;
1688 uint64_t f_ffree;
1689 fsid_t f_fsid;
1690 uint32_t f_namelen;
1691 uint32_t f_frsize;
1692 uint32_t f_flags;
1693 uint32_t f_spare[4];
1694}
1695#if defined(X86_64) || defined(IA64)
1696 __attribute__ ((packed, aligned(4)))
1697#endif
1698;
1699
1700static void
1701printcompat_statfs64(struct tcb *tcp, long addr)
1702{
1703 struct compat_statfs64 statbuf;
1704
1705 if (syserror(tcp) || !verbose(tcp)) {
1706 tprintf("%#lx", addr);
1707 return;
1708 }
1709 if (umove(tcp, addr, &statbuf) < 0) {
1710 tprints("{...}");
1711 return;
1712 }
1713 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1714 sprintfstype(statbuf.f_type),
1715 (unsigned long)statbuf.f_bsize,
1716 (unsigned long long)statbuf.f_blocks,
1717 (unsigned long long)statbuf.f_bfree);
1718 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1719 (unsigned long long)statbuf.f_bavail,
1720 (unsigned long long)statbuf.f_files,
1721 (unsigned long long)statbuf.f_ffree,
1722 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1723 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1724 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01001725 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
Andreas Schwab7d558012012-01-17 18:14:22 +01001726}
1727
Roland McGrathab147c52003-07-17 09:03:02 +00001728int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001729sys_statfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001730{
1731 if (entering(tcp)) {
1732 printpath(tcp, tcp->u_arg[0]);
1733 tprintf(", %lu, ", tcp->u_arg[1]);
1734 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001735 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001736 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001737 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1738 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001739 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001740 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001741 }
1742 return 0;
1743}
1744
1745int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001746sys_fstatfs64(struct tcb *tcp)
Roland McGrathab147c52003-07-17 09:03:02 +00001747{
1748 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001749 printfd(tcp, tcp->u_arg[0]);
1750 tprintf(", %lu, ", tcp->u_arg[1]);
Roland McGrathab147c52003-07-17 09:03:02 +00001751 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001752 if (tcp->u_arg[1] == sizeof(struct statfs64))
Roland McGrathab147c52003-07-17 09:03:02 +00001753 printstatfs64(tcp, tcp->u_arg[2]);
Andreas Schwab7d558012012-01-17 18:14:22 +01001754 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1755 printcompat_statfs64(tcp, tcp->u_arg[2]);
Roland McGrathab147c52003-07-17 09:03:02 +00001756 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001757 tprints("{???}");
Roland McGrathab147c52003-07-17 09:03:02 +00001758 }
1759 return 0;
1760}
1761#endif
1762
Denys Vlasenkoc36c3522012-02-25 02:47:15 +01001763#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001764int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001765osf_statfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001766{
1767 if (entering(tcp)) {
1768 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001769 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001770 } else {
1771 printstatfs(tcp, tcp->u_arg[1]);
1772 tprintf(", %lu", tcp->u_arg[2]);
1773 }
1774 return 0;
1775}
1776
1777int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001778osf_fstatfs(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001779{
1780 if (entering(tcp)) {
1781 tprintf("%lu, ", tcp->u_arg[0]);
1782 } else {
1783 printstatfs(tcp, tcp->u_arg[1]);
1784 tprintf(", %lu", tcp->u_arg[2]);
1785 }
1786 return 0;
1787}
Denys Vlasenko84703742012-02-25 02:38:52 +01001788#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001789
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001790/* directory */
1791int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001792sys_chdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001793{
1794 if (entering(tcp)) {
1795 printpath(tcp, tcp->u_arg[0]);
1796 }
1797 return 0;
1798}
1799
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001800static int
1801decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001802{
1803 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001804 printpath(tcp, tcp->u_arg[offset]);
1805 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001806 }
1807 return 0;
1808}
1809
1810int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001811sys_mkdir(struct tcb *tcp)
1812{
1813 return decode_mkdir(tcp, 0);
1814}
1815
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001816int
1817sys_mkdirat(struct tcb *tcp)
1818{
1819 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001820 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001821 return decode_mkdir(tcp, 1);
1822}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001823
1824int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001825sys_link(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001826{
1827 if (entering(tcp)) {
1828 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001829 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001830 printpath(tcp, tcp->u_arg[1]);
1831 }
1832 return 0;
1833}
1834
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001835int
1836sys_linkat(struct tcb *tcp)
1837{
1838 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001839 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001840 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001841 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001842 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001843 printpath(tcp, tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001844 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001845 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001846 }
1847 return 0;
1848}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001849
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001850int
1851sys_unlinkat(struct tcb *tcp)
1852{
1853 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001854 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001855 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001856 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001857 printflags(at_flags, tcp->u_arg[2], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001858 }
1859 return 0;
1860}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001861
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001862int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001863sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001864{
1865 if (entering(tcp)) {
1866 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001867 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001868 print_dirfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001869 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001870 }
1871 return 0;
1872}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001873
1874static int
1875decode_readlink(struct tcb *tcp, int offset)
1876{
1877 if (entering(tcp)) {
1878 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001879 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001880 } else {
1881 if (syserror(tcp))
1882 tprintf("%#lx", tcp->u_arg[offset + 1]);
1883 else
Denys Vlasenko3449ae82012-01-27 17:24:26 +01001884 /* Used to use printpathn(), but readlink
1885 * neither includes NUL in the returned count,
1886 * nor actually writes it into memory.
1887 * printpathn() would decide on printing
1888 * "..." continuation based on garbage
1889 * past return buffer's end.
1890 */
1891 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001892 tprintf(", %lu", tcp->u_arg[offset + 2]);
1893 }
1894 return 0;
1895}
1896
1897int
1898sys_readlink(struct tcb *tcp)
1899{
1900 return decode_readlink(tcp, 0);
1901}
1902
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001903int
1904sys_readlinkat(struct tcb *tcp)
1905{
1906 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001907 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001908 return decode_readlink(tcp, 1);
1909}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001910
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001911int
1912sys_renameat(struct tcb *tcp)
1913{
1914 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001915 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001916 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001917 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001918 print_dirfd(tcp, tcp->u_arg[2]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001919 printpath(tcp, tcp->u_arg[3]);
1920 }
1921 return 0;
1922}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001923
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001924int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001925sys_chown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001926{
1927 if (entering(tcp)) {
1928 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001929 printuid(", ", tcp->u_arg[1]);
1930 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001931 }
1932 return 0;
1933}
1934
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001935int
1936sys_fchownat(struct tcb *tcp)
1937{
1938 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001939 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001940 printpath(tcp, tcp->u_arg[1]);
1941 printuid(", ", tcp->u_arg[2]);
1942 printuid(", ", tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001943 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00001944 printflags(at_flags, tcp->u_arg[4], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001945 }
1946 return 0;
1947}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001948
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001949int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001950sys_fchown(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001951{
1952 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001953 printfd(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001954 printuid(", ", tcp->u_arg[1]);
1955 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001956 }
1957 return 0;
1958}
1959
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001960static int
1961decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001962{
1963 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001964 printpath(tcp, tcp->u_arg[offset]);
1965 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001966 }
1967 return 0;
1968}
1969
1970int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001971sys_chmod(struct tcb *tcp)
1972{
1973 return decode_chmod(tcp, 0);
1974}
1975
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001976int
1977sys_fchmodat(struct tcb *tcp)
1978{
1979 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03001980 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001981 return decode_chmod(tcp, 1);
1982}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001983
1984int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001985sys_fchmod(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001986{
1987 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001988 printfd(tcp, tcp->u_arg[0]);
1989 tprintf(", %#lo", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001990 }
1991 return 0;
1992}
1993
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001994#ifdef ALPHA
1995int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001996sys_osf_utimes(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001997{
Denys Vlasenko1d632462009-04-14 12:51:00 +00001998 if (entering(tcp)) {
1999 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002000 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002001 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2002 }
2003 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002004}
2005#endif
2006
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002007static int
Roland McGrath6afc5652007-07-24 01:57:11 +00002008decode_utimes(struct tcb *tcp, int offset, int special)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002009{
2010 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002011 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002012 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +00002013 if (tcp->u_arg[offset + 1] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002014 tprints("NULL");
Roland McGrath6afc5652007-07-24 01:57:11 +00002015 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002016 tprints("{");
Roland McGrath6afc5652007-07-24 01:57:11 +00002017 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2018 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002019 tprints(", ");
Roland McGrathe6d0f712007-08-07 01:22:49 +00002020 printtv_bitness(tcp, tcp->u_arg[offset + 1]
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002021 + sizeof(struct timeval),
Roland McGrath6afc5652007-07-24 01:57:11 +00002022 BITNESS_CURRENT, special);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002023 tprints("}");
Roland McGrath6afc5652007-07-24 01:57:11 +00002024 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002025 }
2026 return 0;
2027}
2028
2029int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002030sys_utimes(struct tcb *tcp)
2031{
Roland McGrath6afc5652007-07-24 01:57:11 +00002032 return decode_utimes(tcp, 0, 0);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002033}
2034
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002035int
2036sys_futimesat(struct tcb *tcp)
2037{
2038 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002039 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002040 return decode_utimes(tcp, 1, 0);
2041}
2042
2043int
2044sys_utimensat(struct tcb *tcp)
2045{
2046 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002047 print_dirfd(tcp, tcp->u_arg[0]);
Roland McGrath6afc5652007-07-24 01:57:11 +00002048 decode_utimes(tcp, 1, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002049 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +00002050 printflags(at_flags, tcp->u_arg[3], "AT_???");
Roland McGrath6afc5652007-07-24 01:57:11 +00002051 }
2052 return 0;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002053}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002054
2055int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002056sys_utime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002057{
Roland McGrath7e9817c2007-07-05 20:31:58 +00002058 union {
2059 long utl[2];
2060 int uti[2];
2061 } u;
Denys Vlasenko9fd4f962012-03-19 09:36:42 +01002062 unsigned wordsize = current_wordsize;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002063
2064 if (entering(tcp)) {
2065 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002066 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002067 if (!tcp->u_arg[1])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002068 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002069 else if (!verbose(tcp))
2070 tprintf("%#lx", tcp->u_arg[1]);
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002071 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002072 tprints("[?, ?]");
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002073 else if (wordsize == sizeof u.utl[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002074 tprintf("[%s,", sprinttime(u.utl[0]));
2075 tprintf(" %s]", sprinttime(u.utl[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002076 }
Denys Vlasenko1945ccc2012-02-27 14:37:48 +01002077 else if (wordsize == sizeof u.uti[0]) {
Roland McGrath7e9817c2007-07-05 20:31:58 +00002078 tprintf("[%s,", sprinttime(u.uti[0]));
2079 tprintf(" %s]", sprinttime(u.uti[1]));
2080 }
2081 else
2082 abort();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002083 }
2084 return 0;
2085}
2086
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002087static int
2088decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002089{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002090 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002091
2092 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002093 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002094 tprintf(", %s", sprintmode(mode));
2095 switch (mode & S_IFMT) {
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002096 case S_IFCHR:
2097 case S_IFBLK:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002098#ifdef LINUXSPARC
2099 if (current_personality == 1)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002100 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002101 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2102 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002103 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002104#endif
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01002105 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002106 (unsigned long) major(tcp->u_arg[offset + 2]),
2107 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002108 break;
2109 default:
2110 break;
2111 }
2112 }
2113 return 0;
2114}
2115
2116int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002117sys_mknod(struct tcb *tcp)
2118{
2119 return decode_mknod(tcp, 0);
2120}
2121
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002122int
2123sys_mknodat(struct tcb *tcp)
2124{
2125 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +03002126 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002127 return decode_mknod(tcp, 1);
2128}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002129
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002130static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002131printdir(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002132{
2133 struct dirent d;
2134
2135 if (!verbose(tcp)) {
2136 tprintf("%#lx", addr);
2137 return;
2138 }
2139 if (umove(tcp, addr, &d) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002140 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002141 return;
2142 }
2143 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002144 tprints("d_name=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002145 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002146 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002147}
2148
2149int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002150sys_readdir(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002151{
2152 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002153 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002154 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002155 } else {
2156 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2157 tprintf("%#lx", tcp->u_arg[1]);
2158 else
2159 printdir(tcp, tcp->u_arg[1]);
2160 /* Not much point in printing this out, it is always 1. */
2161 if (tcp->u_arg[2] != 1)
2162 tprintf(", %lu", tcp->u_arg[2]);
2163 }
2164 return 0;
2165}
2166
Roland McGratha4d48532005-06-08 20:45:28 +00002167static const struct xlat direnttypes[] = {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002168 { DT_UNKNOWN, "DT_UNKNOWN" },
2169 { DT_FIFO, "DT_FIFO" },
2170 { DT_CHR, "DT_CHR" },
2171 { DT_DIR, "DT_DIR" },
2172 { DT_BLK, "DT_BLK" },
2173 { DT_REG, "DT_REG" },
2174 { DT_LNK, "DT_LNK" },
2175 { DT_SOCK, "DT_SOCK" },
2176 { DT_WHT, "DT_WHT" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002177 { 0, NULL },
2178};
2179
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002180int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002181sys_getdents(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002182{
2183 int i, len, dents = 0;
2184 char *buf;
2185
2186 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002187 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002188 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002189 return 0;
2190 }
2191 if (syserror(tcp) || !verbose(tcp)) {
2192 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2193 return 0;
2194 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002195 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002196 /* Beware of insanely large or negative values in tcp->u_rval */
2197 if (tcp->u_rval > 1024*1024)
2198 len = 1024*1024;
2199 if (tcp->u_rval < 0)
2200 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002201 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002202 if (len && !buf)
2203 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002204 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002205 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002206 free(buf);
2207 return 0;
2208 }
2209 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002210 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002211 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002212 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002213 if (!abbrev(tcp)) {
2214 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2215 i ? " " : "", d->d_ino, d->d_off);
2216 tprintf("d_reclen=%u, d_name=\"%s\"}",
2217 d->d_reclen, d->d_name);
2218 }
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002219 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002220 tprints("/* d_reclen == 0, problem here */");
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002221 break;
2222 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002223 i += d->d_reclen;
2224 dents++;
2225 }
2226 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002227 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002228 else
2229 tprintf("/* %u entries */", dents);
2230 tprintf(", %lu", tcp->u_arg[2]);
2231 free(buf);
2232 return 0;
2233}
2234
John Hughesbdf48f52001-03-06 15:08:09 +00002235#if _LFS64_LARGEFILE
2236int
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002237sys_getdents64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +00002238{
2239 int i, len, dents = 0;
2240 char *buf;
2241
2242 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002243 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002244 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002245 return 0;
2246 }
2247 if (syserror(tcp) || !verbose(tcp)) {
2248 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2249 return 0;
2250 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002251
John Hughesbdf48f52001-03-06 15:08:09 +00002252 len = tcp->u_rval;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002253 /* Beware of insanely large or negative tcp->u_rval */
2254 if (tcp->u_rval > 1024*1024)
2255 len = 1024*1024;
2256 if (tcp->u_rval < 0)
2257 len = 0;
Mike Frysinger229738c2009-10-07 20:41:56 -04002258 buf = len ? malloc(len) : NULL;
Denys Vlasenko1d46ba52011-08-31 14:00:02 +02002259 if (len && !buf)
2260 die_out_of_memory();
Denys Vlasenko79a79ea2011-09-01 16:35:44 +02002261
John Hughesbdf48f52001-03-06 15:08:09 +00002262 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002263 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002264 free(buf);
2265 return 0;
2266 }
2267 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002268 tprints("{");
John Hughesbdf48f52001-03-06 15:08:09 +00002269 for (i = 0; i < len;) {
2270 struct dirent64 *d = (struct dirent64 *) &buf[i];
John Hughesbdf48f52001-03-06 15:08:09 +00002271 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002272 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002273 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002274 d->d_ino,
2275 d->d_off);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002276 tprints("d_type=");
Roland McGrath40542842004-01-13 09:47:49 +00002277 printxval(direnttypes, d->d_type, "DT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002278 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +00002279 tprintf("d_reclen=%u, d_name=\"%s\"}",
2280 d->d_reclen, d->d_name);
2281 }
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002282 if (!d->d_reclen) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002283 tprints("/* d_reclen == 0, problem here */");
Dmitry V. Levin153fbd62008-04-19 23:49:58 +00002284 break;
2285 }
John Hughesbdf48f52001-03-06 15:08:09 +00002286 i += d->d_reclen;
2287 dents++;
2288 }
2289 if (!abbrev(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002290 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +00002291 else
2292 tprintf("/* %u entries */", dents);
2293 tprintf(", %lu", tcp->u_arg[2]);
2294 free(buf);
2295 return 0;
2296}
2297#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002298
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002299int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002300sys_getcwd(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002301{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002302 if (exiting(tcp)) {
2303 if (syserror(tcp))
2304 tprintf("%#lx", tcp->u_arg[0]);
2305 else
2306 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2307 tprintf(", %lu", tcp->u_arg[1]);
2308 }
2309 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002310}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002311
2312#ifdef HAVE_SYS_ASYNCH_H
2313
2314int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002315sys_aioread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002316{
2317 struct aio_result_t res;
2318
2319 if (entering(tcp)) {
2320 tprintf("%lu, ", tcp->u_arg[0]);
2321 } else {
2322 if (syserror(tcp))
2323 tprintf("%#lx", tcp->u_arg[1]);
2324 else
2325 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2326 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2327 printxval(whence, tcp->u_arg[4], "L_???");
2328 if (syserror(tcp) || tcp->u_arg[5] == 0
2329 || umove(tcp, tcp->u_arg[5], &res) < 0)
2330 tprintf(", %#lx", tcp->u_arg[5]);
2331 else
2332 tprintf(", {aio_return %d aio_errno %d}",
2333 res.aio_return, res.aio_errno);
2334 }
2335 return 0;
2336}
2337
2338int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002339sys_aiowrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002340{
2341 struct aio_result_t res;
2342
2343 if (entering(tcp)) {
2344 tprintf("%lu, ", tcp->u_arg[0]);
2345 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2346 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2347 printxval(whence, tcp->u_arg[4], "L_???");
2348 }
2349 else {
2350 if (tcp->u_arg[5] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002351 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002352 else if (syserror(tcp)
2353 || umove(tcp, tcp->u_arg[5], &res) < 0)
2354 tprintf(", %#lx", tcp->u_arg[5]);
2355 else
2356 tprintf(", {aio_return %d aio_errno %d}",
2357 res.aio_return, res.aio_errno);
2358 }
2359 return 0;
2360}
2361
2362int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002363sys_aiowait(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002364{
2365 if (entering(tcp))
2366 printtv(tcp, tcp->u_arg[0]);
2367 return 0;
2368}
2369
2370int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002371sys_aiocancel(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002372{
2373 struct aio_result_t res;
2374
2375 if (exiting(tcp)) {
2376 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002377 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002378 else if (syserror(tcp)
2379 || umove(tcp, tcp->u_arg[0], &res) < 0)
2380 tprintf("%#lx", tcp->u_arg[0]);
2381 else
2382 tprintf("{aio_return %d aio_errno %d}",
2383 res.aio_return, res.aio_errno);
2384 }
2385 return 0;
2386}
2387
2388#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002389
Roland McGratha4d48532005-06-08 20:45:28 +00002390static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002391#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002392 { XATTR_CREATE, "XATTR_CREATE" },
2393 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002394#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002395 { 0, NULL }
2396};
2397
Roland McGrath3292e222004-08-31 06:30:48 +00002398static void
Denys Vlasenko1d632462009-04-14 12:51:00 +00002399print_xattr_val(struct tcb *tcp, int failed,
2400 unsigned long arg,
2401 unsigned long insize,
2402 unsigned long size)
Roland McGrath3292e222004-08-31 06:30:48 +00002403{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002404 if (!failed) {
2405 unsigned long capacity = 4 * size + 1;
2406 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2407 if (buf == NULL || /* probably a bogus size argument */
2408 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2409 failed = 1;
Roland McGrath883567c2005-02-02 03:38:32 +00002410 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002411 else {
2412 unsigned char *out = buf;
2413 unsigned char *in = &buf[3 * size];
2414 size_t i;
2415 for (i = 0; i < size; ++i) {
2416 if (isprint(in[i]))
2417 *out++ = in[i];
2418 else {
2419#define tohex(n) "0123456789abcdef"[n]
2420 *out++ = '\\';
2421 *out++ = 'x';
2422 *out++ = tohex(in[i] / 16);
2423 *out++ = tohex(in[i] % 16);
2424 }
2425 }
2426 /* Don't print terminating NUL if there is one. */
2427 if (i > 0 && in[i - 1] == '\0')
2428 out -= 4;
2429 *out = '\0';
2430 tprintf(", \"%s\", %ld", buf, insize);
2431 }
2432 free(buf);
Roland McGrath883567c2005-02-02 03:38:32 +00002433 }
Denys Vlasenko1d632462009-04-14 12:51:00 +00002434 if (failed)
2435 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002436}
2437
Roland McGrath186c5ac2002-12-15 23:58:23 +00002438int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002439sys_setxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002440{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002441 if (entering(tcp)) {
2442 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002443 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002444 printstr(tcp, tcp->u_arg[1], -1);
2445 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002446 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002447 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2448 }
2449 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002450}
2451
2452int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002453sys_fsetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002454{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002455 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002456 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002457 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002458 printstr(tcp, tcp->u_arg[1], -1);
2459 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002460 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002461 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2462 }
2463 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002464}
2465
2466int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002467sys_getxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002468{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002469 if (entering(tcp)) {
2470 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002471 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002472 printstr(tcp, tcp->u_arg[1], -1);
2473 } else {
2474 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2475 tcp->u_rval);
2476 }
2477 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002478}
2479
2480int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002481sys_fgetxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002482{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002483 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002484 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002485 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002486 printstr(tcp, tcp->u_arg[1], -1);
2487 } else {
2488 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2489 tcp->u_rval);
2490 }
2491 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002492}
2493
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002494static void
2495print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2496{
2497 if (syserror(tcp)) {
2498 tprintf("%#lx", addr);
2499 } else {
2500 if (!addr) {
2501 tprints("NULL");
2502 } else {
2503 unsigned long len =
2504 (size < tcp->u_rval) ? size : tcp->u_rval;
2505 printstr(tcp, addr, len);
2506 }
2507 }
2508 tprintf(", %lu", size);
2509}
2510
Roland McGrath186c5ac2002-12-15 23:58:23 +00002511int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002512sys_listxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002513{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002514 if (entering(tcp)) {
2515 printpath(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002516 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002517 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002518 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002519 }
2520 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002521}
2522
2523int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002524sys_flistxattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002525{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002526 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002527 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002528 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002529 } else {
Dmitry V. Levin33d24762012-03-14 16:34:32 +00002530 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +00002531 }
2532 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002533}
2534
2535int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002536sys_removexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002537{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002538 if (entering(tcp)) {
2539 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002540 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002541 printstr(tcp, tcp->u_arg[1], -1);
2542 }
2543 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002544}
2545
2546int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002547sys_fremovexattr(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +00002548{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002549 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002550 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002551 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002552 printstr(tcp, tcp->u_arg[1], -1);
2553 }
2554 return 0;
Roland McGrath186c5ac2002-12-15 23:58:23 +00002555}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002556
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002557static const struct xlat advise[] = {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01002558 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2559 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2560 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2561 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2562 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2563 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2564 { 0, NULL }
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002565};
2566
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002567int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002568sys_fadvise64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002569{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002570 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002571 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002572 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002573 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002574 argn = printllval(tcp, "%lld", 1);
2575 tprintf(", %ld, ", tcp->u_arg[argn++]);
2576 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Denys Vlasenko1d632462009-04-14 12:51:00 +00002577 }
2578 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002579}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002580
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002581int
Denys Vlasenko1d632462009-04-14 12:51:00 +00002582sys_fadvise64_64(struct tcb *tcp)
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002583{
Denys Vlasenko1d632462009-04-14 12:51:00 +00002584 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002585 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002586 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002587 tprints(", ");
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002588#if defined ARM || defined POWERPC
2589 argn = printllval(tcp, "%lld, ", 2);
2590#else
2591 argn = printllval(tcp, "%lld, ", 1);
2592#endif
2593 argn = printllval(tcp, "%lld, ", argn);
2594#if defined ARM || defined POWERPC
Kirill A. Shutemov896db212009-09-19 03:21:33 +03002595 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002596#else
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002597 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002598#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +00002599 }
2600 return 0;
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002601}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002602
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002603static const struct xlat inotify_modes[] = {
Dmitry V. Levind475c062011-03-03 01:02:41 +00002604 { 0x00000001, "IN_ACCESS" },
2605 { 0x00000002, "IN_MODIFY" },
2606 { 0x00000004, "IN_ATTRIB" },
2607 { 0x00000008, "IN_CLOSE_WRITE"},
2608 { 0x00000010, "IN_CLOSE_NOWRITE"},
2609 { 0x00000020, "IN_OPEN" },
2610 { 0x00000040, "IN_MOVED_FROM" },
2611 { 0x00000080, "IN_MOVED_TO" },
2612 { 0x00000100, "IN_CREATE" },
2613 { 0x00000200, "IN_DELETE" },
2614 { 0x00000400, "IN_DELETE_SELF"},
2615 { 0x00000800, "IN_MOVE_SELF" },
2616 { 0x00002000, "IN_UNMOUNT" },
2617 { 0x00004000, "IN_Q_OVERFLOW" },
2618 { 0x00008000, "IN_IGNORED" },
2619 { 0x01000000, "IN_ONLYDIR" },
2620 { 0x02000000, "IN_DONT_FOLLOW"},
2621 { 0x20000000, "IN_MASK_ADD" },
2622 { 0x40000000, "IN_ISDIR" },
2623 { 0x80000000, "IN_ONESHOT" },
2624 { 0, NULL }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002625};
2626
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002627static const struct xlat inotify_init_flags[] = {
2628 { 0x00000800, "IN_NONBLOCK" },
Denys Vlasenkob63256e2011-06-07 12:13:24 +02002629 { 0x00080000, "IN_CLOEXEC" },
2630 { 0, NULL }
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002631};
2632
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002633int
2634sys_inotify_add_watch(struct tcb *tcp)
2635{
2636 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002637 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002638 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002639 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002640 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002641 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2642 }
2643 return 0;
2644}
2645
2646int
2647sys_inotify_rm_watch(struct tcb *tcp)
2648{
2649 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03002650 printfd(tcp, tcp->u_arg[0]);
Dmitry V. Levinab1a70c2012-03-11 15:33:34 +00002651 tprintf(", %d", (int) tcp->u_arg[1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002652 }
2653 return 0;
2654}
Roland McGrath96a96612008-05-20 04:56:18 +00002655
2656int
Mark Wielaardbab89402010-03-21 14:41:26 +01002657sys_inotify_init1(struct tcb *tcp)
2658{
2659 if (entering(tcp))
Sebastian Pipping1e1405a2011-03-03 00:50:55 +01002660 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
Mark Wielaardbab89402010-03-21 14:41:26 +01002661 return 0;
2662}
2663
2664int
Roland McGrath96a96612008-05-20 04:56:18 +00002665sys_fallocate(struct tcb *tcp)
2666{
2667 if (entering(tcp)) {
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002668 int argn;
Dmitry V. Levin31382132011-03-04 05:08:02 +03002669 printfd(tcp, tcp->u_arg[0]); /* fd */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02002670 tprints(", ");
Roland McGrath96a96612008-05-20 04:56:18 +00002671 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
Andreas Schwabb5600fc2009-11-04 17:08:34 +01002672 argn = printllval(tcp, "%llu, ", 2); /* offset */
2673 printllval(tcp, "%llu", argn); /* len */
Roland McGrath96a96612008-05-20 04:56:18 +00002674 }
2675 return 0;
2676}
Dmitry V. Levin88293652012-03-09 21:02:19 +00002677
Dmitry V. Levinad0c01e2012-03-15 00:52:22 +00002678#ifndef SWAP_FLAG_PREFER
2679# define SWAP_FLAG_PREFER 0x8000
2680#endif
2681#ifndef SWAP_FLAG_DISCARD
2682# define SWAP_FLAG_DISCARD 0x10000
2683#endif
Dmitry V. Levin88293652012-03-09 21:02:19 +00002684static const struct xlat swap_flags[] = {
2685 { SWAP_FLAG_PREFER, "SWAP_FLAG_PREFER" },
2686 { SWAP_FLAG_DISCARD, "SWAP_FLAG_DISCARD" },
2687 { 0, NULL }
2688};
2689
2690int
2691sys_swapon(struct tcb *tcp)
2692{
2693 if (entering(tcp)) {
2694 int flags = tcp->u_arg[1];
2695 printpath(tcp, tcp->u_arg[0]);
2696 tprints(", ");
2697 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2698 "SWAP_FLAG_???");
2699 if (flags & SWAP_FLAG_PREFER)
2700 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);
2701 }
2702 return 0;
2703}