blob: dbd16618c9070ea57ab29869108daf84d057c7fb [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
Michal Ludvig53b320f2002-09-23 13:30:09 +00002#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
4 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
5 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00006 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00007 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * $Id$
32 */
33
34#include "defs.h"
35
36#include <dirent.h>
Michal Ludvig53b320f2002-09-23 13:30:09 +000037#ifdef LINUX
Wichert Akkerman9524bb91999-05-25 23:11:18 +000038#define dirent kernel_dirent
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +000039#define dirent64 kernel_dirent64
Wichert Akkerman9524bb91999-05-25 23:11:18 +000040#include <linux/types.h>
41#include <linux/dirent.h>
42#undef dirent
Michal Ludvig10a88d02002-10-07 14:31:00 +000043#undef dirent64
Wichert Akkerman9524bb91999-05-25 23:11:18 +000044#else
45#define kernel_dirent dirent
46#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000047
Michal Ludvig53b320f2002-09-23 13:30:09 +000048#ifdef LINUX
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000049# ifdef LINUXSPARC
50struct stat {
51 unsigned short st_dev;
52 unsigned int st_ino;
53 unsigned short st_mode;
54 short st_nlink;
55 unsigned short st_uid;
56 unsigned short st_gid;
57 unsigned short st_rdev;
58 unsigned int st_size;
59 int st_atime;
60 unsigned int __unused1;
61 int st_mtime;
62 unsigned int __unused2;
63 int st_ctime;
64 unsigned int __unused3;
65 int st_blksize;
66 int st_blocks;
67 unsigned int __unused4[2];
68};
Roland McGrath6d1a65c2004-07-12 07:44:08 +000069#if defined(SPARC64)
70struct stat_sparc64 {
71 unsigned int st_dev;
72 unsigned long st_ino;
73 unsigned int st_mode;
74 unsigned int st_nlink;
75 unsigned int st_uid;
76 unsigned int st_gid;
77 unsigned int st_rdev;
78 long st_size;
79 long st_atime;
80 long st_mtime;
81 long st_ctime;
82 long st_blksize;
83 long st_blocks;
84 unsigned long __unused4[2];
85};
86#endif /* SPARC64 */
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000087# define stat kernel_stat
88# include <asm/stat.h>
89# undef stat
90# else
Wichert Akkerman5b4d1281999-07-09 00:32:54 +000091# undef dev_t
92# undef ino_t
93# undef mode_t
94# undef nlink_t
95# undef uid_t
96# undef gid_t
97# undef off_t
98# undef loff_t
99
Wichert Akkermana6013701999-07-08 14:00:58 +0000100# define dev_t __kernel_dev_t
101# define ino_t __kernel_ino_t
102# define mode_t __kernel_mode_t
103# define nlink_t __kernel_nlink_t
104# define uid_t __kernel_uid_t
105# define gid_t __kernel_gid_t
106# define off_t __kernel_off_t
107# define loff_t __kernel_loff_t
108
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000109# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +0000110
111# undef dev_t
112# undef ino_t
113# undef mode_t
114# undef nlink_t
115# undef uid_t
116# undef gid_t
117# undef off_t
118# undef loff_t
Wichert Akkerman5b4d1281999-07-09 00:32:54 +0000119
120# define dev_t dev_t
121# define ino_t ino_t
122# define mode_t mode_t
123# define nlink_t nlink_t
124# define uid_t uid_t
125# define gid_t gid_t
126# define off_t off_t
127# define loff_t loff_t
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000128# endif
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000129# ifdef HPPA /* asm-parisc/stat.h defines stat64 */
130# undef stat64
131# endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000132# define stat libc_stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000133# define stat64 libc_stat64
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000134# include <sys/stat.h>
135# undef stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000136# undef stat64
Roland McGrathca16a402003-01-09 06:53:22 +0000137 /* These might be macros. */
138# undef st_atime
139# undef st_mtime
140# undef st_ctime
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000141# ifdef HPPA
142# define stat64 hpux_stat64
143# endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000144#else
145# include <sys/stat.h>
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000146#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000147
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148#include <fcntl.h>
149
150#ifdef SVR4
151# include <sys/cred.h>
152#endif /* SVR4 */
153
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000154#ifdef HAVE_SYS_VFS_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000155#include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000156#endif
157
Roland McGrath186c5ac2002-12-15 23:58:23 +0000158#ifdef HAVE_LINUX_XATTR_H
159#include <linux/xattr.h>
160#elif defined linux
161#define XATTR_CREATE 1
162#define XATTR_REPLACE 2
163#endif
164
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000165#ifdef FREEBSD
166#include <sys/param.h>
167#include <sys/mount.h>
168#include <sys/stat.h>
John Hughes70623be2001-03-08 13:59:00 +0000169#endif
170
Dmitry V. Levin1f336e52006-10-14 20:20:46 +0000171#if _LFS64_LARGEFILE && (defined(LINUX) || defined(SVR4))
172# ifdef HAVE_INTTYPES_H
173# include <inttypes.h>
174# else
175# define PRId64 "lld"
176# define PRIu64 "llu"
177# endif
178#endif
179
John Hughes70623be2001-03-08 13:59:00 +0000180#if HAVE_LONG_LONG_OFF_T
181/*
182 * Ugly hacks for systems that have typedef long long off_t
183 */
John Hughesb8c9f772001-03-07 16:53:07 +0000184
185#define stat64 stat
186#define HAVE_STAT64 1 /* Ugly hack */
John Hughes70623be2001-03-08 13:59:00 +0000187
188#define sys_stat64 sys_stat
189#define sys_fstat64 sys_fstat
190#define sys_lstat64 sys_lstat
191#define sys_lseek64 sys_lseek
192#define sys_truncate64 sys_truncate
193#define sys_ftruncate64 sys_ftruncate
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000194#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000195
196#ifdef MAJOR_IN_SYSMACROS
197#include <sys/sysmacros.h>
198#endif
199
200#ifdef MAJOR_IN_MKDEV
201#include <sys/mkdev.h>
202#endif
203
204#ifdef HAVE_SYS_ASYNCH_H
205#include <sys/asynch.h>
206#endif
207
208#ifdef SUNOS4
209#include <ustat.h>
210#endif
211
212/*
213 * This is a really dirty trick but it should always work. Traditional
214 * Unix says r/w/rw are 0/1/2, so we make them true flags 1/2/3 by
215 * adding 1. Just remember to add 1 to any arg decoded with openmodes.
216 */
Roland McGrathd9f816f2004-09-04 03:39:20 +0000217const struct xlat openmodes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000218 { O_RDWR+1, "O_RDWR" },
219 { O_RDONLY+1, "O_RDONLY" },
220 { O_WRONLY+1, "O_WRONLY" },
221 { O_NONBLOCK, "O_NONBLOCK" },
222 { O_APPEND, "O_APPEND" },
223 { O_CREAT, "O_CREAT" },
224 { O_TRUNC, "O_TRUNC" },
225 { O_EXCL, "O_EXCL" },
226 { O_NOCTTY, "O_NOCTTY" },
227#ifdef O_SYNC
228 { O_SYNC, "O_SYNC" },
229#endif
230#ifdef O_ASYNC
231 { O_ASYNC, "O_ASYNC" },
232#endif
233#ifdef O_DSYNC
234 { O_DSYNC, "O_DSYNC" },
235#endif
236#ifdef O_RSYNC
237 { O_RSYNC, "O_RSYNC" },
238#endif
239#ifdef O_NDELAY
240 { O_NDELAY, "O_NDELAY" },
241#endif
242#ifdef O_PRIV
243 { O_PRIV, "O_PRIV" },
244#endif
245#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000246 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000247#endif
248#ifdef O_LARGEFILE
Roland McGrathfee836e2005-02-02 22:11:32 +0000249# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
250# undef O_LARGEFILE
251# ifdef SPARC64
252# define O_LARGEFILE 0x40000
253# elif defined X86_64 || defined S390X
254# define O_LARGEFILE 0100000
255# endif
256# endif
Roland McGrath663a8a02005-02-04 09:49:56 +0000257# ifdef O_LARGEFILE
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000258 { O_LARGEFILE, "O_LARGEFILE" },
Roland McGrath663a8a02005-02-04 09:49:56 +0000259# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000260#endif
261#ifdef O_DIRECTORY
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000262 { O_DIRECTORY, "O_DIRECTORY" },
263#endif
264#ifdef O_NOFOLLOW
265 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000266#endif
Roland McGrath1025c3e2005-05-09 07:40:35 +0000267#ifdef O_NOATIME
268 { O_NOATIME, "O_NOATIME" },
269#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000270
271#ifdef FNDELAY
272 { FNDELAY, "FNDELAY" },
273#endif
274#ifdef FAPPEND
275 { FAPPEND, "FAPPEND" },
276#endif
277#ifdef FMARK
278 { FMARK, "FMARK" },
279#endif
280#ifdef FDEFER
281 { FDEFER, "FDEFER" },
282#endif
283#ifdef FASYNC
284 { FASYNC, "FASYNC" },
285#endif
286#ifdef FSHLOCK
287 { FSHLOCK, "FSHLOCK" },
288#endif
289#ifdef FEXLOCK
290 { FEXLOCK, "FEXLOCK" },
291#endif
292#ifdef FCREAT
293 { FCREAT, "FCREAT" },
294#endif
295#ifdef FTRUNC
296 { FTRUNC, "FTRUNC" },
297#endif
298#ifdef FEXCL
299 { FEXCL, "FEXCL" },
300#endif
301#ifdef FNBIO
302 { FNBIO, "FNBIO" },
303#endif
304#ifdef FSYNC
305 { FSYNC, "FSYNC" },
306#endif
307#ifdef FNOCTTY
308 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000309#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000310#ifdef O_SHLOCK
311 { O_SHLOCK, "O_SHLOCK" },
312#endif
313#ifdef O_EXLOCK
314 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000315#endif
316 { 0, NULL },
317};
318
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000319#ifdef LINUX
320
321#ifndef AT_FDCWD
322# define AT_FDCWD -100
323#endif
324
325static void
326print_dirfd(long fd)
327{
328 if (fd == AT_FDCWD)
329 tprintf("AT_FDCWD, ");
330 else
331 tprintf("%ld, ", fd);
332}
333#endif
334
335static int
336decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000337{
338 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000339 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000340 tprintf(", ");
341 /* flags */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000342 printflags(openmodes, tcp->u_arg[offset + 1] + 1, "O_???");
343 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000344 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000345 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000346 }
347 }
348 return 0;
349}
350
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000351int
352sys_open(struct tcb *tcp)
353{
354 return decode_open(tcp, 0);
355}
356
357#ifdef LINUX
358int
359sys_openat(struct tcb *tcp)
360{
361 if (entering(tcp))
362 print_dirfd(tcp->u_arg[0]);
363 return decode_open(tcp, 1);
364}
365#endif
366
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000367#ifdef LINUXSPARC
Roland McGratha4d48532005-06-08 20:45:28 +0000368static const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000369 { 0, "O_RDWR" },
370 { 1, "O_RDONLY" },
371 { 2, "O_WRONLY" },
372 { 0x80, "O_NONBLOCK" },
373 { 8, "O_APPEND" },
374 { 0x100, "O_CREAT" },
375 { 0x200, "O_TRUNC" },
376 { 0x400, "O_EXCL" },
377 { 0x800, "O_NOCTTY" },
378 { 0x10, "O_SYNC" },
379 { 0x40, "O_DSYNC" },
380 { 0x8000, "O_RSYNC" },
381 { 4, "O_NDELAY" },
382 { 0x1000, "O_PRIV" },
383 { 0, NULL },
384};
385
386int
387solaris_open(tcp)
388struct tcb *tcp;
389{
390 if (entering(tcp)) {
391 printpath(tcp, tcp->u_arg[0]);
392 tprintf(", ");
393 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000394 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000395 if (tcp->u_arg[1] & 0x100) {
396 /* mode */
397 tprintf(", %#lo", tcp->u_arg[2]);
398 }
399 }
400 return 0;
401}
402
403#endif
404
405int
406sys_creat(tcp)
407struct tcb *tcp;
408{
409 if (entering(tcp)) {
410 printpath(tcp, tcp->u_arg[0]);
411 tprintf(", %#lo", tcp->u_arg[1]);
412 }
413 return 0;
414}
415
Roland McGrathd9f816f2004-09-04 03:39:20 +0000416static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000417 { F_OK, "F_OK", },
418 { R_OK, "R_OK" },
419 { W_OK, "W_OK" },
420 { X_OK, "X_OK" },
421#ifdef EFF_ONLY_OK
422 { EFF_ONLY_OK, "EFF_ONLY_OK" },
423#endif
424#ifdef EX_OK
425 { EX_OK, "EX_OK" },
426#endif
427 { 0, NULL },
428};
429
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000430static int
431decode_access(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000432{
433 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000434 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000435 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000436 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000437 }
438 return 0;
439}
440
441int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000442sys_access(struct tcb *tcp)
443{
444 return decode_access(tcp, 0);
445}
446
447#ifdef LINUX
448int
449sys_faccessat(struct tcb *tcp)
450{
451 if (entering(tcp))
452 print_dirfd(tcp->u_arg[0]);
453 return decode_access(tcp, 1);
454}
455#endif
456
457int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000458sys_umask(tcp)
459struct tcb *tcp;
460{
461 if (entering(tcp)) {
462 tprintf("%#lo", tcp->u_arg[0]);
463 }
464 return RVAL_OCTAL;
465}
466
Roland McGrathd9f816f2004-09-04 03:39:20 +0000467static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000468 { SEEK_SET, "SEEK_SET" },
469 { SEEK_CUR, "SEEK_CUR" },
470 { SEEK_END, "SEEK_END" },
471 { 0, NULL },
472};
473
John Hughes70623be2001-03-08 13:59:00 +0000474#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000475int
476sys_lseek(tcp)
477struct tcb *tcp;
478{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000479 off_t offset;
480 int _whence;
481
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000482 if (entering(tcp)) {
483 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000484 offset = tcp->u_arg[1];
485 _whence = tcp->u_arg[2];
486 if (_whence == SEEK_SET)
487 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000488 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000489 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000490 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000491 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000492 return RVAL_UDECIMAL;
493}
John Hughes5a826b82001-03-07 13:21:24 +0000494#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000495
Michal Ludvig53b320f2002-09-23 13:30:09 +0000496#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000497int
498sys_llseek (tcp)
499struct tcb *tcp;
500{
501 if (entering(tcp)) {
Roland McGrath8c304bc2004-10-19 22:59:55 +0000502 /*
503 * This one call takes explicitly two 32-bit arguments hi, lo,
504 * rather than one 64-bit argument for which LONG_LONG works
505 * appropriate for the native byte order.
506 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000507 if (tcp->u_arg[4] == SEEK_SET)
508 tprintf("%ld, %llu, ", tcp->u_arg[0],
Roland McGrath8c304bc2004-10-19 22:59:55 +0000509 (((long long int) tcp->u_arg[1]) << 32
510 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000511 else
512 tprintf("%ld, %lld, ", tcp->u_arg[0],
Roland McGrath8c304bc2004-10-19 22:59:55 +0000513 (((long long int) tcp->u_arg[1]) << 32
514 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000515 }
516 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000517 long long int off;
518 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000519 tprintf("%#lx, ", tcp->u_arg[3]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000520 else
521 tprintf("[%llu], ", off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522 printxval(whence, tcp->u_arg[4], "SEEK_???");
523 }
524 return 0;
525}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000526
527int
528sys_readahead (tcp)
529struct tcb *tcp;
530{
531 if (entering(tcp)) {
532 tprintf("%ld, %lld, %ld", tcp->u_arg[0],
533# if defined IA64 || defined X86_64 || defined ALPHA
534 (long long int) tcp->u_arg[1], tcp->u_arg[2]
535# else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +0000536 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]
Roland McGrath186c5ac2002-12-15 23:58:23 +0000537# endif
538 );
539 }
540 return 0;
541}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000542#endif
543
John Hughes70623be2001-03-08 13:59:00 +0000544#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000545int
546sys_lseek64 (tcp)
547struct tcb *tcp;
548{
549 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000550 long long offset;
551 ALIGN64 (tcp, 1); /* FreeBSD aligns off_t args */
John Hughes0c79e012001-03-08 14:40:06 +0000552 offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +0000553 if (tcp->u_arg[3] == SEEK_SET)
554 tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
555 else
556 tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
557 printxval(whence, tcp->u_arg[3], "SEEK_???");
558 }
559 return RVAL_LUDECIMAL;
560}
561#endif
562
John Hughes70623be2001-03-08 13:59:00 +0000563#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564int
565sys_truncate(tcp)
566struct tcb *tcp;
567{
568 if (entering(tcp)) {
569 printpath(tcp, tcp->u_arg[0]);
570 tprintf(", %lu", tcp->u_arg[1]);
571 }
572 return 0;
573}
John Hughes5a826b82001-03-07 13:21:24 +0000574#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000575
John Hughes70623be2001-03-08 13:59:00 +0000576#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000577int
578sys_truncate64(tcp)
579struct tcb *tcp;
580{
581 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000582 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000583 printpath(tcp, tcp->u_arg[0]);
John Hughes0c79e012001-03-08 14:40:06 +0000584 tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000585 }
586 return 0;
587}
588#endif
589
John Hughes70623be2001-03-08 13:59:00 +0000590#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000591int
592sys_ftruncate(tcp)
593struct tcb *tcp;
594{
595 if (entering(tcp)) {
596 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
597 }
598 return 0;
599}
John Hughes5a826b82001-03-07 13:21:24 +0000600#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000601
John Hughes70623be2001-03-08 13:59:00 +0000602#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000603int
604sys_ftruncate64(tcp)
605struct tcb *tcp;
606{
607 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000608 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000609 tprintf("%ld, %llu", tcp->u_arg[0],
John Hughes0c79e012001-03-08 14:40:06 +0000610 LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000611 }
612 return 0;
613}
614#endif
615
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000616/* several stats */
617
Roland McGrathd9f816f2004-09-04 03:39:20 +0000618static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000619 { S_IFREG, "S_IFREG" },
620 { S_IFSOCK, "S_IFSOCK" },
621 { S_IFIFO, "S_IFIFO" },
622 { S_IFLNK, "S_IFLNK" },
623 { S_IFDIR, "S_IFDIR" },
624 { S_IFBLK, "S_IFBLK" },
625 { S_IFCHR, "S_IFCHR" },
626 { 0, NULL },
627};
628
Roland McGrathf9c49b22004-10-06 22:11:54 +0000629static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000630sprintmode(mode)
631int mode;
632{
633 static char buf[64];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000634 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000635
636 if ((mode & S_IFMT) == 0)
637 s = "";
638 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
639 sprintf(buf, "%#o", mode);
640 return buf;
641 }
642 sprintf(buf, "%s%s%s%s", s,
643 (mode & S_ISUID) ? "|S_ISUID" : "",
644 (mode & S_ISGID) ? "|S_ISGID" : "",
645 (mode & S_ISVTX) ? "|S_ISVTX" : "");
646 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
647 if (mode)
648 sprintf(buf + strlen(buf), "|%#o", mode);
649 s = (*buf == '|') ? buf + 1 : buf;
650 return *s ? s : "0";
651}
652
653static char *
654sprinttime(t)
655time_t t;
656{
657 struct tm *tmp;
658 static char buf[32];
659
660 if (t == 0) {
661 sprintf(buf, "0");
662 return buf;
663 }
664 tmp = localtime(&t);
665 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
Wichert Akkerman3ed6dc22000-01-11 14:41:09 +0000666 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000667 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
668 return buf;
669}
670
671#ifdef LINUXSPARC
672typedef struct {
673 int tv_sec;
674 int tv_nsec;
675} timestruct_t;
676
677struct solstat {
678 unsigned st_dev;
679 int st_pad1[3]; /* network id */
680 unsigned st_ino;
681 unsigned st_mode;
682 unsigned st_nlink;
683 unsigned st_uid;
684 unsigned st_gid;
685 unsigned st_rdev;
686 int st_pad2[2];
687 int st_size;
688 int st_pad3; /* st_size, off_t expansion */
689 timestruct_t st_atime;
690 timestruct_t st_mtime;
691 timestruct_t st_ctime;
692 int st_blksize;
693 int st_blocks;
694 char st_fstype[16];
695 int st_pad4[8]; /* expansion area */
696};
697
698static void
699printstatsol(tcp, addr)
700struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000701long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000702{
703 struct solstat statbuf;
704
705 if (!addr) {
706 tprintf("NULL");
707 return;
708 }
709 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000710 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000711 return;
712 }
713 if (umove(tcp, addr, &statbuf) < 0) {
714 tprintf("{...}");
715 return;
716 }
717 if (!abbrev(tcp)) {
718 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
719 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
720 (unsigned long) (statbuf.st_dev & 0x3ffff),
721 (unsigned long) statbuf.st_ino,
722 sprintmode(statbuf.st_mode));
723 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
724 (unsigned long) statbuf.st_nlink,
725 (unsigned long) statbuf.st_uid,
726 (unsigned long) statbuf.st_gid);
727 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
728 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
729 }
730 else
731 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
732 switch (statbuf.st_mode & S_IFMT) {
733 case S_IFCHR: case S_IFBLK:
734 tprintf("st_rdev=makedev(%lu, %lu), ",
735 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
736 (unsigned long) (statbuf.st_rdev & 0x3ffff));
737 break;
738 default:
739 tprintf("st_size=%u, ", statbuf.st_size);
740 break;
741 }
742 if (!abbrev(tcp)) {
743 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
744 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
745 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
746 }
747 else
748 tprintf("...}");
749}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000750
751#if defined (SPARC64)
752static void
753printstat_sparc64(tcp, addr)
754struct tcb *tcp;
755long addr;
756{
757 struct stat_sparc64 statbuf;
758
759 if (!addr) {
760 tprintf("NULL");
761 return;
762 }
763 if (syserror(tcp) || !verbose(tcp)) {
764 tprintf("%#lx", addr);
765 return;
766 }
767 if (umove(tcp, addr, &statbuf) < 0) {
768 tprintf("{...}");
769 return;
770 }
771
772 if (!abbrev(tcp)) {
773 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
774 (unsigned long) major(statbuf.st_dev),
775 (unsigned long) minor(statbuf.st_dev),
776 (unsigned long) statbuf.st_ino,
777 sprintmode(statbuf.st_mode));
778 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
779 (unsigned long) statbuf.st_nlink,
780 (unsigned long) statbuf.st_uid,
781 (unsigned long) statbuf.st_gid);
782 tprintf("st_blksize=%lu, ",
783 (unsigned long) statbuf.st_blksize);
784 tprintf("st_blocks=%lu, ",
785 (unsigned long) statbuf.st_blocks);
786 }
787 else
788 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
789 switch (statbuf.st_mode & S_IFMT) {
790 case S_IFCHR: case S_IFBLK:
791 tprintf("st_rdev=makedev(%lu, %lu), ",
792 (unsigned long) major(statbuf.st_rdev),
793 (unsigned long) minor(statbuf.st_rdev));
794 break;
795 default:
796 tprintf("st_size=%lu, ", statbuf.st_size);
797 break;
798 }
799 if (!abbrev(tcp)) {
800 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
801 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
802 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
803 tprintf("}");
804 }
805 else
806 tprintf("...}");
807}
808#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000809#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000810
Roland McGratha4d48532005-06-08 20:45:28 +0000811static const struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000812#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000813 { UF_NODUMP, "UF_NODUMP" },
814 { UF_IMMUTABLE, "UF_IMMUTABLE" },
815 { UF_APPEND, "UF_APPEND" },
816 { UF_OPAQUE, "UF_OPAQUE" },
817 { UF_NOUNLINK, "UF_NOUNLINK" },
818 { SF_ARCHIVED, "SF_ARCHIVED" },
819 { SF_IMMUTABLE, "SF_IMMUTABLE" },
820 { SF_APPEND, "SF_APPEND" },
821 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000822#elif UNIXWARE >= 2
823#ifdef _S_ISMLD
824 { _S_ISMLD, "_S_ISMLD" },
825#endif
826#ifdef _S_ISMOUNTED
827 { _S_ISMOUNTED, "_S_ISMOUNTED" },
828#endif
829#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000830 { 0, NULL },
831};
832
John Hughesc0fc3fd2001-03-08 16:10:40 +0000833#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000834int
835sys_chflags(tcp)
836struct tcb *tcp;
837{
838 if (entering(tcp)) {
839 printpath(tcp, tcp->u_arg[0]);
840 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000841 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000842 }
843 return 0;
844}
845
846int
847sys_fchflags(tcp)
848struct tcb *tcp;
849{
850 if (entering(tcp)) {
851 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000852 printflags(fileflags, tcp->u_arg[1], "UF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000853 }
854 return 0;
855}
856#endif
857
John Hughes70623be2001-03-08 13:59:00 +0000858#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000859static void
860realprintstat(tcp, statbuf)
861struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000862struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000863{
864 if (!abbrev(tcp)) {
865 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
866 (unsigned long) major(statbuf->st_dev),
867 (unsigned long) minor(statbuf->st_dev),
868 (unsigned long) statbuf->st_ino,
869 sprintmode(statbuf->st_mode));
870 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
871 (unsigned long) statbuf->st_nlink,
872 (unsigned long) statbuf->st_uid,
873 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000874#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000875 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000876#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
877#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000878 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000879#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000880 }
881 else
882 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
883 switch (statbuf->st_mode & S_IFMT) {
884 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000885#ifdef HAVE_STRUCT_STAT_ST_RDEV
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000886 tprintf("st_rdev=makedev(%lu, %lu), ",
887 (unsigned long) major(statbuf->st_rdev),
888 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000889#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000890 tprintf("st_size=makedev(%lu, %lu), ",
891 (unsigned long) major(statbuf->st_size),
892 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000893#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000894 break;
895 default:
896 tprintf("st_size=%lu, ", statbuf->st_size);
897 break;
898 }
899 if (!abbrev(tcp)) {
900 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
901 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000902 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000903#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000904 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000905 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000906#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000907#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000908 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
909#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000910#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000911 tprintf(", st_level=%ld", statbuf->st_level);
912#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000913#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000914 tprintf(", st_fstype=%.*s",
915 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
916#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000917#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000918 tprintf(", st_gen=%u", statbuf->st_gen);
919#endif
920 tprintf("}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000921 }
922 else
923 tprintf("...}");
924}
925
Nate Sammons771a6ff1999-04-05 22:39:31 +0000926
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000927static void
928printstat(tcp, addr)
929struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000930long 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
934#ifdef LINUXSPARC
935 if (current_personality == 1) {
936 printstatsol(tcp, addr);
937 return;
938 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000939#ifdef SPARC64
940 else if (current_personality == 2) {
941 printstat_sparc64(tcp, addr);
942 return;
943 }
944#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000945#endif /* LINUXSPARC */
946
947 if (!addr) {
948 tprintf("NULL");
949 return;
950 }
951 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000952 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000953 return;
954 }
955 if (umove(tcp, addr, &statbuf) < 0) {
956 tprintf("{...}");
957 return;
958 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000959
960 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000961}
John Hughes70623be2001-03-08 13:59:00 +0000962#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000963
Wichert Akkermanc7926982000-04-10 22:22:31 +0000964#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000965static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000966printstat64(tcp, addr)
967struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000968long addr;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000969{
970 struct stat64 statbuf;
971
972#ifdef LINUXSPARC
973 if (current_personality == 1) {
974 printstatsol(tcp, addr);
975 return;
976 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000977#ifdef SPARC64
978 else if (current_personality == 2) {
979 printstat_sparc64(tcp, addr);
980 return;
981 }
982#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000983#endif /* LINUXSPARC */
984
985 if (!addr) {
986 tprintf("NULL");
987 return;
988 }
989 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000990 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000991 return;
992 }
993 if (umove(tcp, addr, &statbuf) < 0) {
994 tprintf("{...}");
995 return;
996 }
997
998 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +0000999#ifdef HAVE_LONG_LONG
1000 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1001#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001002 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +00001003#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001004 (unsigned long) major(statbuf.st_dev),
1005 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +00001006#ifdef HAVE_LONG_LONG
1007 (unsigned long long) statbuf.st_ino,
1008#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001009 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +00001010#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001011 sprintmode(statbuf.st_mode));
1012 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1013 (unsigned long) statbuf.st_nlink,
1014 (unsigned long) statbuf.st_uid,
1015 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001016#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001017 tprintf("st_blksize=%lu, ",
1018 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001019#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1020#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001021 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +00001022#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001023 }
1024 else
1025 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1026 switch (statbuf.st_mode & S_IFMT) {
1027 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +00001028#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001029 tprintf("st_rdev=makedev(%lu, %lu), ",
1030 (unsigned long) major(statbuf.st_rdev),
1031 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001032#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001033 tprintf("st_size=makedev(%lu, %lu), ",
1034 (unsigned long) major(statbuf.st_size),
1035 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001036#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001037 break;
1038 default:
1039 tprintf("st_size=%llu, ", statbuf.st_size);
1040 break;
1041 }
1042 if (!abbrev(tcp)) {
1043 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1044 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +00001045 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001046#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +00001047 tprintf(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001048 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001049#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001050#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001051 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1052#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001053#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001054 tprintf(", st_level=%ld", statbuf.st_level);
1055#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001056#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001057 tprintf(", st_fstype=%.*s",
1058 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1059#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001060#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001061 tprintf(", st_gen=%u", statbuf.st_gen);
1062#endif
1063 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001064 }
1065 else
1066 tprintf("...}");
1067}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001068#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001069
Roland McGrath79db8af2003-06-27 21:20:09 +00001070#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001071static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001072convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001073const struct __old_kernel_stat *oldbuf;
1074struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001075{
1076 newbuf->st_dev=oldbuf->st_dev;
1077 newbuf->st_ino=oldbuf->st_ino;
1078 newbuf->st_mode=oldbuf->st_mode;
1079 newbuf->st_nlink=oldbuf->st_nlink;
1080 newbuf->st_uid=oldbuf->st_uid;
1081 newbuf->st_gid=oldbuf->st_gid;
1082 newbuf->st_rdev=oldbuf->st_rdev;
1083 newbuf->st_size=oldbuf->st_size;
1084 newbuf->st_atime=oldbuf->st_atime;
1085 newbuf->st_mtime=oldbuf->st_mtime;
1086 newbuf->st_ctime=oldbuf->st_ctime;
1087 newbuf->st_blksize=0; /* not supported in old_stat */
1088 newbuf->st_blocks=0; /* not supported in old_stat */
1089}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001090
1091
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001092static void
1093printoldstat(tcp, addr)
1094struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001095long addr;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001096{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001097 struct __old_kernel_stat statbuf;
1098 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001099
1100#ifdef LINUXSPARC
1101 if (current_personality == 1) {
1102 printstatsol(tcp, addr);
1103 return;
1104 }
1105#endif /* LINUXSPARC */
1106
1107 if (!addr) {
1108 tprintf("NULL");
1109 return;
1110 }
1111 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001112 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001113 return;
1114 }
1115 if (umove(tcp, addr, &statbuf) < 0) {
1116 tprintf("{...}");
1117 return;
1118 }
1119
1120 convertoldstat(&statbuf, &newstatbuf);
1121 realprintstat(tcp, &newstatbuf);
1122}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001123#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001124
John Hughes70623be2001-03-08 13:59:00 +00001125#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001126int
1127sys_stat(tcp)
1128struct tcb *tcp;
1129{
1130 if (entering(tcp)) {
1131 printpath(tcp, tcp->u_arg[0]);
1132 tprintf(", ");
1133 } else {
1134 printstat(tcp, tcp->u_arg[1]);
1135 }
1136 return 0;
1137}
John Hughesb8c9f772001-03-07 16:53:07 +00001138#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001139
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001140int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001141sys_stat64(tcp)
1142struct tcb *tcp;
1143{
1144#ifdef HAVE_STAT64
1145 if (entering(tcp)) {
1146 printpath(tcp, tcp->u_arg[0]);
1147 tprintf(", ");
1148 } else {
1149 printstat64(tcp, tcp->u_arg[1]);
1150 }
1151 return 0;
1152#else
1153 return printargs(tcp);
1154#endif
1155}
1156
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001157#ifdef LINUX
1158static const struct xlat fstatatflags[] = {
1159#ifndef AT_SYMLINK_NOFOLLOW
1160# define AT_SYMLINK_NOFOLLOW 0x100
1161#endif
1162 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1163 { 0, NULL },
1164};
1165
1166int
1167sys_newfstatat(struct tcb *tcp)
1168{
1169 if (entering(tcp)) {
1170 print_dirfd(tcp->u_arg[0]);
1171 printpath(tcp, tcp->u_arg[1]);
1172 tprintf(", ");
1173 } else {
1174#ifdef HAVE_STAT64
1175 printstat64(tcp, tcp->u_arg[2]);
1176#else
1177 printstat(tcp, tcp->u_arg[2]);
1178#endif
1179 tprintf(", ");
1180 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1181 }
1182 return 0;
1183}
1184#endif
1185
Roland McGrath79db8af2003-06-27 21:20:09 +00001186#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001187int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001188sys_oldstat(tcp)
1189struct tcb *tcp;
1190{
1191 if (entering(tcp)) {
1192 printpath(tcp, tcp->u_arg[0]);
1193 tprintf(", ");
1194 } else {
1195 printoldstat(tcp, tcp->u_arg[1]);
1196 }
1197 return 0;
1198}
Roland McGrath79db8af2003-06-27 21:20:09 +00001199#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001200
John Hughes70623be2001-03-08 13:59:00 +00001201#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001202int
1203sys_fstat(tcp)
1204struct tcb *tcp;
1205{
1206 if (entering(tcp))
1207 tprintf("%ld, ", tcp->u_arg[0]);
1208 else {
1209 printstat(tcp, tcp->u_arg[1]);
1210 }
1211 return 0;
1212}
John Hughesb8c9f772001-03-07 16:53:07 +00001213#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001214
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001215int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001216sys_fstat64(tcp)
1217struct tcb *tcp;
1218{
1219#ifdef HAVE_STAT64
1220 if (entering(tcp))
1221 tprintf("%ld, ", tcp->u_arg[0]);
1222 else {
1223 printstat64(tcp, tcp->u_arg[1]);
1224 }
1225 return 0;
1226#else
1227 return printargs(tcp);
1228#endif
1229}
1230
Roland McGrath79db8af2003-06-27 21:20:09 +00001231#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001232int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001233sys_oldfstat(tcp)
1234struct tcb *tcp;
1235{
1236 if (entering(tcp))
1237 tprintf("%ld, ", tcp->u_arg[0]);
1238 else {
1239 printoldstat(tcp, tcp->u_arg[1]);
1240 }
1241 return 0;
1242}
Roland McGrath79db8af2003-06-27 21:20:09 +00001243#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001244
John Hughes70623be2001-03-08 13:59:00 +00001245#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001246int
1247sys_lstat(tcp)
1248struct tcb *tcp;
1249{
1250 if (entering(tcp)) {
1251 printpath(tcp, tcp->u_arg[0]);
1252 tprintf(", ");
1253 } else {
1254 printstat(tcp, tcp->u_arg[1]);
1255 }
1256 return 0;
1257}
John Hughesb8c9f772001-03-07 16:53:07 +00001258#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001259
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001260int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001261sys_lstat64(tcp)
1262struct tcb *tcp;
1263{
1264#ifdef HAVE_STAT64
1265 if (entering(tcp)) {
1266 printpath(tcp, tcp->u_arg[0]);
1267 tprintf(", ");
1268 } else {
1269 printstat64(tcp, tcp->u_arg[1]);
1270 }
1271 return 0;
1272#else
1273 return printargs(tcp);
1274#endif
1275}
1276
Roland McGrath79db8af2003-06-27 21:20:09 +00001277#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001278int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001279sys_oldlstat(tcp)
1280struct tcb *tcp;
1281{
1282 if (entering(tcp)) {
1283 printpath(tcp, tcp->u_arg[0]);
1284 tprintf(", ");
1285 } else {
1286 printoldstat(tcp, tcp->u_arg[1]);
1287 }
1288 return 0;
1289}
Roland McGrath79db8af2003-06-27 21:20:09 +00001290#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001291
1292
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001293#if defined(SVR4) || defined(LINUXSPARC)
1294
1295int
1296sys_xstat(tcp)
1297struct tcb *tcp;
1298{
1299 if (entering(tcp)) {
1300 tprintf("%ld, ", tcp->u_arg[0]);
1301 printpath(tcp, tcp->u_arg[1]);
1302 tprintf(", ");
1303 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001304#ifdef _STAT64_VER
1305 if (tcp->u_arg[0] == _STAT64_VER)
1306 printstat64 (tcp, tcp->u_arg[2]);
1307 else
1308#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001309 printstat(tcp, tcp->u_arg[2]);
1310 }
1311 return 0;
1312}
1313
1314int
1315sys_fxstat(tcp)
1316struct tcb *tcp;
1317{
1318 if (entering(tcp))
1319 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1320 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001321#ifdef _STAT64_VER
1322 if (tcp->u_arg[0] == _STAT64_VER)
1323 printstat64 (tcp, tcp->u_arg[2]);
1324 else
1325#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001326 printstat(tcp, tcp->u_arg[2]);
1327 }
1328 return 0;
1329}
1330
1331int
1332sys_lxstat(tcp)
1333struct tcb *tcp;
1334{
1335 if (entering(tcp)) {
1336 tprintf("%ld, ", tcp->u_arg[0]);
1337 printpath(tcp, tcp->u_arg[1]);
1338 tprintf(", ");
1339 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001340#ifdef _STAT64_VER
1341 if (tcp->u_arg[0] == _STAT64_VER)
1342 printstat64 (tcp, tcp->u_arg[2]);
1343 else
1344#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001345 printstat(tcp, tcp->u_arg[2]);
1346 }
1347 return 0;
1348}
1349
1350int
1351sys_xmknod(tcp)
1352struct tcb *tcp;
1353{
1354 int mode = tcp->u_arg[2];
1355
1356 if (entering(tcp)) {
1357 tprintf("%ld, ", tcp->u_arg[0]);
1358 printpath(tcp, tcp->u_arg[1]);
1359 tprintf(", %s", sprintmode(mode));
1360 switch (mode & S_IFMT) {
1361 case S_IFCHR: case S_IFBLK:
1362#ifdef LINUXSPARC
1363 tprintf(", makedev(%lu, %lu)",
1364 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1365 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001366#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001367 tprintf(", makedev(%lu, %lu)",
1368 (unsigned long) major(tcp->u_arg[3]),
1369 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001370#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001371 break;
1372 default:
1373 break;
1374 }
1375 }
1376 return 0;
1377}
1378
Wichert Akkerman8829a551999-06-11 13:18:40 +00001379#ifdef HAVE_SYS_ACL_H
1380
1381#include <sys/acl.h>
1382
Roland McGratha4d48532005-06-08 20:45:28 +00001383static const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001384#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001385 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001386#endif
1387#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001388 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001389#endif
1390#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001391 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001392#endif
1393#ifdef ACL_GET
1394 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001395#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001396#ifdef ACL_SET
1397 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001398#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001399#ifdef ACL_CNT
1400 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001401#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001402 { 0, NULL },
1403};
1404
1405int
1406sys_acl(tcp)
1407struct tcb *tcp;
1408{
1409 if (entering(tcp)) {
1410 printpath(tcp, tcp->u_arg[0]);
1411 tprintf(", ");
1412 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1413 tprintf(", %ld", tcp->u_arg[2]);
1414 /*
1415 * FIXME - dump out the list of aclent_t's pointed to
1416 * by "tcp->u_arg[3]" if it's not NULL.
1417 */
1418 if (tcp->u_arg[3])
1419 tprintf(", %#lx", tcp->u_arg[3]);
1420 else
1421 tprintf(", NULL");
1422 }
1423 return 0;
1424}
1425
1426
1427int
1428sys_facl(tcp)
1429struct tcb *tcp;
1430{
1431 if (entering(tcp)) {
1432 tprintf("%ld, ", tcp->u_arg[0]);
1433 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1434 tprintf(", %ld", tcp->u_arg[2]);
1435 /*
1436 * FIXME - dump out the list of aclent_t's pointed to
1437 * by "tcp->u_arg[3]" if it's not NULL.
1438 */
1439 if (tcp->u_arg[3])
1440 tprintf(", %#lx", tcp->u_arg[3]);
1441 else
1442 tprintf(", NULL");
1443 }
1444 return 0;
1445}
1446
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001447
Roland McGratha4d48532005-06-08 20:45:28 +00001448static const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001449#ifdef IPC_SHM
1450 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001451#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001452#ifdef IPC_SEM
1453 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001454#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001455#ifdef IPC_MSG
1456 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001457#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001458 { 0, NULL },
1459};
1460
1461
1462int
1463sys_aclipc(tcp)
1464struct tcb *tcp;
1465{
1466 if (entering(tcp)) {
1467 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1468 tprintf(", %#lx, ", tcp->u_arg[1]);
1469 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1470 tprintf(", %ld", tcp->u_arg[3]);
1471 /*
1472 * FIXME - dump out the list of aclent_t's pointed to
1473 * by "tcp->u_arg[4]" if it's not NULL.
1474 */
1475 if (tcp->u_arg[4])
1476 tprintf(", %#lx", tcp->u_arg[4]);
1477 else
1478 tprintf(", NULL");
1479 }
1480 return 0;
1481}
1482
1483
1484
Wichert Akkerman8829a551999-06-11 13:18:40 +00001485#endif /* HAVE_SYS_ACL_H */
1486
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001487#endif /* SVR4 || LINUXSPARC */
1488
Michal Ludvig53b320f2002-09-23 13:30:09 +00001489#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001490
Roland McGrathd9f816f2004-09-04 03:39:20 +00001491static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001492 { 0x73757245, "CODA_SUPER_MAGIC" },
1493 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1494 { 0x1373, "DEVFS_SUPER_MAGIC" },
1495 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1496 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001497 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1498 { 0xef53, "EXT2_SUPER_MAGIC" },
1499 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001500 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001501 { 0x9660, "ISOFS_SUPER_MAGIC" },
1502 { 0x137f, "MINIX_SUPER_MAGIC" },
1503 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001504 { 0x2468, "MINIX2_SUPER_MAGIC" },
1505 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001506 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001507 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001508 { 0x6969, "NFS_SUPER_MAGIC" },
1509 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001510 { 0x002f, "QNX4_SUPER_MAGIC" },
1511 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1512 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1513 { 0x517b, "SMB_SUPER_MAGIC" },
1514 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1515 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1516 { 0x00011954, "UFS_MAGIC" },
1517 { 0x54190100, "UFS_CIGAM" },
1518 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001519 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001520 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001521 { 0, NULL },
1522};
1523
Michal Ludvig53b320f2002-09-23 13:30:09 +00001524#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001525
1526#ifndef SVR4
1527
Roland McGrathf9c49b22004-10-06 22:11:54 +00001528static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001529sprintfstype(magic)
1530int magic;
1531{
1532 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001533#ifdef LINUX
Roland McGrathf9c49b22004-10-06 22:11:54 +00001534 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001535
1536 s = xlookup(fsmagic, magic);
1537 if (s) {
1538 sprintf(buf, "\"%s\"", s);
1539 return buf;
1540 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001541#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001542 sprintf(buf, "%#x", magic);
1543 return buf;
1544}
1545
1546static void
1547printstatfs(tcp, addr)
1548struct tcb *tcp;
1549long addr;
1550{
1551 struct statfs statbuf;
1552
1553 if (syserror(tcp) || !verbose(tcp)) {
1554 tprintf("%#lx", addr);
1555 return;
1556 }
1557 if (umove(tcp, addr, &statbuf) < 0) {
1558 tprintf("{...}");
1559 return;
1560 }
1561#ifdef ALPHA
1562
1563 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1564 sprintfstype(statbuf.f_type),
1565 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001566 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1567 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1568 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1569 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001570#else /* !ALPHA */
1571 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1572 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001573 (unsigned long)statbuf.f_bsize,
1574 (unsigned long)statbuf.f_blocks,
1575 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001576 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1577 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001578 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001579 (unsigned long)statbuf.f_ffree,
1580 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001581#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001582 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001583#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001584#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001585#ifdef _STATFS_F_FRSIZE
1586 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1587#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001588 tprintf("}");
1589}
1590
1591int
1592sys_statfs(tcp)
1593struct tcb *tcp;
1594{
1595 if (entering(tcp)) {
1596 printpath(tcp, tcp->u_arg[0]);
1597 tprintf(", ");
1598 } else {
1599 printstatfs(tcp, tcp->u_arg[1]);
1600 }
1601 return 0;
1602}
1603
1604int
1605sys_fstatfs(tcp)
1606struct tcb *tcp;
1607{
1608 if (entering(tcp)) {
1609 tprintf("%lu, ", tcp->u_arg[0]);
1610 } else {
1611 printstatfs(tcp, tcp->u_arg[1]);
1612 }
1613 return 0;
1614}
1615
Roland McGrathab147c52003-07-17 09:03:02 +00001616#ifdef LINUX
1617static void
1618printstatfs64(tcp, addr)
1619struct tcb *tcp;
1620long addr;
1621{
1622 struct statfs64 statbuf;
1623
1624 if (syserror(tcp) || !verbose(tcp)) {
1625 tprintf("%#lx", addr);
1626 return;
1627 }
1628 if (umove(tcp, addr, &statbuf) < 0) {
1629 tprintf("{...}");
1630 return;
1631 }
Roland McGrath08738432005-06-03 02:40:39 +00001632 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
Roland McGrathab147c52003-07-17 09:03:02 +00001633 sprintfstype(statbuf.f_type),
Roland McGrath08738432005-06-03 02:40:39 +00001634 (unsigned long long)statbuf.f_bsize,
1635 (unsigned long long)statbuf.f_blocks,
1636 (unsigned long long)statbuf.f_bfree);
1637 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1638 (unsigned long long)statbuf.f_bavail,
1639 (unsigned long long)statbuf.f_files,
1640 (unsigned long long)statbuf.f_ffree,
Roland McGrathab147c52003-07-17 09:03:02 +00001641 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1642 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Roland McGrathab147c52003-07-17 09:03:02 +00001643#ifdef _STATFS_F_FRSIZE
Roland McGrath08738432005-06-03 02:40:39 +00001644 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
Roland McGrathab147c52003-07-17 09:03:02 +00001645#endif
1646 tprintf("}");
1647}
1648
1649int
1650sys_statfs64(tcp)
1651struct tcb *tcp;
1652{
1653 if (entering(tcp)) {
1654 printpath(tcp, tcp->u_arg[0]);
1655 tprintf(", %lu, ", tcp->u_arg[1]);
1656 } else {
1657 if (tcp->u_arg[1] == sizeof (struct statfs64))
1658 printstatfs64(tcp, tcp->u_arg[2]);
1659 else
1660 tprintf("{???}");
1661 }
1662 return 0;
1663}
1664
1665int
1666sys_fstatfs64(tcp)
1667struct tcb *tcp;
1668{
1669 if (entering(tcp)) {
1670 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1671 } else {
1672 if (tcp->u_arg[1] == sizeof (struct statfs64))
1673 printstatfs64(tcp, tcp->u_arg[2]);
1674 else
1675 tprintf("{???}");
1676 }
1677 return 0;
1678}
1679#endif
1680
Michal Ludvig53b320f2002-09-23 13:30:09 +00001681#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001682
1683int
1684osf_statfs(tcp)
1685struct tcb *tcp;
1686{
1687 if (entering(tcp)) {
1688 printpath(tcp, tcp->u_arg[0]);
1689 tprintf(", ");
1690 } else {
1691 printstatfs(tcp, tcp->u_arg[1]);
1692 tprintf(", %lu", tcp->u_arg[2]);
1693 }
1694 return 0;
1695}
1696
1697int
1698osf_fstatfs(tcp)
1699struct tcb *tcp;
1700{
1701 if (entering(tcp)) {
1702 tprintf("%lu, ", tcp->u_arg[0]);
1703 } else {
1704 printstatfs(tcp, tcp->u_arg[1]);
1705 tprintf(", %lu", tcp->u_arg[2]);
1706 }
1707 return 0;
1708}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001709#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001710
1711#endif /* !SVR4 */
1712
1713#ifdef SUNOS4
1714
1715int
1716sys_ustat(tcp)
1717struct tcb *tcp;
1718{
1719 struct ustat statbuf;
1720
1721 if (entering(tcp)) {
1722 tprintf("makedev(%lu, %lu), ",
1723 (long) major(tcp->u_arg[0]),
1724 (long) minor(tcp->u_arg[0]));
1725 }
1726 else {
1727 if (syserror(tcp) || !verbose(tcp))
1728 tprintf("%#lx", tcp->u_arg[1]);
1729 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1730 tprintf("{...}");
1731 else {
1732 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1733 statbuf.f_tfree, statbuf.f_tinode);
1734 tprintf("f_fname=\"%.*s\", ",
1735 (int) sizeof(statbuf.f_fname),
1736 statbuf.f_fname);
1737 tprintf("f_fpack=\"%.*s\"}",
1738 (int) sizeof(statbuf.f_fpack),
1739 statbuf.f_fpack);
1740 }
1741 }
1742 return 0;
1743}
1744
1745#endif /* SUNOS4 */
1746
Wichert Akkermanc7926982000-04-10 22:22:31 +00001747int
1748sys_pivotroot(tcp)
1749struct tcb *tcp;
1750{
1751 if (entering(tcp)) {
1752 printpath(tcp, tcp->u_arg[0]);
1753 tprintf(", ");
1754 printpath(tcp, tcp->u_arg[1]);
1755 }
1756 return 0;
1757}
1758
1759
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001760/* directory */
1761int
1762sys_chdir(tcp)
1763struct tcb *tcp;
1764{
1765 if (entering(tcp)) {
1766 printpath(tcp, tcp->u_arg[0]);
1767 }
1768 return 0;
1769}
1770
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001771static int
1772decode_mkdir(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001773{
1774 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001775 printpath(tcp, tcp->u_arg[offset]);
1776 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001777 }
1778 return 0;
1779}
1780
1781int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001782sys_mkdir(struct tcb *tcp)
1783{
1784 return decode_mkdir(tcp, 0);
1785}
1786
1787#ifdef LINUX
1788int
1789sys_mkdirat(struct tcb *tcp)
1790{
1791 if (entering(tcp))
1792 print_dirfd(tcp->u_arg[0]);
1793 return decode_mkdir(tcp, 1);
1794}
1795#endif
1796
1797int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001798sys_rmdir(tcp)
1799struct tcb *tcp;
1800{
1801 if (entering(tcp)) {
1802 printpath(tcp, tcp->u_arg[0]);
1803 }
1804 return 0;
1805}
1806
1807int
1808sys_fchdir(tcp)
1809struct tcb *tcp;
1810{
1811 if (entering(tcp)) {
1812 tprintf("%ld", tcp->u_arg[0]);
1813 }
1814 return 0;
1815}
1816
1817int
1818sys_chroot(tcp)
1819struct tcb *tcp;
1820{
1821 if (entering(tcp)) {
1822 printpath(tcp, tcp->u_arg[0]);
1823 }
1824 return 0;
1825}
1826
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001827#if defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001828int
1829sys_fchroot(tcp)
1830struct tcb *tcp;
1831{
1832 if (entering(tcp)) {
1833 tprintf("%ld", tcp->u_arg[0]);
1834 }
1835 return 0;
1836}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00001837#endif /* SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001838
1839int
1840sys_link(tcp)
1841struct tcb *tcp;
1842{
1843 if (entering(tcp)) {
1844 printpath(tcp, tcp->u_arg[0]);
1845 tprintf(", ");
1846 printpath(tcp, tcp->u_arg[1]);
1847 }
1848 return 0;
1849}
1850
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001851#ifdef LINUX
1852int
1853sys_linkat(struct tcb *tcp)
1854{
1855 if (entering(tcp)) {
1856 print_dirfd(tcp->u_arg[0]);
1857 printpath(tcp, tcp->u_arg[1]);
1858 tprintf(", ");
1859 print_dirfd(tcp->u_arg[2]);
1860 printpath(tcp, tcp->u_arg[3]);
1861 tprintf(", %ld", tcp->u_arg[4]);
1862 }
1863 return 0;
1864}
1865#endif
1866
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001867int
1868sys_unlink(tcp)
1869struct tcb *tcp;
1870{
1871 if (entering(tcp)) {
1872 printpath(tcp, tcp->u_arg[0]);
1873 }
1874 return 0;
1875}
1876
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001877#ifdef LINUX
1878static const struct xlat unlinkatflags[] = {
1879#ifndef AT_REMOVEDIR
1880# define AT_REMOVEDIR 0x200
1881#endif
1882 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1883 { 0, NULL },
1884};
1885
1886int
1887sys_unlinkat(struct tcb *tcp)
1888{
1889 if (entering(tcp)) {
1890 print_dirfd(tcp->u_arg[0]);
1891 printpath(tcp, tcp->u_arg[1]);
1892 tprintf(", ");
1893 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1894 }
1895 return 0;
1896}
1897#endif
1898
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001899int
1900sys_symlink(tcp)
1901struct tcb *tcp;
1902{
1903 if (entering(tcp)) {
1904 printpath(tcp, tcp->u_arg[0]);
1905 tprintf(", ");
1906 printpath(tcp, tcp->u_arg[1]);
1907 }
1908 return 0;
1909}
1910
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001911#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001912int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001913sys_symlinkat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001914{
1915 if (entering(tcp)) {
1916 printpath(tcp, tcp->u_arg[0]);
1917 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001918 print_dirfd(tcp->u_arg[1]);
1919 printpath(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001920 }
1921 return 0;
1922}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001923#endif
1924
1925static int
1926decode_readlink(struct tcb *tcp, int offset)
1927{
1928 if (entering(tcp)) {
1929 printpath(tcp, tcp->u_arg[offset]);
1930 tprintf(", ");
1931 } else {
1932 if (syserror(tcp))
1933 tprintf("%#lx", tcp->u_arg[offset + 1]);
1934 else
1935 printpathn(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1936 tprintf(", %lu", tcp->u_arg[offset + 2]);
1937 }
1938 return 0;
1939}
1940
1941int
1942sys_readlink(struct tcb *tcp)
1943{
1944 return decode_readlink(tcp, 0);
1945}
1946
1947#ifdef LINUX
1948int
1949sys_readlinkat(struct tcb *tcp)
1950{
1951 if (entering(tcp))
1952 print_dirfd(tcp->u_arg[0]);
1953 return decode_readlink(tcp, 1);
1954}
1955#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001956
1957int
1958sys_rename(tcp)
1959struct tcb *tcp;
1960{
1961 if (entering(tcp)) {
1962 printpath(tcp, tcp->u_arg[0]);
1963 tprintf(", ");
1964 printpath(tcp, tcp->u_arg[1]);
1965 }
1966 return 0;
1967}
1968
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001969#ifdef LINUX
1970int
1971sys_renameat(struct tcb *tcp)
1972{
1973 if (entering(tcp)) {
1974 print_dirfd(tcp->u_arg[0]);
1975 printpath(tcp, tcp->u_arg[1]);
1976 tprintf(", ");
1977 print_dirfd(tcp->u_arg[2]);
1978 printpath(tcp, tcp->u_arg[3]);
1979 }
1980 return 0;
1981}
1982#endif
1983
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001984int
1985sys_chown(tcp)
1986struct tcb *tcp;
1987{
1988 if (entering(tcp)) {
1989 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001990 printuid(", ", tcp->u_arg[1]);
1991 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001992 }
1993 return 0;
1994}
1995
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001996#ifdef LINUX
1997int
1998sys_fchownat(struct tcb *tcp)
1999{
2000 if (entering(tcp)) {
2001 print_dirfd(tcp->u_arg[0]);
2002 printpath(tcp, tcp->u_arg[1]);
2003 printuid(", ", tcp->u_arg[2]);
2004 printuid(", ", tcp->u_arg[3]);
2005 tprintf(", ");
2006 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
2007 }
2008 return 0;
2009}
2010#endif
2011
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002012int
2013sys_fchown(tcp)
2014struct tcb *tcp;
2015{
2016 if (entering(tcp)) {
Roland McGrath6bc12202003-11-13 22:32:27 +00002017 tprintf("%ld", tcp->u_arg[0]);
2018 printuid(", ", tcp->u_arg[1]);
2019 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002020 }
2021 return 0;
2022}
2023
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002024static int
2025decode_chmod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002026{
2027 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002028 printpath(tcp, tcp->u_arg[offset]);
2029 tprintf(", %#lo", tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002030 }
2031 return 0;
2032}
2033
2034int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002035sys_chmod(struct tcb *tcp)
2036{
2037 return decode_chmod(tcp, 0);
2038}
2039
2040#ifdef LINUX
2041int
2042sys_fchmodat(struct tcb *tcp)
2043{
2044 if (entering(tcp))
2045 print_dirfd(tcp->u_arg[0]);
2046 return decode_chmod(tcp, 1);
2047}
2048#endif
2049
2050int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002051sys_fchmod(tcp)
2052struct tcb *tcp;
2053{
2054 if (entering(tcp)) {
2055 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
2056 }
2057 return 0;
2058}
2059
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00002060#ifdef ALPHA
2061int
2062sys_osf_utimes(tcp)
2063struct tcb *tcp;
2064{
2065 if (entering(tcp)) {
2066 printpath(tcp, tcp->u_arg[0]);
2067 tprintf(", ");
2068 printtv32(tcp, tcp->u_arg[1]);
2069 }
2070 return 0;
2071}
2072#endif
2073
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002074static int
2075decode_utimes(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002076{
2077 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002078 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002079 tprintf(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002080 printtv(tcp, tcp->u_arg[offset + 1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002081 }
2082 return 0;
2083}
2084
2085int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002086sys_utimes(struct tcb *tcp)
2087{
2088 return decode_utimes(tcp, 0);
2089}
2090
2091#ifdef LINUX
2092int
2093sys_futimesat(struct tcb *tcp)
2094{
2095 if (entering(tcp))
2096 print_dirfd(tcp->u_arg[0]);
2097 return decode_utimes(tcp, 1);
2098}
2099#endif
2100
2101int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002102sys_utime(tcp)
2103struct tcb *tcp;
2104{
2105 long ut[2];
2106
2107 if (entering(tcp)) {
2108 printpath(tcp, tcp->u_arg[0]);
2109 tprintf(", ");
2110 if (!tcp->u_arg[1])
2111 tprintf("NULL");
2112 else if (!verbose(tcp))
2113 tprintf("%#lx", tcp->u_arg[1]);
2114 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
2115 (char *) ut) < 0)
2116 tprintf("[?, ?]");
2117 else {
2118 tprintf("[%s,", sprinttime(ut[0]));
2119 tprintf(" %s]", sprinttime(ut[1]));
2120 }
2121 }
2122 return 0;
2123}
2124
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002125static int
2126decode_mknod(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002127{
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002128 int mode = tcp->u_arg[offset + 1];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002129
2130 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002131 printpath(tcp, tcp->u_arg[offset]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002132 tprintf(", %s", sprintmode(mode));
2133 switch (mode & S_IFMT) {
2134 case S_IFCHR: case S_IFBLK:
2135#ifdef LINUXSPARC
2136 if (current_personality == 1)
2137 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002138 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2139 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002140 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00002141#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002142 tprintf(", makedev(%lu, %lu)",
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002143 (unsigned long) major(tcp->u_arg[offset + 2]),
2144 (unsigned long) minor(tcp->u_arg[offset + 2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002145 break;
2146 default:
2147 break;
2148 }
2149 }
2150 return 0;
2151}
2152
2153int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002154sys_mknod(struct tcb *tcp)
2155{
2156 return decode_mknod(tcp, 0);
2157}
2158
2159#ifdef LINUX
2160int
2161sys_mknodat(struct tcb *tcp)
2162{
2163 if (entering(tcp))
2164 print_dirfd(tcp->u_arg[0]);
2165 return decode_mknod(tcp, 1);
2166}
2167#endif
2168
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002169#ifdef FREEBSD
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002170int
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002171sys_mkfifo(tcp)
2172struct tcb *tcp;
2173{
2174 if (entering(tcp)) {
2175 printpath(tcp, tcp->u_arg[0]);
2176 tprintf(", %#lo", tcp->u_arg[1]);
2177 }
2178 return 0;
2179}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +00002180#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002181
2182int
2183sys_fsync(tcp)
2184struct tcb *tcp;
2185{
2186 if (entering(tcp)) {
2187 tprintf("%ld", tcp->u_arg[0]);
2188 }
2189 return 0;
2190}
2191
Michal Ludvig53b320f2002-09-23 13:30:09 +00002192#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002193
2194static void
2195printdir(tcp, addr)
2196struct tcb *tcp;
2197long addr;
2198{
2199 struct dirent d;
2200
2201 if (!verbose(tcp)) {
2202 tprintf("%#lx", addr);
2203 return;
2204 }
2205 if (umove(tcp, addr, &d) < 0) {
2206 tprintf("{...}");
2207 return;
2208 }
2209 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002210 tprintf("d_name=");
2211 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2212 tprintf("}");
2213}
2214
2215int
2216sys_readdir(tcp)
2217struct tcb *tcp;
2218{
2219 if (entering(tcp)) {
2220 tprintf("%lu, ", tcp->u_arg[0]);
2221 } else {
2222 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2223 tprintf("%#lx", tcp->u_arg[1]);
2224 else
2225 printdir(tcp, tcp->u_arg[1]);
2226 /* Not much point in printing this out, it is always 1. */
2227 if (tcp->u_arg[2] != 1)
2228 tprintf(", %lu", tcp->u_arg[2]);
2229 }
2230 return 0;
2231}
2232
Michal Ludvig53b320f2002-09-23 13:30:09 +00002233#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002234
Roland McGrath40542842004-01-13 09:47:49 +00002235#if defined FREEBSD || defined LINUX
Roland McGratha4d48532005-06-08 20:45:28 +00002236static const struct xlat direnttypes[] = {
Roland McGrath40542842004-01-13 09:47:49 +00002237 { DT_UNKNOWN, "DT_UNKNOWN" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002238 { DT_FIFO, "DT_FIFO" },
2239 { DT_CHR, "DT_CHR" },
2240 { DT_DIR, "DT_DIR" },
2241 { DT_BLK, "DT_BLK" },
2242 { DT_REG, "DT_REG" },
2243 { DT_LNK, "DT_LNK" },
2244 { DT_SOCK, "DT_SOCK" },
2245 { DT_WHT, "DT_WHT" },
2246 { 0, NULL },
2247};
2248
2249#endif
2250
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002251int
2252sys_getdents(tcp)
2253struct tcb *tcp;
2254{
2255 int i, len, dents = 0;
2256 char *buf;
2257
2258 if (entering(tcp)) {
2259 tprintf("%lu, ", tcp->u_arg[0]);
2260 return 0;
2261 }
2262 if (syserror(tcp) || !verbose(tcp)) {
2263 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2264 return 0;
2265 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002266 len = tcp->u_rval;
2267 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002268 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2269 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002270 return 0;
2271 }
2272 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002273 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002274 free(buf);
2275 return 0;
2276 }
2277 if (!abbrev(tcp))
2278 tprintf("{");
2279 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002280 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002281#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002282 if (!abbrev(tcp)) {
2283 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2284 i ? " " : "", d->d_ino, d->d_off);
2285 tprintf("d_reclen=%u, d_name=\"%s\"}",
2286 d->d_reclen, d->d_name);
2287 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002288#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002289#ifdef SVR4
2290 if (!abbrev(tcp)) {
2291 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002292 i ? " " : "",
2293 (unsigned long) d->d_ino,
2294 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002295 tprintf("d_reclen=%u, d_name=\"%s\"}",
2296 d->d_reclen, d->d_name);
2297 }
2298#endif /* SVR4 */
2299#ifdef SUNOS4
2300 if (!abbrev(tcp)) {
2301 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2302 i ? " " : "", d->d_off, d->d_fileno,
2303 d->d_reclen);
2304 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2305 d->d_namlen, d->d_namlen, d->d_name);
2306 }
2307#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002308#ifdef FREEBSD
2309 if (!abbrev(tcp)) {
2310 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2311 i ? " " : "", d->d_fileno, d->d_reclen);
2312 printxval(direnttypes, d->d_type, "DT_???");
2313 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2314 d->d_namlen, d->d_namlen, d->d_name);
2315 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002316#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002317 if (!d->d_reclen) {
2318 tprintf("/* d_reclen == 0, problem here */");
2319 break;
2320 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002321 i += d->d_reclen;
2322 dents++;
2323 }
2324 if (!abbrev(tcp))
2325 tprintf("}");
2326 else
2327 tprintf("/* %u entries */", dents);
2328 tprintf(", %lu", tcp->u_arg[2]);
2329 free(buf);
2330 return 0;
2331}
2332
John Hughesbdf48f52001-03-06 15:08:09 +00002333
2334#if _LFS64_LARGEFILE
2335int
2336sys_getdents64(tcp)
2337struct tcb *tcp;
2338{
2339 int i, len, dents = 0;
2340 char *buf;
2341
2342 if (entering(tcp)) {
2343 tprintf("%lu, ", tcp->u_arg[0]);
2344 return 0;
2345 }
2346 if (syserror(tcp) || !verbose(tcp)) {
2347 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2348 return 0;
2349 }
2350 len = tcp->u_rval;
2351 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002352 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2353 fprintf(stderr, "out of memory\n");
John Hughesbdf48f52001-03-06 15:08:09 +00002354 return 0;
2355 }
2356 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002357 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002358 free(buf);
2359 return 0;
2360 }
2361 if (!abbrev(tcp))
2362 tprintf("{");
2363 for (i = 0; i < len;) {
2364 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002365#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002366 if (!abbrev(tcp)) {
Dmitry V. Levin1f336e52006-10-14 20:20:46 +00002367 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002368 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002369 d->d_ino,
2370 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002371#ifdef LINUX
2372 tprintf("d_type=");
2373 printxval(direnttypes, d->d_type, "DT_???");
2374 tprintf(", ");
2375#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002376 tprintf("d_reclen=%u, d_name=\"%s\"}",
2377 d->d_reclen, d->d_name);
2378 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002379#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002380#ifdef SUNOS4
2381 if (!abbrev(tcp)) {
2382 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2383 i ? " " : "", d->d_off, d->d_fileno,
2384 d->d_reclen);
2385 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2386 d->d_namlen, d->d_namlen, d->d_name);
2387 }
2388#endif /* SUNOS4 */
2389 i += d->d_reclen;
2390 dents++;
2391 }
2392 if (!abbrev(tcp))
2393 tprintf("}");
2394 else
2395 tprintf("/* %u entries */", dents);
2396 tprintf(", %lu", tcp->u_arg[2]);
2397 free(buf);
2398 return 0;
2399}
2400#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002401
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002402#ifdef FREEBSD
2403int
2404sys_getdirentries(tcp)
2405struct tcb * tcp;
2406{
2407 int i, len, dents = 0;
2408 long basep;
2409 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002410
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002411 if (entering(tcp)) {
2412 tprintf("%lu, ", tcp->u_arg[0]);
2413 return 0;
2414 }
2415 if (syserror(tcp) || !verbose(tcp)) {
2416 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2417 return 0;
2418 }
2419 len = tcp->u_rval;
2420 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002421 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2422 fprintf(stderr, "out of memory\n");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002423 return 0;
2424 }
2425 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002426 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002427 free(buf);
2428 return 0;
2429 }
2430 if (!abbrev(tcp))
2431 tprintf("{");
2432 for (i = 0; i < len;) {
2433 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2434 if (!abbrev(tcp)) {
2435 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2436 i ? " " : "", d->d_fileno, d->d_reclen);
2437 printxval(direnttypes, d->d_type, "DT_???");
2438 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2439 d->d_namlen, d->d_namlen, d->d_name);
2440 }
2441 i += d->d_reclen;
2442 dents++;
2443 }
2444 if (!abbrev(tcp))
2445 tprintf("}");
2446 else
2447 tprintf("/* %u entries */", dents);
2448 free(buf);
2449 tprintf(", %lu", tcp->u_arg[2]);
2450 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2451 tprintf(", %#lx", tcp->u_arg[3]);
2452 else
2453 tprintf(", [%lu]", basep);
2454 return 0;
2455}
2456#endif
2457
Michal Ludvig53b320f2002-09-23 13:30:09 +00002458#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002459int
2460sys_getcwd(tcp)
2461struct tcb *tcp;
2462{
2463 if (exiting(tcp)) {
2464 if (syserror(tcp))
2465 tprintf("%#lx", tcp->u_arg[0]);
2466 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002467 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002468 tprintf(", %lu", tcp->u_arg[1]);
2469 }
2470 return 0;
2471}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002472#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002473
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002474#ifdef FREEBSD
2475int
2476sys___getcwd(tcp)
2477struct tcb *tcp;
2478{
2479 if (exiting(tcp)) {
2480 if (syserror(tcp))
2481 tprintf("%#lx", tcp->u_arg[0]);
2482 else
2483 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2484 tprintf(", %lu", tcp->u_arg[1]);
2485 }
2486 return 0;
2487}
2488#endif
2489
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002490#ifdef HAVE_SYS_ASYNCH_H
2491
2492int
2493sys_aioread(tcp)
2494struct tcb *tcp;
2495{
2496 struct aio_result_t res;
2497
2498 if (entering(tcp)) {
2499 tprintf("%lu, ", tcp->u_arg[0]);
2500 } else {
2501 if (syserror(tcp))
2502 tprintf("%#lx", tcp->u_arg[1]);
2503 else
2504 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2505 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2506 printxval(whence, tcp->u_arg[4], "L_???");
2507 if (syserror(tcp) || tcp->u_arg[5] == 0
2508 || umove(tcp, tcp->u_arg[5], &res) < 0)
2509 tprintf(", %#lx", tcp->u_arg[5]);
2510 else
2511 tprintf(", {aio_return %d aio_errno %d}",
2512 res.aio_return, res.aio_errno);
2513 }
2514 return 0;
2515}
2516
2517int
2518sys_aiowrite(tcp)
2519struct tcb *tcp;
2520{
2521 struct aio_result_t res;
2522
2523 if (entering(tcp)) {
2524 tprintf("%lu, ", tcp->u_arg[0]);
2525 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2526 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2527 printxval(whence, tcp->u_arg[4], "L_???");
2528 }
2529 else {
2530 if (tcp->u_arg[5] == 0)
2531 tprintf(", NULL");
2532 else if (syserror(tcp)
2533 || umove(tcp, tcp->u_arg[5], &res) < 0)
2534 tprintf(", %#lx", tcp->u_arg[5]);
2535 else
2536 tprintf(", {aio_return %d aio_errno %d}",
2537 res.aio_return, res.aio_errno);
2538 }
2539 return 0;
2540}
2541
2542int
2543sys_aiowait(tcp)
2544struct tcb *tcp;
2545{
2546 if (entering(tcp))
2547 printtv(tcp, tcp->u_arg[0]);
2548 return 0;
2549}
2550
2551int
2552sys_aiocancel(tcp)
2553struct tcb *tcp;
2554{
2555 struct aio_result_t res;
2556
2557 if (exiting(tcp)) {
2558 if (tcp->u_arg[0] == 0)
2559 tprintf("NULL");
2560 else if (syserror(tcp)
2561 || umove(tcp, tcp->u_arg[0], &res) < 0)
2562 tprintf("%#lx", tcp->u_arg[0]);
2563 else
2564 tprintf("{aio_return %d aio_errno %d}",
2565 res.aio_return, res.aio_errno);
2566 }
2567 return 0;
2568}
2569
2570#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002571
Roland McGratha4d48532005-06-08 20:45:28 +00002572static const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002573#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002574 { XATTR_CREATE, "XATTR_CREATE" },
2575 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002576#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002577 { 0, NULL }
2578};
2579
Roland McGrath3292e222004-08-31 06:30:48 +00002580static void
2581print_xattr_val(tcp, failed, arg, insize, size)
2582struct tcb *tcp;
2583int failed;
2584unsigned long arg;
Roland McGrathaa524c82005-06-01 19:22:06 +00002585unsigned long insize, size;
Roland McGrath3292e222004-08-31 06:30:48 +00002586{
Roland McGrath883567c2005-02-02 03:38:32 +00002587 if (!failed) {
Roland McGrathaa524c82005-06-01 19:22:06 +00002588 unsigned long capacity = 4 * size + 1;
2589 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
Roland McGrath883567c2005-02-02 03:38:32 +00002590 if (buf == NULL || /* probably a bogus size argument */
Roland McGrathf7746422005-03-01 23:02:32 +00002591 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
Roland McGrath883567c2005-02-02 03:38:32 +00002592 failed = 1;
2593 }
2594 else {
2595 unsigned char *out = buf;
2596 unsigned char *in = &buf[3 * size];
2597 size_t i;
2598 for (i = 0; i < size; ++i)
2599 if (isprint(in[i]))
2600 *out++ = in[i];
2601 else {
Roland McGrath3292e222004-08-31 06:30:48 +00002602#define tohex(n) "0123456789abcdef"[n]
Roland McGrath883567c2005-02-02 03:38:32 +00002603 *out++ = '\\';
2604 *out++ = 'x';
2605 *out++ = tohex(in[i] / 16);
2606 *out++ = tohex(in[i] % 16);
2607 }
2608 /* Don't print terminating NUL if there is one. */
Dmitry V. Levin504eb0b2006-10-11 22:58:31 +00002609 if (i > 0 && in[i - 1] == '\0')
Roland McGrath883567c2005-02-02 03:38:32 +00002610 out -= 4;
2611 *out = '\0';
2612 tprintf(", \"%s\", %ld", buf, insize);
2613 }
2614 free(buf);
2615 }
2616 if (failed)
2617 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002618}
2619
Roland McGrath186c5ac2002-12-15 23:58:23 +00002620int
2621sys_setxattr(tcp)
2622struct tcb *tcp;
2623{
2624 if (entering(tcp)) {
2625 printpath(tcp, tcp->u_arg[0]);
2626 tprintf(", ");
2627 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002628 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2629 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002630 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002631 }
2632 return 0;
2633}
2634
2635int
2636sys_fsetxattr(tcp)
2637struct tcb *tcp;
2638{
2639 if (entering(tcp)) {
2640 tprintf("%ld, ", tcp->u_arg[0]);
2641 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002642 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2643 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00002644 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002645 }
2646 return 0;
2647}
2648
2649int
2650sys_getxattr(tcp)
2651struct tcb *tcp;
2652{
2653 if (entering(tcp)) {
2654 printpath(tcp, tcp->u_arg[0]);
2655 tprintf(", ");
2656 printstr(tcp, tcp->u_arg[1], -1);
2657 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002658 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2659 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002660 }
2661 return 0;
2662}
2663
2664int
2665sys_fgetxattr(tcp)
2666struct tcb *tcp;
2667{
2668 if (entering(tcp)) {
2669 tprintf("%ld, ", tcp->u_arg[0]);
2670 printstr(tcp, tcp->u_arg[1], -1);
2671 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002672 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2673 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002674 }
2675 return 0;
2676}
2677
2678int
2679sys_listxattr(tcp)
2680struct tcb *tcp;
2681{
2682 if (entering(tcp)) {
2683 printpath(tcp, tcp->u_arg[0]);
2684 } else {
2685 /* XXX Print value in format */
2686 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2687 }
2688 return 0;
2689}
2690
2691int
2692sys_flistxattr(tcp)
2693struct tcb *tcp;
2694{
2695 if (entering(tcp)) {
2696 tprintf("%ld", tcp->u_arg[0]);
2697 } else {
2698 /* XXX Print value in format */
2699 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2700 }
2701 return 0;
2702}
2703
2704int
2705sys_removexattr(tcp)
2706struct tcb *tcp;
2707{
2708 if (entering(tcp)) {
2709 printpath(tcp, tcp->u_arg[0]);
2710 tprintf(", ");
2711 printstr(tcp, tcp->u_arg[1], -1);
2712 }
2713 return 0;
2714}
2715
2716int
2717sys_fremovexattr(tcp)
2718struct tcb *tcp;
2719{
2720 if (entering(tcp)) {
2721 tprintf("%ld, ", tcp->u_arg[0]);
2722 printstr(tcp, tcp->u_arg[1], -1);
2723 }
2724 return 0;
2725}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002726
2727
2728static const struct xlat advise[] = {
2729 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2730 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2731 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2732 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2733 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2734 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2735 { 0, NULL }
2736};
2737
2738
Roland McGrathe27ed342004-10-20 02:24:19 +00002739#ifdef LINUX
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002740int
2741sys_fadvise64(tcp)
2742struct tcb *tcp;
2743{
2744 if (entering(tcp)) {
2745 tprintf("%ld, %lld, %ld, ",
2746 tcp->u_arg[0],
2747# if defined IA64 || defined X86_64 || defined ALPHA
2748 (long long int) tcp->u_arg[1], tcp->u_arg[2]);
2749 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2750#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002751 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
2752 printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002753#endif
2754 }
2755 return 0;
2756}
2757#endif
2758
2759
2760int
2761sys_fadvise64_64(tcp)
2762struct tcb *tcp;
2763{
2764 if (entering(tcp)) {
2765 tprintf("%ld, %lld, %lld, ",
2766 tcp->u_arg[0],
2767# if defined IA64 || defined X86_64 || defined ALPHA
2768 (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
2769 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2770#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002771 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
2772 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002773 printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
2774#endif
2775 }
2776 return 0;
2777}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00002778
2779#ifdef LINUX
2780static const struct xlat inotify_modes[] = {
2781 { 0x00000001, "IN_ACCESS" },
2782 { 0x00000002, "IN_MODIFY" },
2783 { 0x00000004, "IN_ATTRIB" },
2784 { 0x00000008, "IN_CLOSE_WRITE" },
2785 { 0x00000010, "IN_CLOSE_NOWRITE" },
2786 { 0x00000020, "IN_OPEN" },
2787 { 0x00000040, "IN_MOVED_FROM" },
2788 { 0x00000080, "IN_MOVED_TO" },
2789 { 0x00000100, "IN_CREATE" },
2790 { 0x00000200, "IN_DELETE" },
2791 { 0x00000400, "IN_DELETE_SELF" },
2792 { 0x00000800, "IN_MOVE_SELF" },
2793 { 0x00002000, "IN_UNMOUNT" },
2794 { 0x00004000, "IN_Q_OVERFLOW" },
2795 { 0x00008000, "IN_IGNORED" },
2796 { 0x01000000, "IN_ONLYDIR" },
2797 { 0x02000000, "IN_DONT_FOLLOW" },
2798 { 0x20000000, "IN_MASK_ADD" },
2799 { 0x40000000, "IN_ISDIR" },
2800 { 0x80000000, "IN_ONESHOT" }
2801};
2802
2803int
2804sys_inotify_add_watch(struct tcb *tcp)
2805{
2806 if (entering(tcp)) {
2807 tprintf("%ld, ", tcp->u_arg[0]);
2808 printpath(tcp, tcp->u_arg[1]);
2809 tprintf(", ");
2810 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2811 }
2812 return 0;
2813}
2814
2815int
2816sys_inotify_rm_watch(struct tcb *tcp)
2817{
2818 if (entering(tcp)) {
2819 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
2820 }
2821 return 0;
2822}
2823#endif