blob: 630f973e6080b3d6a6865c643054c37ba7029b8a [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
171#if HAVE_LONG_LONG_OFF_T
172/*
173 * Ugly hacks for systems that have typedef long long off_t
174 */
John Hughesb8c9f772001-03-07 16:53:07 +0000175
176#define stat64 stat
177#define HAVE_STAT64 1 /* Ugly hack */
John Hughes70623be2001-03-08 13:59:00 +0000178
179#define sys_stat64 sys_stat
180#define sys_fstat64 sys_fstat
181#define sys_lstat64 sys_lstat
182#define sys_lseek64 sys_lseek
183#define sys_truncate64 sys_truncate
184#define sys_ftruncate64 sys_ftruncate
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000185#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186
187#ifdef MAJOR_IN_SYSMACROS
188#include <sys/sysmacros.h>
189#endif
190
191#ifdef MAJOR_IN_MKDEV
192#include <sys/mkdev.h>
193#endif
194
195#ifdef HAVE_SYS_ASYNCH_H
196#include <sys/asynch.h>
197#endif
198
199#ifdef SUNOS4
200#include <ustat.h>
201#endif
202
203/*
204 * This is a really dirty trick but it should always work. Traditional
205 * Unix says r/w/rw are 0/1/2, so we make them true flags 1/2/3 by
206 * adding 1. Just remember to add 1 to any arg decoded with openmodes.
207 */
Roland McGrathd9f816f2004-09-04 03:39:20 +0000208const struct xlat openmodes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000209 { O_RDWR+1, "O_RDWR" },
210 { O_RDONLY+1, "O_RDONLY" },
211 { O_WRONLY+1, "O_WRONLY" },
212 { O_NONBLOCK, "O_NONBLOCK" },
213 { O_APPEND, "O_APPEND" },
214 { O_CREAT, "O_CREAT" },
215 { O_TRUNC, "O_TRUNC" },
216 { O_EXCL, "O_EXCL" },
217 { O_NOCTTY, "O_NOCTTY" },
218#ifdef O_SYNC
219 { O_SYNC, "O_SYNC" },
220#endif
221#ifdef O_ASYNC
222 { O_ASYNC, "O_ASYNC" },
223#endif
224#ifdef O_DSYNC
225 { O_DSYNC, "O_DSYNC" },
226#endif
227#ifdef O_RSYNC
228 { O_RSYNC, "O_RSYNC" },
229#endif
230#ifdef O_NDELAY
231 { O_NDELAY, "O_NDELAY" },
232#endif
233#ifdef O_PRIV
234 { O_PRIV, "O_PRIV" },
235#endif
236#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000237 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000238#endif
239#ifdef O_LARGEFILE
Roland McGrathfee836e2005-02-02 22:11:32 +0000240# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
241# undef O_LARGEFILE
242# ifdef SPARC64
243# define O_LARGEFILE 0x40000
244# elif defined X86_64 || defined S390X
245# define O_LARGEFILE 0100000
246# endif
247# endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000248 { O_LARGEFILE, "O_LARGEFILE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000249#endif
250#ifdef O_DIRECTORY
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000251 { O_DIRECTORY, "O_DIRECTORY" },
252#endif
253#ifdef O_NOFOLLOW
254 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000255#endif
256
257#ifdef FNDELAY
258 { FNDELAY, "FNDELAY" },
259#endif
260#ifdef FAPPEND
261 { FAPPEND, "FAPPEND" },
262#endif
263#ifdef FMARK
264 { FMARK, "FMARK" },
265#endif
266#ifdef FDEFER
267 { FDEFER, "FDEFER" },
268#endif
269#ifdef FASYNC
270 { FASYNC, "FASYNC" },
271#endif
272#ifdef FSHLOCK
273 { FSHLOCK, "FSHLOCK" },
274#endif
275#ifdef FEXLOCK
276 { FEXLOCK, "FEXLOCK" },
277#endif
278#ifdef FCREAT
279 { FCREAT, "FCREAT" },
280#endif
281#ifdef FTRUNC
282 { FTRUNC, "FTRUNC" },
283#endif
284#ifdef FEXCL
285 { FEXCL, "FEXCL" },
286#endif
287#ifdef FNBIO
288 { FNBIO, "FNBIO" },
289#endif
290#ifdef FSYNC
291 { FSYNC, "FSYNC" },
292#endif
293#ifdef FNOCTTY
294 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000295#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000296#ifdef O_SHLOCK
297 { O_SHLOCK, "O_SHLOCK" },
298#endif
299#ifdef O_EXLOCK
300 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000301#endif
302 { 0, NULL },
303};
304
305int
306sys_open(tcp)
307struct tcb *tcp;
308{
309 if (entering(tcp)) {
310 printpath(tcp, tcp->u_arg[0]);
311 tprintf(", ");
312 /* flags */
313 printflags(openmodes, tcp->u_arg[1] + 1);
314 if (tcp->u_arg[1] & O_CREAT) {
315 /* mode */
316 tprintf(", %#lo", tcp->u_arg[2]);
317 }
318 }
319 return 0;
320}
321
322#ifdef LINUXSPARC
Roland McGrathd9f816f2004-09-04 03:39:20 +0000323const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000324 { 0, "O_RDWR" },
325 { 1, "O_RDONLY" },
326 { 2, "O_WRONLY" },
327 { 0x80, "O_NONBLOCK" },
328 { 8, "O_APPEND" },
329 { 0x100, "O_CREAT" },
330 { 0x200, "O_TRUNC" },
331 { 0x400, "O_EXCL" },
332 { 0x800, "O_NOCTTY" },
333 { 0x10, "O_SYNC" },
334 { 0x40, "O_DSYNC" },
335 { 0x8000, "O_RSYNC" },
336 { 4, "O_NDELAY" },
337 { 0x1000, "O_PRIV" },
338 { 0, NULL },
339};
340
341int
342solaris_open(tcp)
343struct tcb *tcp;
344{
345 if (entering(tcp)) {
346 printpath(tcp, tcp->u_arg[0]);
347 tprintf(", ");
348 /* flags */
349 printflags(openmodessol, tcp->u_arg[1] + 1);
350 if (tcp->u_arg[1] & 0x100) {
351 /* mode */
352 tprintf(", %#lo", tcp->u_arg[2]);
353 }
354 }
355 return 0;
356}
357
358#endif
359
360int
361sys_creat(tcp)
362struct tcb *tcp;
363{
364 if (entering(tcp)) {
365 printpath(tcp, tcp->u_arg[0]);
366 tprintf(", %#lo", tcp->u_arg[1]);
367 }
368 return 0;
369}
370
Roland McGrathd9f816f2004-09-04 03:39:20 +0000371static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000372 { F_OK, "F_OK", },
373 { R_OK, "R_OK" },
374 { W_OK, "W_OK" },
375 { X_OK, "X_OK" },
376#ifdef EFF_ONLY_OK
377 { EFF_ONLY_OK, "EFF_ONLY_OK" },
378#endif
379#ifdef EX_OK
380 { EX_OK, "EX_OK" },
381#endif
382 { 0, NULL },
383};
384
385int
386sys_access(tcp)
387struct tcb *tcp;
388{
389 if (entering(tcp)) {
390 printpath(tcp, tcp->u_arg[0]);
391 tprintf(", ");
392 printflags(access_flags, tcp->u_arg[1]);
393 }
394 return 0;
395}
396
397int
398sys_umask(tcp)
399struct tcb *tcp;
400{
401 if (entering(tcp)) {
402 tprintf("%#lo", tcp->u_arg[0]);
403 }
404 return RVAL_OCTAL;
405}
406
Roland McGrathd9f816f2004-09-04 03:39:20 +0000407static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000408 { SEEK_SET, "SEEK_SET" },
409 { SEEK_CUR, "SEEK_CUR" },
410 { SEEK_END, "SEEK_END" },
411 { 0, NULL },
412};
413
John Hughes70623be2001-03-08 13:59:00 +0000414#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000415int
416sys_lseek(tcp)
417struct tcb *tcp;
418{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000419 off_t offset;
420 int _whence;
421
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000422 if (entering(tcp)) {
423 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000424 offset = tcp->u_arg[1];
425 _whence = tcp->u_arg[2];
426 if (_whence == SEEK_SET)
427 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000428 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000429 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000430 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000431 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000432 return RVAL_UDECIMAL;
433}
John Hughes5a826b82001-03-07 13:21:24 +0000434#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000435
Michal Ludvig53b320f2002-09-23 13:30:09 +0000436#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000437int
438sys_llseek (tcp)
439struct tcb *tcp;
440{
441 if (entering(tcp)) {
Roland McGrath8c304bc2004-10-19 22:59:55 +0000442 /*
443 * This one call takes explicitly two 32-bit arguments hi, lo,
444 * rather than one 64-bit argument for which LONG_LONG works
445 * appropriate for the native byte order.
446 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000447 if (tcp->u_arg[4] == SEEK_SET)
448 tprintf("%ld, %llu, ", tcp->u_arg[0],
Roland McGrath8c304bc2004-10-19 22:59:55 +0000449 (((long long int) tcp->u_arg[1]) << 32
450 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000451 else
452 tprintf("%ld, %lld, ", tcp->u_arg[0],
Roland McGrath8c304bc2004-10-19 22:59:55 +0000453 (((long long int) tcp->u_arg[1]) << 32
454 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000455 }
456 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000457 long long int off;
458 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000459 tprintf("%#lx, ", tcp->u_arg[3]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000460 else
461 tprintf("[%llu], ", off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000462 printxval(whence, tcp->u_arg[4], "SEEK_???");
463 }
464 return 0;
465}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000466
467int
468sys_readahead (tcp)
469struct tcb *tcp;
470{
471 if (entering(tcp)) {
472 tprintf("%ld, %lld, %ld", tcp->u_arg[0],
473# if defined IA64 || defined X86_64 || defined ALPHA
474 (long long int) tcp->u_arg[1], tcp->u_arg[2]
475# else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +0000476 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]
Roland McGrath186c5ac2002-12-15 23:58:23 +0000477# endif
478 );
479 }
480 return 0;
481}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000482#endif
483
John Hughes70623be2001-03-08 13:59:00 +0000484#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000485int
486sys_lseek64 (tcp)
487struct tcb *tcp;
488{
489 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000490 long long offset;
491 ALIGN64 (tcp, 1); /* FreeBSD aligns off_t args */
John Hughes0c79e012001-03-08 14:40:06 +0000492 offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +0000493 if (tcp->u_arg[3] == SEEK_SET)
494 tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
495 else
496 tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
497 printxval(whence, tcp->u_arg[3], "SEEK_???");
498 }
499 return RVAL_LUDECIMAL;
500}
501#endif
502
John Hughes70623be2001-03-08 13:59:00 +0000503#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000504int
505sys_truncate(tcp)
506struct tcb *tcp;
507{
508 if (entering(tcp)) {
509 printpath(tcp, tcp->u_arg[0]);
510 tprintf(", %lu", tcp->u_arg[1]);
511 }
512 return 0;
513}
John Hughes5a826b82001-03-07 13:21:24 +0000514#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000515
John Hughes70623be2001-03-08 13:59:00 +0000516#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000517int
518sys_truncate64(tcp)
519struct tcb *tcp;
520{
521 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000522 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000523 printpath(tcp, tcp->u_arg[0]);
John Hughes0c79e012001-03-08 14:40:06 +0000524 tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000525 }
526 return 0;
527}
528#endif
529
John Hughes70623be2001-03-08 13:59:00 +0000530#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000531int
532sys_ftruncate(tcp)
533struct tcb *tcp;
534{
535 if (entering(tcp)) {
536 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
537 }
538 return 0;
539}
John Hughes5a826b82001-03-07 13:21:24 +0000540#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541
John Hughes70623be2001-03-08 13:59:00 +0000542#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000543int
544sys_ftruncate64(tcp)
545struct tcb *tcp;
546{
547 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000548 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000549 tprintf("%ld, %llu", tcp->u_arg[0],
John Hughes0c79e012001-03-08 14:40:06 +0000550 LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000551 }
552 return 0;
553}
554#endif
555
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000556/* several stats */
557
Roland McGrathd9f816f2004-09-04 03:39:20 +0000558static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000559 { S_IFREG, "S_IFREG" },
560 { S_IFSOCK, "S_IFSOCK" },
561 { S_IFIFO, "S_IFIFO" },
562 { S_IFLNK, "S_IFLNK" },
563 { S_IFDIR, "S_IFDIR" },
564 { S_IFBLK, "S_IFBLK" },
565 { S_IFCHR, "S_IFCHR" },
566 { 0, NULL },
567};
568
Roland McGrathf9c49b22004-10-06 22:11:54 +0000569static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000570sprintmode(mode)
571int mode;
572{
573 static char buf[64];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000574 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000575
576 if ((mode & S_IFMT) == 0)
577 s = "";
578 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
579 sprintf(buf, "%#o", mode);
580 return buf;
581 }
582 sprintf(buf, "%s%s%s%s", s,
583 (mode & S_ISUID) ? "|S_ISUID" : "",
584 (mode & S_ISGID) ? "|S_ISGID" : "",
585 (mode & S_ISVTX) ? "|S_ISVTX" : "");
586 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
587 if (mode)
588 sprintf(buf + strlen(buf), "|%#o", mode);
589 s = (*buf == '|') ? buf + 1 : buf;
590 return *s ? s : "0";
591}
592
593static char *
594sprinttime(t)
595time_t t;
596{
597 struct tm *tmp;
598 static char buf[32];
599
600 if (t == 0) {
601 sprintf(buf, "0");
602 return buf;
603 }
604 tmp = localtime(&t);
605 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
Wichert Akkerman3ed6dc22000-01-11 14:41:09 +0000606 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000607 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
608 return buf;
609}
610
611#ifdef LINUXSPARC
612typedef struct {
613 int tv_sec;
614 int tv_nsec;
615} timestruct_t;
616
617struct solstat {
618 unsigned st_dev;
619 int st_pad1[3]; /* network id */
620 unsigned st_ino;
621 unsigned st_mode;
622 unsigned st_nlink;
623 unsigned st_uid;
624 unsigned st_gid;
625 unsigned st_rdev;
626 int st_pad2[2];
627 int st_size;
628 int st_pad3; /* st_size, off_t expansion */
629 timestruct_t st_atime;
630 timestruct_t st_mtime;
631 timestruct_t st_ctime;
632 int st_blksize;
633 int st_blocks;
634 char st_fstype[16];
635 int st_pad4[8]; /* expansion area */
636};
637
638static void
639printstatsol(tcp, addr)
640struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000641long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000642{
643 struct solstat statbuf;
644
645 if (!addr) {
646 tprintf("NULL");
647 return;
648 }
649 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000650 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000651 return;
652 }
653 if (umove(tcp, addr, &statbuf) < 0) {
654 tprintf("{...}");
655 return;
656 }
657 if (!abbrev(tcp)) {
658 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
659 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
660 (unsigned long) (statbuf.st_dev & 0x3ffff),
661 (unsigned long) statbuf.st_ino,
662 sprintmode(statbuf.st_mode));
663 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
664 (unsigned long) statbuf.st_nlink,
665 (unsigned long) statbuf.st_uid,
666 (unsigned long) statbuf.st_gid);
667 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
668 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
669 }
670 else
671 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
672 switch (statbuf.st_mode & S_IFMT) {
673 case S_IFCHR: case S_IFBLK:
674 tprintf("st_rdev=makedev(%lu, %lu), ",
675 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
676 (unsigned long) (statbuf.st_rdev & 0x3ffff));
677 break;
678 default:
679 tprintf("st_size=%u, ", statbuf.st_size);
680 break;
681 }
682 if (!abbrev(tcp)) {
683 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
684 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
685 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
686 }
687 else
688 tprintf("...}");
689}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000690
691#if defined (SPARC64)
692static void
693printstat_sparc64(tcp, addr)
694struct tcb *tcp;
695long addr;
696{
697 struct stat_sparc64 statbuf;
698
699 if (!addr) {
700 tprintf("NULL");
701 return;
702 }
703 if (syserror(tcp) || !verbose(tcp)) {
704 tprintf("%#lx", addr);
705 return;
706 }
707 if (umove(tcp, addr, &statbuf) < 0) {
708 tprintf("{...}");
709 return;
710 }
711
712 if (!abbrev(tcp)) {
713 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
714 (unsigned long) major(statbuf.st_dev),
715 (unsigned long) minor(statbuf.st_dev),
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, ",
723 (unsigned long) statbuf.st_blksize);
724 tprintf("st_blocks=%lu, ",
725 (unsigned long) statbuf.st_blocks);
726 }
727 else
728 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
729 switch (statbuf.st_mode & S_IFMT) {
730 case S_IFCHR: case S_IFBLK:
731 tprintf("st_rdev=makedev(%lu, %lu), ",
732 (unsigned long) major(statbuf.st_rdev),
733 (unsigned long) minor(statbuf.st_rdev));
734 break;
735 default:
736 tprintf("st_size=%lu, ", statbuf.st_size);
737 break;
738 }
739 if (!abbrev(tcp)) {
740 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
741 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
742 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
743 tprintf("}");
744 }
745 else
746 tprintf("...}");
747}
748#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000749#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000750
Roland McGrathd9f816f2004-09-04 03:39:20 +0000751const struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000752#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000753 { UF_NODUMP, "UF_NODUMP" },
754 { UF_IMMUTABLE, "UF_IMMUTABLE" },
755 { UF_APPEND, "UF_APPEND" },
756 { UF_OPAQUE, "UF_OPAQUE" },
757 { UF_NOUNLINK, "UF_NOUNLINK" },
758 { SF_ARCHIVED, "SF_ARCHIVED" },
759 { SF_IMMUTABLE, "SF_IMMUTABLE" },
760 { SF_APPEND, "SF_APPEND" },
761 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000762#elif UNIXWARE >= 2
763#ifdef _S_ISMLD
764 { _S_ISMLD, "_S_ISMLD" },
765#endif
766#ifdef _S_ISMOUNTED
767 { _S_ISMOUNTED, "_S_ISMOUNTED" },
768#endif
769#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000770 { 0, NULL },
771};
772
John Hughesc0fc3fd2001-03-08 16:10:40 +0000773#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000774int
775sys_chflags(tcp)
776struct tcb *tcp;
777{
778 if (entering(tcp)) {
779 printpath(tcp, tcp->u_arg[0]);
780 tprintf(", ");
781 if (tcp->u_arg[1])
782 printflags(fileflags, tcp->u_arg[1]);
783 else
784 tprintf("0");
785 }
786 return 0;
787}
788
789int
790sys_fchflags(tcp)
791struct tcb *tcp;
792{
793 if (entering(tcp)) {
794 tprintf("%ld, ", tcp->u_arg[0]);
795 if (tcp->u_arg[1])
796 printflags(fileflags, tcp->u_arg[1]);
797 else
798 tprintf("0");
799 }
800 return 0;
801}
802#endif
803
John Hughes70623be2001-03-08 13:59:00 +0000804#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000805static void
806realprintstat(tcp, statbuf)
807struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000808struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000809{
810 if (!abbrev(tcp)) {
811 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
812 (unsigned long) major(statbuf->st_dev),
813 (unsigned long) minor(statbuf->st_dev),
814 (unsigned long) statbuf->st_ino,
815 sprintmode(statbuf->st_mode));
816 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
817 (unsigned long) statbuf->st_nlink,
818 (unsigned long) statbuf->st_uid,
819 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000820#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000821 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000822#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
823#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000824 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000825#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000826 }
827 else
828 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
829 switch (statbuf->st_mode & S_IFMT) {
830 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000831#ifdef HAVE_STRUCT_STAT_ST_RDEV
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000832 tprintf("st_rdev=makedev(%lu, %lu), ",
833 (unsigned long) major(statbuf->st_rdev),
834 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000835#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000836 tprintf("st_size=makedev(%lu, %lu), ",
837 (unsigned long) major(statbuf->st_size),
838 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000839#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000840 break;
841 default:
842 tprintf("st_size=%lu, ", statbuf->st_size);
843 break;
844 }
845 if (!abbrev(tcp)) {
846 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
847 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000848 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000849#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000850 tprintf(", st_flags=");
851 if (statbuf->st_flags) {
852 printflags(fileflags, statbuf->st_flags);
853 } else
854 tprintf("0");
855#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000856#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000857 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
858#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000859#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000860 tprintf(", st_level=%ld", statbuf->st_level);
861#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000862#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000863 tprintf(", st_fstype=%.*s",
864 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
865#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000866#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000867 tprintf(", st_gen=%u", statbuf->st_gen);
868#endif
869 tprintf("}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000870 }
871 else
872 tprintf("...}");
873}
874
Nate Sammons771a6ff1999-04-05 22:39:31 +0000875
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000876static void
877printstat(tcp, addr)
878struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000879long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000880{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000881 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000882
883#ifdef LINUXSPARC
884 if (current_personality == 1) {
885 printstatsol(tcp, addr);
886 return;
887 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000888#ifdef SPARC64
889 else if (current_personality == 2) {
890 printstat_sparc64(tcp, addr);
891 return;
892 }
893#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000894#endif /* LINUXSPARC */
895
896 if (!addr) {
897 tprintf("NULL");
898 return;
899 }
900 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000901 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000902 return;
903 }
904 if (umove(tcp, addr, &statbuf) < 0) {
905 tprintf("{...}");
906 return;
907 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000908
909 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000910}
John Hughes70623be2001-03-08 13:59:00 +0000911#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000912
Wichert Akkermanc7926982000-04-10 22:22:31 +0000913#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000914static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000915printstat64(tcp, addr)
916struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000917long addr;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000918{
919 struct stat64 statbuf;
920
921#ifdef LINUXSPARC
922 if (current_personality == 1) {
923 printstatsol(tcp, addr);
924 return;
925 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000926#ifdef SPARC64
927 else if (current_personality == 2) {
928 printstat_sparc64(tcp, addr);
929 return;
930 }
931#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000932#endif /* LINUXSPARC */
933
934 if (!addr) {
935 tprintf("NULL");
936 return;
937 }
938 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000939 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000940 return;
941 }
942 if (umove(tcp, addr, &statbuf) < 0) {
943 tprintf("{...}");
944 return;
945 }
946
947 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +0000948#ifdef HAVE_LONG_LONG
949 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
950#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000951 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +0000952#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000953 (unsigned long) major(statbuf.st_dev),
954 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +0000955#ifdef HAVE_LONG_LONG
956 (unsigned long long) statbuf.st_ino,
957#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000958 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +0000959#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000960 sprintmode(statbuf.st_mode));
961 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
962 (unsigned long) statbuf.st_nlink,
963 (unsigned long) statbuf.st_uid,
964 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000965#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000966 tprintf("st_blksize=%lu, ",
967 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000968#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
969#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000970 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000971#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000972 }
973 else
974 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
975 switch (statbuf.st_mode & S_IFMT) {
976 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000977#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000978 tprintf("st_rdev=makedev(%lu, %lu), ",
979 (unsigned long) major(statbuf.st_rdev),
980 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000981#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000982 tprintf("st_size=makedev(%lu, %lu), ",
983 (unsigned long) major(statbuf.st_size),
984 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000985#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000986 break;
987 default:
988 tprintf("st_size=%llu, ", statbuf.st_size);
989 break;
990 }
991 if (!abbrev(tcp)) {
992 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
993 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000994 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000995#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000996 tprintf(", st_flags=");
John Hughesb8c9f772001-03-07 16:53:07 +0000997 if (statbuf.st_flags) {
998 printflags(fileflags, statbuf.st_flags);
999 } else
1000 tprintf("0");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001001#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001002#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001003 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1004#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001005#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001006 tprintf(", st_level=%ld", statbuf.st_level);
1007#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001008#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001009 tprintf(", st_fstype=%.*s",
1010 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1011#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001012#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001013 tprintf(", st_gen=%u", statbuf.st_gen);
1014#endif
1015 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001016 }
1017 else
1018 tprintf("...}");
1019}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001020#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001021
Roland McGrath79db8af2003-06-27 21:20:09 +00001022#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001023static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001024convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001025const struct __old_kernel_stat *oldbuf;
1026struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001027{
1028 newbuf->st_dev=oldbuf->st_dev;
1029 newbuf->st_ino=oldbuf->st_ino;
1030 newbuf->st_mode=oldbuf->st_mode;
1031 newbuf->st_nlink=oldbuf->st_nlink;
1032 newbuf->st_uid=oldbuf->st_uid;
1033 newbuf->st_gid=oldbuf->st_gid;
1034 newbuf->st_rdev=oldbuf->st_rdev;
1035 newbuf->st_size=oldbuf->st_size;
1036 newbuf->st_atime=oldbuf->st_atime;
1037 newbuf->st_mtime=oldbuf->st_mtime;
1038 newbuf->st_ctime=oldbuf->st_ctime;
1039 newbuf->st_blksize=0; /* not supported in old_stat */
1040 newbuf->st_blocks=0; /* not supported in old_stat */
1041}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001042
1043
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001044static void
1045printoldstat(tcp, addr)
1046struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001047long addr;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001048{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001049 struct __old_kernel_stat statbuf;
1050 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001051
1052#ifdef LINUXSPARC
1053 if (current_personality == 1) {
1054 printstatsol(tcp, addr);
1055 return;
1056 }
1057#endif /* LINUXSPARC */
1058
1059 if (!addr) {
1060 tprintf("NULL");
1061 return;
1062 }
1063 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001064 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001065 return;
1066 }
1067 if (umove(tcp, addr, &statbuf) < 0) {
1068 tprintf("{...}");
1069 return;
1070 }
1071
1072 convertoldstat(&statbuf, &newstatbuf);
1073 realprintstat(tcp, &newstatbuf);
1074}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001075#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001076
John Hughes70623be2001-03-08 13:59:00 +00001077#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001078int
1079sys_stat(tcp)
1080struct tcb *tcp;
1081{
1082 if (entering(tcp)) {
1083 printpath(tcp, tcp->u_arg[0]);
1084 tprintf(", ");
1085 } else {
1086 printstat(tcp, tcp->u_arg[1]);
1087 }
1088 return 0;
1089}
John Hughesb8c9f772001-03-07 16:53:07 +00001090#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001091
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001092int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001093sys_stat64(tcp)
1094struct tcb *tcp;
1095{
1096#ifdef HAVE_STAT64
1097 if (entering(tcp)) {
1098 printpath(tcp, tcp->u_arg[0]);
1099 tprintf(", ");
1100 } else {
1101 printstat64(tcp, tcp->u_arg[1]);
1102 }
1103 return 0;
1104#else
1105 return printargs(tcp);
1106#endif
1107}
1108
Roland McGrath79db8af2003-06-27 21:20:09 +00001109#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001110int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001111sys_oldstat(tcp)
1112struct tcb *tcp;
1113{
1114 if (entering(tcp)) {
1115 printpath(tcp, tcp->u_arg[0]);
1116 tprintf(", ");
1117 } else {
1118 printoldstat(tcp, tcp->u_arg[1]);
1119 }
1120 return 0;
1121}
Roland McGrath79db8af2003-06-27 21:20:09 +00001122#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001123
John Hughes70623be2001-03-08 13:59:00 +00001124#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001125int
1126sys_fstat(tcp)
1127struct tcb *tcp;
1128{
1129 if (entering(tcp))
1130 tprintf("%ld, ", tcp->u_arg[0]);
1131 else {
1132 printstat(tcp, tcp->u_arg[1]);
1133 }
1134 return 0;
1135}
John Hughesb8c9f772001-03-07 16:53:07 +00001136#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001137
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001138int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001139sys_fstat64(tcp)
1140struct tcb *tcp;
1141{
1142#ifdef HAVE_STAT64
1143 if (entering(tcp))
1144 tprintf("%ld, ", tcp->u_arg[0]);
1145 else {
1146 printstat64(tcp, tcp->u_arg[1]);
1147 }
1148 return 0;
1149#else
1150 return printargs(tcp);
1151#endif
1152}
1153
Roland McGrath79db8af2003-06-27 21:20:09 +00001154#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001155int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001156sys_oldfstat(tcp)
1157struct tcb *tcp;
1158{
1159 if (entering(tcp))
1160 tprintf("%ld, ", tcp->u_arg[0]);
1161 else {
1162 printoldstat(tcp, tcp->u_arg[1]);
1163 }
1164 return 0;
1165}
Roland McGrath79db8af2003-06-27 21:20:09 +00001166#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001167
John Hughes70623be2001-03-08 13:59:00 +00001168#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001169int
1170sys_lstat(tcp)
1171struct tcb *tcp;
1172{
1173 if (entering(tcp)) {
1174 printpath(tcp, tcp->u_arg[0]);
1175 tprintf(", ");
1176 } else {
1177 printstat(tcp, tcp->u_arg[1]);
1178 }
1179 return 0;
1180}
John Hughesb8c9f772001-03-07 16:53:07 +00001181#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001182
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001183int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001184sys_lstat64(tcp)
1185struct tcb *tcp;
1186{
1187#ifdef HAVE_STAT64
1188 if (entering(tcp)) {
1189 printpath(tcp, tcp->u_arg[0]);
1190 tprintf(", ");
1191 } else {
1192 printstat64(tcp, tcp->u_arg[1]);
1193 }
1194 return 0;
1195#else
1196 return printargs(tcp);
1197#endif
1198}
1199
Roland McGrath79db8af2003-06-27 21:20:09 +00001200#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001201int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001202sys_oldlstat(tcp)
1203struct tcb *tcp;
1204{
1205 if (entering(tcp)) {
1206 printpath(tcp, tcp->u_arg[0]);
1207 tprintf(", ");
1208 } else {
1209 printoldstat(tcp, tcp->u_arg[1]);
1210 }
1211 return 0;
1212}
Roland McGrath79db8af2003-06-27 21:20:09 +00001213#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001214
1215
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001216#if defined(SVR4) || defined(LINUXSPARC)
1217
1218int
1219sys_xstat(tcp)
1220struct tcb *tcp;
1221{
1222 if (entering(tcp)) {
1223 tprintf("%ld, ", tcp->u_arg[0]);
1224 printpath(tcp, tcp->u_arg[1]);
1225 tprintf(", ");
1226 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001227#ifdef _STAT64_VER
1228 if (tcp->u_arg[0] == _STAT64_VER)
1229 printstat64 (tcp, tcp->u_arg[2]);
1230 else
1231#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001232 printstat(tcp, tcp->u_arg[2]);
1233 }
1234 return 0;
1235}
1236
1237int
1238sys_fxstat(tcp)
1239struct tcb *tcp;
1240{
1241 if (entering(tcp))
1242 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1243 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001244#ifdef _STAT64_VER
1245 if (tcp->u_arg[0] == _STAT64_VER)
1246 printstat64 (tcp, tcp->u_arg[2]);
1247 else
1248#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001249 printstat(tcp, tcp->u_arg[2]);
1250 }
1251 return 0;
1252}
1253
1254int
1255sys_lxstat(tcp)
1256struct tcb *tcp;
1257{
1258 if (entering(tcp)) {
1259 tprintf("%ld, ", tcp->u_arg[0]);
1260 printpath(tcp, tcp->u_arg[1]);
1261 tprintf(", ");
1262 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001263#ifdef _STAT64_VER
1264 if (tcp->u_arg[0] == _STAT64_VER)
1265 printstat64 (tcp, tcp->u_arg[2]);
1266 else
1267#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001268 printstat(tcp, tcp->u_arg[2]);
1269 }
1270 return 0;
1271}
1272
1273int
1274sys_xmknod(tcp)
1275struct tcb *tcp;
1276{
1277 int mode = tcp->u_arg[2];
1278
1279 if (entering(tcp)) {
1280 tprintf("%ld, ", tcp->u_arg[0]);
1281 printpath(tcp, tcp->u_arg[1]);
1282 tprintf(", %s", sprintmode(mode));
1283 switch (mode & S_IFMT) {
1284 case S_IFCHR: case S_IFBLK:
1285#ifdef LINUXSPARC
1286 tprintf(", makedev(%lu, %lu)",
1287 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1288 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001289#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001290 tprintf(", makedev(%lu, %lu)",
1291 (unsigned long) major(tcp->u_arg[3]),
1292 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001293#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001294 break;
1295 default:
1296 break;
1297 }
1298 }
1299 return 0;
1300}
1301
Wichert Akkerman8829a551999-06-11 13:18:40 +00001302#ifdef HAVE_SYS_ACL_H
1303
1304#include <sys/acl.h>
1305
Roland McGrathd9f816f2004-09-04 03:39:20 +00001306const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001307#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001308 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001309#endif
1310#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001311 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001312#endif
1313#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001314 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001315#endif
1316#ifdef ACL_GET
1317 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001318#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001319#ifdef ACL_SET
1320 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001321#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001322#ifdef ACL_CNT
1323 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001324#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001325 { 0, NULL },
1326};
1327
1328int
1329sys_acl(tcp)
1330struct tcb *tcp;
1331{
1332 if (entering(tcp)) {
1333 printpath(tcp, tcp->u_arg[0]);
1334 tprintf(", ");
1335 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1336 tprintf(", %ld", tcp->u_arg[2]);
1337 /*
1338 * FIXME - dump out the list of aclent_t's pointed to
1339 * by "tcp->u_arg[3]" if it's not NULL.
1340 */
1341 if (tcp->u_arg[3])
1342 tprintf(", %#lx", tcp->u_arg[3]);
1343 else
1344 tprintf(", NULL");
1345 }
1346 return 0;
1347}
1348
1349
1350int
1351sys_facl(tcp)
1352struct tcb *tcp;
1353{
1354 if (entering(tcp)) {
1355 tprintf("%ld, ", tcp->u_arg[0]);
1356 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1357 tprintf(", %ld", tcp->u_arg[2]);
1358 /*
1359 * FIXME - dump out the list of aclent_t's pointed to
1360 * by "tcp->u_arg[3]" if it's not NULL.
1361 */
1362 if (tcp->u_arg[3])
1363 tprintf(", %#lx", tcp->u_arg[3]);
1364 else
1365 tprintf(", NULL");
1366 }
1367 return 0;
1368}
1369
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001370
Roland McGrathd9f816f2004-09-04 03:39:20 +00001371const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001372#ifdef IPC_SHM
1373 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001374#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001375#ifdef IPC_SEM
1376 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001377#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001378#ifdef IPC_MSG
1379 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001380#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001381 { 0, NULL },
1382};
1383
1384
1385int
1386sys_aclipc(tcp)
1387struct tcb *tcp;
1388{
1389 if (entering(tcp)) {
1390 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1391 tprintf(", %#lx, ", tcp->u_arg[1]);
1392 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1393 tprintf(", %ld", tcp->u_arg[3]);
1394 /*
1395 * FIXME - dump out the list of aclent_t's pointed to
1396 * by "tcp->u_arg[4]" if it's not NULL.
1397 */
1398 if (tcp->u_arg[4])
1399 tprintf(", %#lx", tcp->u_arg[4]);
1400 else
1401 tprintf(", NULL");
1402 }
1403 return 0;
1404}
1405
1406
1407
Wichert Akkerman8829a551999-06-11 13:18:40 +00001408#endif /* HAVE_SYS_ACL_H */
1409
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001410#endif /* SVR4 || LINUXSPARC */
1411
Michal Ludvig53b320f2002-09-23 13:30:09 +00001412#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413
Roland McGrathd9f816f2004-09-04 03:39:20 +00001414static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001415 { 0x73757245, "CODA_SUPER_MAGIC" },
1416 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1417 { 0x1373, "DEVFS_SUPER_MAGIC" },
1418 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1419 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001420 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1421 { 0xef53, "EXT2_SUPER_MAGIC" },
1422 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001423 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001424 { 0x9660, "ISOFS_SUPER_MAGIC" },
1425 { 0x137f, "MINIX_SUPER_MAGIC" },
1426 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001427 { 0x2468, "MINIX2_SUPER_MAGIC" },
1428 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001429 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001430 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001431 { 0x6969, "NFS_SUPER_MAGIC" },
1432 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001433 { 0x002f, "QNX4_SUPER_MAGIC" },
1434 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1435 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1436 { 0x517b, "SMB_SUPER_MAGIC" },
1437 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1438 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1439 { 0x00011954, "UFS_MAGIC" },
1440 { 0x54190100, "UFS_CIGAM" },
1441 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001442 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001443 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001444 { 0, NULL },
1445};
1446
Michal Ludvig53b320f2002-09-23 13:30:09 +00001447#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001448
1449#ifndef SVR4
1450
Roland McGrathf9c49b22004-10-06 22:11:54 +00001451static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001452sprintfstype(magic)
1453int magic;
1454{
1455 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001456#ifdef LINUX
Roland McGrathf9c49b22004-10-06 22:11:54 +00001457 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001458
1459 s = xlookup(fsmagic, magic);
1460 if (s) {
1461 sprintf(buf, "\"%s\"", s);
1462 return buf;
1463 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001464#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001465 sprintf(buf, "%#x", magic);
1466 return buf;
1467}
1468
1469static void
1470printstatfs(tcp, addr)
1471struct tcb *tcp;
1472long addr;
1473{
1474 struct statfs statbuf;
1475
1476 if (syserror(tcp) || !verbose(tcp)) {
1477 tprintf("%#lx", addr);
1478 return;
1479 }
1480 if (umove(tcp, addr, &statbuf) < 0) {
1481 tprintf("{...}");
1482 return;
1483 }
1484#ifdef ALPHA
1485
1486 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1487 sprintfstype(statbuf.f_type),
1488 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001489 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1490 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1491 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1492 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001493#else /* !ALPHA */
1494 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1495 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001496 (unsigned long)statbuf.f_bsize,
1497 (unsigned long)statbuf.f_blocks,
1498 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001499 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1500 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001501 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001502 (unsigned long)statbuf.f_ffree,
1503 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001504#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001505 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001506#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001507#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001508#ifdef _STATFS_F_FRSIZE
1509 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1510#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001511 tprintf("}");
1512}
1513
1514int
1515sys_statfs(tcp)
1516struct tcb *tcp;
1517{
1518 if (entering(tcp)) {
1519 printpath(tcp, tcp->u_arg[0]);
1520 tprintf(", ");
1521 } else {
1522 printstatfs(tcp, tcp->u_arg[1]);
1523 }
1524 return 0;
1525}
1526
1527int
1528sys_fstatfs(tcp)
1529struct tcb *tcp;
1530{
1531 if (entering(tcp)) {
1532 tprintf("%lu, ", tcp->u_arg[0]);
1533 } else {
1534 printstatfs(tcp, tcp->u_arg[1]);
1535 }
1536 return 0;
1537}
1538
Roland McGrathab147c52003-07-17 09:03:02 +00001539#ifdef LINUX
1540static void
1541printstatfs64(tcp, addr)
1542struct tcb *tcp;
1543long addr;
1544{
1545 struct statfs64 statbuf;
1546
1547 if (syserror(tcp) || !verbose(tcp)) {
1548 tprintf("%#lx", addr);
1549 return;
1550 }
1551 if (umove(tcp, addr, &statbuf) < 0) {
1552 tprintf("{...}");
1553 return;
1554 }
1555#ifdef ALPHA
1556
1557 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1558 sprintfstype(statbuf.f_type),
1559 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1560 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1561 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1562 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1563 statbuf.f_namelen);
1564#else /* !ALPHA */
1565 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1566 sprintfstype(statbuf.f_type),
1567 (unsigned long)statbuf.f_bsize,
1568 (unsigned long)statbuf.f_blocks,
1569 (unsigned long)statbuf.f_bfree);
1570 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1571 (unsigned long)statbuf.f_bavail,
1572 (unsigned long)statbuf.f_files,
1573 (unsigned long)statbuf.f_ffree,
1574 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1575 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1576#endif /* !ALPHA */
1577#ifdef _STATFS_F_FRSIZE
1578 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1579#endif
1580 tprintf("}");
1581}
1582
1583int
1584sys_statfs64(tcp)
1585struct tcb *tcp;
1586{
1587 if (entering(tcp)) {
1588 printpath(tcp, tcp->u_arg[0]);
1589 tprintf(", %lu, ", tcp->u_arg[1]);
1590 } else {
1591 if (tcp->u_arg[1] == sizeof (struct statfs64))
1592 printstatfs64(tcp, tcp->u_arg[2]);
1593 else
1594 tprintf("{???}");
1595 }
1596 return 0;
1597}
1598
1599int
1600sys_fstatfs64(tcp)
1601struct tcb *tcp;
1602{
1603 if (entering(tcp)) {
1604 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1605 } else {
1606 if (tcp->u_arg[1] == sizeof (struct statfs64))
1607 printstatfs64(tcp, tcp->u_arg[2]);
1608 else
1609 tprintf("{???}");
1610 }
1611 return 0;
1612}
1613#endif
1614
Michal Ludvig53b320f2002-09-23 13:30:09 +00001615#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001616
1617int
1618osf_statfs(tcp)
1619struct tcb *tcp;
1620{
1621 if (entering(tcp)) {
1622 printpath(tcp, tcp->u_arg[0]);
1623 tprintf(", ");
1624 } else {
1625 printstatfs(tcp, tcp->u_arg[1]);
1626 tprintf(", %lu", tcp->u_arg[2]);
1627 }
1628 return 0;
1629}
1630
1631int
1632osf_fstatfs(tcp)
1633struct tcb *tcp;
1634{
1635 if (entering(tcp)) {
1636 tprintf("%lu, ", tcp->u_arg[0]);
1637 } else {
1638 printstatfs(tcp, tcp->u_arg[1]);
1639 tprintf(", %lu", tcp->u_arg[2]);
1640 }
1641 return 0;
1642}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001643#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001644
1645#endif /* !SVR4 */
1646
1647#ifdef SUNOS4
1648
1649int
1650sys_ustat(tcp)
1651struct tcb *tcp;
1652{
1653 struct ustat statbuf;
1654
1655 if (entering(tcp)) {
1656 tprintf("makedev(%lu, %lu), ",
1657 (long) major(tcp->u_arg[0]),
1658 (long) minor(tcp->u_arg[0]));
1659 }
1660 else {
1661 if (syserror(tcp) || !verbose(tcp))
1662 tprintf("%#lx", tcp->u_arg[1]);
1663 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1664 tprintf("{...}");
1665 else {
1666 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1667 statbuf.f_tfree, statbuf.f_tinode);
1668 tprintf("f_fname=\"%.*s\", ",
1669 (int) sizeof(statbuf.f_fname),
1670 statbuf.f_fname);
1671 tprintf("f_fpack=\"%.*s\"}",
1672 (int) sizeof(statbuf.f_fpack),
1673 statbuf.f_fpack);
1674 }
1675 }
1676 return 0;
1677}
1678
1679#endif /* SUNOS4 */
1680
Wichert Akkermanc7926982000-04-10 22:22:31 +00001681int
1682sys_pivotroot(tcp)
1683struct tcb *tcp;
1684{
1685 if (entering(tcp)) {
1686 printpath(tcp, tcp->u_arg[0]);
1687 tprintf(", ");
1688 printpath(tcp, tcp->u_arg[1]);
1689 }
1690 return 0;
1691}
1692
1693
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001694/* directory */
1695int
1696sys_chdir(tcp)
1697struct tcb *tcp;
1698{
1699 if (entering(tcp)) {
1700 printpath(tcp, tcp->u_arg[0]);
1701 }
1702 return 0;
1703}
1704
1705int
1706sys_mkdir(tcp)
1707struct tcb *tcp;
1708{
1709 if (entering(tcp)) {
1710 printpath(tcp, tcp->u_arg[0]);
1711 tprintf(", %#lo", tcp->u_arg[1]);
1712 }
1713 return 0;
1714}
1715
1716int
1717sys_rmdir(tcp)
1718struct tcb *tcp;
1719{
1720 if (entering(tcp)) {
1721 printpath(tcp, tcp->u_arg[0]);
1722 }
1723 return 0;
1724}
1725
1726int
1727sys_fchdir(tcp)
1728struct tcb *tcp;
1729{
1730 if (entering(tcp)) {
1731 tprintf("%ld", tcp->u_arg[0]);
1732 }
1733 return 0;
1734}
1735
1736int
1737sys_chroot(tcp)
1738struct tcb *tcp;
1739{
1740 if (entering(tcp)) {
1741 printpath(tcp, tcp->u_arg[0]);
1742 }
1743 return 0;
1744}
1745
1746int
1747sys_fchroot(tcp)
1748struct tcb *tcp;
1749{
1750 if (entering(tcp)) {
1751 tprintf("%ld", tcp->u_arg[0]);
1752 }
1753 return 0;
1754}
1755
1756int
1757sys_link(tcp)
1758struct tcb *tcp;
1759{
1760 if (entering(tcp)) {
1761 printpath(tcp, tcp->u_arg[0]);
1762 tprintf(", ");
1763 printpath(tcp, tcp->u_arg[1]);
1764 }
1765 return 0;
1766}
1767
1768int
1769sys_unlink(tcp)
1770struct tcb *tcp;
1771{
1772 if (entering(tcp)) {
1773 printpath(tcp, tcp->u_arg[0]);
1774 }
1775 return 0;
1776}
1777
1778int
1779sys_symlink(tcp)
1780struct tcb *tcp;
1781{
1782 if (entering(tcp)) {
1783 printpath(tcp, tcp->u_arg[0]);
1784 tprintf(", ");
1785 printpath(tcp, tcp->u_arg[1]);
1786 }
1787 return 0;
1788}
1789
1790int
1791sys_readlink(tcp)
1792struct tcb *tcp;
1793{
1794 if (entering(tcp)) {
1795 printpath(tcp, tcp->u_arg[0]);
1796 tprintf(", ");
1797 } else {
1798 if (syserror(tcp))
1799 tprintf("%#lx", tcp->u_arg[1]);
1800 else
1801 printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
1802 tprintf(", %lu", tcp->u_arg[2]);
1803 }
1804 return 0;
1805}
1806
1807int
1808sys_rename(tcp)
1809struct tcb *tcp;
1810{
1811 if (entering(tcp)) {
1812 printpath(tcp, tcp->u_arg[0]);
1813 tprintf(", ");
1814 printpath(tcp, tcp->u_arg[1]);
1815 }
1816 return 0;
1817}
1818
1819int
1820sys_chown(tcp)
1821struct tcb *tcp;
1822{
1823 if (entering(tcp)) {
1824 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001825 printuid(", ", tcp->u_arg[1]);
1826 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001827 }
1828 return 0;
1829}
1830
1831int
1832sys_fchown(tcp)
1833struct tcb *tcp;
1834{
1835 if (entering(tcp)) {
Roland McGrath6bc12202003-11-13 22:32:27 +00001836 tprintf("%ld", tcp->u_arg[0]);
1837 printuid(", ", tcp->u_arg[1]);
1838 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001839 }
1840 return 0;
1841}
1842
1843int
1844sys_chmod(tcp)
1845struct tcb *tcp;
1846{
1847 if (entering(tcp)) {
1848 printpath(tcp, tcp->u_arg[0]);
1849 tprintf(", %#lo", tcp->u_arg[1]);
1850 }
1851 return 0;
1852}
1853
1854int
1855sys_fchmod(tcp)
1856struct tcb *tcp;
1857{
1858 if (entering(tcp)) {
1859 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
1860 }
1861 return 0;
1862}
1863
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001864#ifdef ALPHA
1865int
1866sys_osf_utimes(tcp)
1867struct tcb *tcp;
1868{
1869 if (entering(tcp)) {
1870 printpath(tcp, tcp->u_arg[0]);
1871 tprintf(", ");
1872 printtv32(tcp, tcp->u_arg[1]);
1873 }
1874 return 0;
1875}
1876#endif
1877
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001878int
1879sys_utimes(tcp)
1880struct tcb *tcp;
1881{
1882 if (entering(tcp)) {
1883 printpath(tcp, tcp->u_arg[0]);
1884 tprintf(", ");
1885 printtv(tcp, tcp->u_arg[1]);
1886 }
1887 return 0;
1888}
1889
1890int
1891sys_utime(tcp)
1892struct tcb *tcp;
1893{
1894 long ut[2];
1895
1896 if (entering(tcp)) {
1897 printpath(tcp, tcp->u_arg[0]);
1898 tprintf(", ");
1899 if (!tcp->u_arg[1])
1900 tprintf("NULL");
1901 else if (!verbose(tcp))
1902 tprintf("%#lx", tcp->u_arg[1]);
1903 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
1904 (char *) ut) < 0)
1905 tprintf("[?, ?]");
1906 else {
1907 tprintf("[%s,", sprinttime(ut[0]));
1908 tprintf(" %s]", sprinttime(ut[1]));
1909 }
1910 }
1911 return 0;
1912}
1913
1914int
1915sys_mknod(tcp)
1916struct tcb *tcp;
1917{
1918 int mode = tcp->u_arg[1];
1919
1920 if (entering(tcp)) {
1921 printpath(tcp, tcp->u_arg[0]);
1922 tprintf(", %s", sprintmode(mode));
1923 switch (mode & S_IFMT) {
1924 case S_IFCHR: case S_IFBLK:
1925#ifdef LINUXSPARC
1926 if (current_personality == 1)
1927 tprintf(", makedev(%lu, %lu)",
1928 (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
1929 (unsigned long) (tcp->u_arg[2] & 0x3ffff));
1930 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00001931#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001932 tprintf(", makedev(%lu, %lu)",
1933 (unsigned long) major(tcp->u_arg[2]),
1934 (unsigned long) minor(tcp->u_arg[2]));
1935 break;
1936 default:
1937 break;
1938 }
1939 }
1940 return 0;
1941}
1942
1943int
1944sys_mkfifo(tcp)
1945struct tcb *tcp;
1946{
1947 if (entering(tcp)) {
1948 printpath(tcp, tcp->u_arg[0]);
1949 tprintf(", %#lo", tcp->u_arg[1]);
1950 }
1951 return 0;
1952}
1953
1954int
1955sys_fsync(tcp)
1956struct tcb *tcp;
1957{
1958 if (entering(tcp)) {
1959 tprintf("%ld", tcp->u_arg[0]);
1960 }
1961 return 0;
1962}
1963
Michal Ludvig53b320f2002-09-23 13:30:09 +00001964#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001965
1966static void
1967printdir(tcp, addr)
1968struct tcb *tcp;
1969long addr;
1970{
1971 struct dirent d;
1972
1973 if (!verbose(tcp)) {
1974 tprintf("%#lx", addr);
1975 return;
1976 }
1977 if (umove(tcp, addr, &d) < 0) {
1978 tprintf("{...}");
1979 return;
1980 }
1981 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001982 tprintf("d_name=");
1983 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
1984 tprintf("}");
1985}
1986
1987int
1988sys_readdir(tcp)
1989struct tcb *tcp;
1990{
1991 if (entering(tcp)) {
1992 tprintf("%lu, ", tcp->u_arg[0]);
1993 } else {
1994 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
1995 tprintf("%#lx", tcp->u_arg[1]);
1996 else
1997 printdir(tcp, tcp->u_arg[1]);
1998 /* Not much point in printing this out, it is always 1. */
1999 if (tcp->u_arg[2] != 1)
2000 tprintf(", %lu", tcp->u_arg[2]);
2001 }
2002 return 0;
2003}
2004
Michal Ludvig53b320f2002-09-23 13:30:09 +00002005#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002006
Roland McGrath40542842004-01-13 09:47:49 +00002007#if defined FREEBSD || defined LINUX
Roland McGrathd9f816f2004-09-04 03:39:20 +00002008const struct xlat direnttypes[] = {
Roland McGrath40542842004-01-13 09:47:49 +00002009 { DT_UNKNOWN, "DT_UNKNOWN" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002010 { DT_FIFO, "DT_FIFO" },
2011 { DT_CHR, "DT_CHR" },
2012 { DT_DIR, "DT_DIR" },
2013 { DT_BLK, "DT_BLK" },
2014 { DT_REG, "DT_REG" },
2015 { DT_LNK, "DT_LNK" },
2016 { DT_SOCK, "DT_SOCK" },
2017 { DT_WHT, "DT_WHT" },
2018 { 0, NULL },
2019};
2020
2021#endif
2022
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002023int
2024sys_getdents(tcp)
2025struct tcb *tcp;
2026{
2027 int i, len, dents = 0;
2028 char *buf;
2029
2030 if (entering(tcp)) {
2031 tprintf("%lu, ", tcp->u_arg[0]);
2032 return 0;
2033 }
2034 if (syserror(tcp) || !verbose(tcp)) {
2035 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2036 return 0;
2037 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002038 len = tcp->u_rval;
2039 if ((buf = malloc(len)) == NULL) {
2040 tprintf("out of memory\n");
2041 return 0;
2042 }
2043 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2044 tprintf("{...}, %lu", tcp->u_arg[2]);
2045 free(buf);
2046 return 0;
2047 }
2048 if (!abbrev(tcp))
2049 tprintf("{");
2050 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002051 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002052#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002053 if (!abbrev(tcp)) {
2054 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2055 i ? " " : "", d->d_ino, d->d_off);
2056 tprintf("d_reclen=%u, d_name=\"%s\"}",
2057 d->d_reclen, d->d_name);
2058 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002059#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002060#ifdef SVR4
2061 if (!abbrev(tcp)) {
2062 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002063 i ? " " : "",
2064 (unsigned long) d->d_ino,
2065 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002066 tprintf("d_reclen=%u, d_name=\"%s\"}",
2067 d->d_reclen, d->d_name);
2068 }
2069#endif /* SVR4 */
2070#ifdef SUNOS4
2071 if (!abbrev(tcp)) {
2072 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2073 i ? " " : "", d->d_off, d->d_fileno,
2074 d->d_reclen);
2075 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2076 d->d_namlen, d->d_namlen, d->d_name);
2077 }
2078#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002079#ifdef FREEBSD
2080 if (!abbrev(tcp)) {
2081 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2082 i ? " " : "", d->d_fileno, d->d_reclen);
2083 printxval(direnttypes, d->d_type, "DT_???");
2084 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2085 d->d_namlen, d->d_namlen, d->d_name);
2086 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002087#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002088 if (!d->d_reclen) {
2089 tprintf("/* d_reclen == 0, problem here */");
2090 break;
2091 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002092 i += d->d_reclen;
2093 dents++;
2094 }
2095 if (!abbrev(tcp))
2096 tprintf("}");
2097 else
2098 tprintf("/* %u entries */", dents);
2099 tprintf(", %lu", tcp->u_arg[2]);
2100 free(buf);
2101 return 0;
2102}
2103
John Hughesbdf48f52001-03-06 15:08:09 +00002104
2105#if _LFS64_LARGEFILE
2106int
2107sys_getdents64(tcp)
2108struct tcb *tcp;
2109{
2110 int i, len, dents = 0;
2111 char *buf;
2112
2113 if (entering(tcp)) {
2114 tprintf("%lu, ", tcp->u_arg[0]);
2115 return 0;
2116 }
2117 if (syserror(tcp) || !verbose(tcp)) {
2118 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2119 return 0;
2120 }
2121 len = tcp->u_rval;
2122 if ((buf = malloc(len)) == NULL) {
2123 tprintf("out of memory\n");
2124 return 0;
2125 }
2126 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2127 tprintf("{...}, %lu", tcp->u_arg[2]);
2128 free(buf);
2129 return 0;
2130 }
2131 if (!abbrev(tcp))
2132 tprintf("{");
2133 for (i = 0; i < len;) {
2134 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002135#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002136 if (!abbrev(tcp)) {
Roland McGrath92053242004-01-13 10:16:47 +00002137 tprintf("%s{d_ino=%llu, d_off=%llu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002138 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002139 d->d_ino,
2140 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002141#ifdef LINUX
2142 tprintf("d_type=");
2143 printxval(direnttypes, d->d_type, "DT_???");
2144 tprintf(", ");
2145#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002146 tprintf("d_reclen=%u, d_name=\"%s\"}",
2147 d->d_reclen, d->d_name);
2148 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002149#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002150#ifdef SUNOS4
2151 if (!abbrev(tcp)) {
2152 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2153 i ? " " : "", d->d_off, d->d_fileno,
2154 d->d_reclen);
2155 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2156 d->d_namlen, d->d_namlen, d->d_name);
2157 }
2158#endif /* SUNOS4 */
2159 i += d->d_reclen;
2160 dents++;
2161 }
2162 if (!abbrev(tcp))
2163 tprintf("}");
2164 else
2165 tprintf("/* %u entries */", dents);
2166 tprintf(", %lu", tcp->u_arg[2]);
2167 free(buf);
2168 return 0;
2169}
2170#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002171
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002172#ifdef FREEBSD
2173int
2174sys_getdirentries(tcp)
2175struct tcb * tcp;
2176{
2177 int i, len, dents = 0;
2178 long basep;
2179 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002180
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002181 if (entering(tcp)) {
2182 tprintf("%lu, ", tcp->u_arg[0]);
2183 return 0;
2184 }
2185 if (syserror(tcp) || !verbose(tcp)) {
2186 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2187 return 0;
2188 }
2189 len = tcp->u_rval;
2190 if ((buf = malloc(len)) == NULL) {
2191 tprintf("out of memory\n");
2192 return 0;
2193 }
2194 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2195 tprintf("{...}, %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3]);
2196 free(buf);
2197 return 0;
2198 }
2199 if (!abbrev(tcp))
2200 tprintf("{");
2201 for (i = 0; i < len;) {
2202 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2203 if (!abbrev(tcp)) {
2204 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2205 i ? " " : "", d->d_fileno, d->d_reclen);
2206 printxval(direnttypes, d->d_type, "DT_???");
2207 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2208 d->d_namlen, d->d_namlen, d->d_name);
2209 }
2210 i += d->d_reclen;
2211 dents++;
2212 }
2213 if (!abbrev(tcp))
2214 tprintf("}");
2215 else
2216 tprintf("/* %u entries */", dents);
2217 free(buf);
2218 tprintf(", %lu", tcp->u_arg[2]);
2219 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2220 tprintf(", %#lx", tcp->u_arg[3]);
2221 else
2222 tprintf(", [%lu]", basep);
2223 return 0;
2224}
2225#endif
2226
Michal Ludvig53b320f2002-09-23 13:30:09 +00002227#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002228int
2229sys_getcwd(tcp)
2230struct tcb *tcp;
2231{
2232 if (exiting(tcp)) {
2233 if (syserror(tcp))
2234 tprintf("%#lx", tcp->u_arg[0]);
2235 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002236 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002237 tprintf(", %lu", tcp->u_arg[1]);
2238 }
2239 return 0;
2240}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002241#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002242
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002243#ifdef FREEBSD
2244int
2245sys___getcwd(tcp)
2246struct tcb *tcp;
2247{
2248 if (exiting(tcp)) {
2249 if (syserror(tcp))
2250 tprintf("%#lx", tcp->u_arg[0]);
2251 else
2252 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2253 tprintf(", %lu", tcp->u_arg[1]);
2254 }
2255 return 0;
2256}
2257#endif
2258
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002259#ifdef HAVE_SYS_ASYNCH_H
2260
2261int
2262sys_aioread(tcp)
2263struct tcb *tcp;
2264{
2265 struct aio_result_t res;
2266
2267 if (entering(tcp)) {
2268 tprintf("%lu, ", tcp->u_arg[0]);
2269 } else {
2270 if (syserror(tcp))
2271 tprintf("%#lx", tcp->u_arg[1]);
2272 else
2273 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2274 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2275 printxval(whence, tcp->u_arg[4], "L_???");
2276 if (syserror(tcp) || tcp->u_arg[5] == 0
2277 || umove(tcp, tcp->u_arg[5], &res) < 0)
2278 tprintf(", %#lx", tcp->u_arg[5]);
2279 else
2280 tprintf(", {aio_return %d aio_errno %d}",
2281 res.aio_return, res.aio_errno);
2282 }
2283 return 0;
2284}
2285
2286int
2287sys_aiowrite(tcp)
2288struct tcb *tcp;
2289{
2290 struct aio_result_t res;
2291
2292 if (entering(tcp)) {
2293 tprintf("%lu, ", tcp->u_arg[0]);
2294 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2295 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2296 printxval(whence, tcp->u_arg[4], "L_???");
2297 }
2298 else {
2299 if (tcp->u_arg[5] == 0)
2300 tprintf(", NULL");
2301 else if (syserror(tcp)
2302 || umove(tcp, tcp->u_arg[5], &res) < 0)
2303 tprintf(", %#lx", tcp->u_arg[5]);
2304 else
2305 tprintf(", {aio_return %d aio_errno %d}",
2306 res.aio_return, res.aio_errno);
2307 }
2308 return 0;
2309}
2310
2311int
2312sys_aiowait(tcp)
2313struct tcb *tcp;
2314{
2315 if (entering(tcp))
2316 printtv(tcp, tcp->u_arg[0]);
2317 return 0;
2318}
2319
2320int
2321sys_aiocancel(tcp)
2322struct tcb *tcp;
2323{
2324 struct aio_result_t res;
2325
2326 if (exiting(tcp)) {
2327 if (tcp->u_arg[0] == 0)
2328 tprintf("NULL");
2329 else if (syserror(tcp)
2330 || umove(tcp, tcp->u_arg[0], &res) < 0)
2331 tprintf("%#lx", tcp->u_arg[0]);
2332 else
2333 tprintf("{aio_return %d aio_errno %d}",
2334 res.aio_return, res.aio_errno);
2335 }
2336 return 0;
2337}
2338
2339#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002340
Roland McGrathd9f816f2004-09-04 03:39:20 +00002341const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002342#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002343 { XATTR_CREATE, "XATTR_CREATE" },
2344 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002345#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002346 { 0, NULL }
2347};
2348
Roland McGrath3292e222004-08-31 06:30:48 +00002349static void
2350print_xattr_val(tcp, failed, arg, insize, size)
2351struct tcb *tcp;
2352int failed;
2353unsigned long arg;
Roland McGrath883567c2005-02-02 03:38:32 +00002354long insize, size;
Roland McGrath3292e222004-08-31 06:30:48 +00002355{
Roland McGrath883567c2005-02-02 03:38:32 +00002356 if (!failed) {
2357 unsigned char *buf = malloc(4 * size + 1);
2358 if (buf == NULL || /* probably a bogus size argument */
2359 umoven(tcp, arg, size, &buf[3 * size]) < 0) {
2360 failed = 1;
2361 }
2362 else {
2363 unsigned char *out = buf;
2364 unsigned char *in = &buf[3 * size];
2365 size_t i;
2366 for (i = 0; i < size; ++i)
2367 if (isprint(in[i]))
2368 *out++ = in[i];
2369 else {
Roland McGrath3292e222004-08-31 06:30:48 +00002370#define tohex(n) "0123456789abcdef"[n]
Roland McGrath883567c2005-02-02 03:38:32 +00002371 *out++ = '\\';
2372 *out++ = 'x';
2373 *out++ = tohex(in[i] / 16);
2374 *out++ = tohex(in[i] % 16);
2375 }
2376 /* Don't print terminating NUL if there is one. */
2377 if (in[i - 1] == '\0')
2378 out -= 4;
2379 *out = '\0';
2380 tprintf(", \"%s\", %ld", buf, insize);
2381 }
2382 free(buf);
2383 }
2384 if (failed)
2385 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002386}
2387
Roland McGrath186c5ac2002-12-15 23:58:23 +00002388int
2389sys_setxattr(tcp)
2390struct tcb *tcp;
2391{
2392 if (entering(tcp)) {
2393 printpath(tcp, tcp->u_arg[0]);
2394 tprintf(", ");
2395 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002396 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2397 tprintf(", ");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002398 printflags(xattrflags, tcp->u_arg[4]);
2399 }
2400 return 0;
2401}
2402
2403int
2404sys_fsetxattr(tcp)
2405struct tcb *tcp;
2406{
2407 if (entering(tcp)) {
2408 tprintf("%ld, ", tcp->u_arg[0]);
2409 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002410 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2411 tprintf(", ");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002412 printflags(xattrflags, tcp->u_arg[4]);
2413 }
2414 return 0;
2415}
2416
2417int
2418sys_getxattr(tcp)
2419struct tcb *tcp;
2420{
2421 if (entering(tcp)) {
2422 printpath(tcp, tcp->u_arg[0]);
2423 tprintf(", ");
2424 printstr(tcp, tcp->u_arg[1], -1);
2425 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002426 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2427 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002428 }
2429 return 0;
2430}
2431
2432int
2433sys_fgetxattr(tcp)
2434struct tcb *tcp;
2435{
2436 if (entering(tcp)) {
2437 tprintf("%ld, ", tcp->u_arg[0]);
2438 printstr(tcp, tcp->u_arg[1], -1);
2439 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002440 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2441 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002442 }
2443 return 0;
2444}
2445
2446int
2447sys_listxattr(tcp)
2448struct tcb *tcp;
2449{
2450 if (entering(tcp)) {
2451 printpath(tcp, tcp->u_arg[0]);
2452 } else {
2453 /* XXX Print value in format */
2454 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2455 }
2456 return 0;
2457}
2458
2459int
2460sys_flistxattr(tcp)
2461struct tcb *tcp;
2462{
2463 if (entering(tcp)) {
2464 tprintf("%ld", tcp->u_arg[0]);
2465 } else {
2466 /* XXX Print value in format */
2467 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2468 }
2469 return 0;
2470}
2471
2472int
2473sys_removexattr(tcp)
2474struct tcb *tcp;
2475{
2476 if (entering(tcp)) {
2477 printpath(tcp, tcp->u_arg[0]);
2478 tprintf(", ");
2479 printstr(tcp, tcp->u_arg[1], -1);
2480 }
2481 return 0;
2482}
2483
2484int
2485sys_fremovexattr(tcp)
2486struct tcb *tcp;
2487{
2488 if (entering(tcp)) {
2489 tprintf("%ld, ", tcp->u_arg[0]);
2490 printstr(tcp, tcp->u_arg[1], -1);
2491 }
2492 return 0;
2493}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002494
2495
2496static const struct xlat advise[] = {
2497 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2498 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2499 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2500 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2501 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2502 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2503 { 0, NULL }
2504};
2505
2506
Roland McGrathe27ed342004-10-20 02:24:19 +00002507#ifdef LINUX
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002508int
2509sys_fadvise64(tcp)
2510struct tcb *tcp;
2511{
2512 if (entering(tcp)) {
2513 tprintf("%ld, %lld, %ld, ",
2514 tcp->u_arg[0],
2515# if defined IA64 || defined X86_64 || defined ALPHA
2516 (long long int) tcp->u_arg[1], tcp->u_arg[2]);
2517 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2518#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002519 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
2520 printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002521#endif
2522 }
2523 return 0;
2524}
2525#endif
2526
2527
2528int
2529sys_fadvise64_64(tcp)
2530struct tcb *tcp;
2531{
2532 if (entering(tcp)) {
2533 tprintf("%ld, %lld, %lld, ",
2534 tcp->u_arg[0],
2535# if defined IA64 || defined X86_64 || defined ALPHA
2536 (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
2537 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2538#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002539 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
2540 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002541 printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
2542#endif
2543 }
2544 return 0;
2545}