blob: c8f7b87812ac84a358b7b883dfb63ae553c8f2b3 [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
Roland McGrath663a8a02005-02-04 09:49:56 +0000248# ifdef O_LARGEFILE
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000249 { O_LARGEFILE, "O_LARGEFILE" },
Roland McGrath663a8a02005-02-04 09:49:56 +0000250# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000251#endif
252#ifdef O_DIRECTORY
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000253 { O_DIRECTORY, "O_DIRECTORY" },
254#endif
255#ifdef O_NOFOLLOW
256 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000257#endif
258
259#ifdef FNDELAY
260 { FNDELAY, "FNDELAY" },
261#endif
262#ifdef FAPPEND
263 { FAPPEND, "FAPPEND" },
264#endif
265#ifdef FMARK
266 { FMARK, "FMARK" },
267#endif
268#ifdef FDEFER
269 { FDEFER, "FDEFER" },
270#endif
271#ifdef FASYNC
272 { FASYNC, "FASYNC" },
273#endif
274#ifdef FSHLOCK
275 { FSHLOCK, "FSHLOCK" },
276#endif
277#ifdef FEXLOCK
278 { FEXLOCK, "FEXLOCK" },
279#endif
280#ifdef FCREAT
281 { FCREAT, "FCREAT" },
282#endif
283#ifdef FTRUNC
284 { FTRUNC, "FTRUNC" },
285#endif
286#ifdef FEXCL
287 { FEXCL, "FEXCL" },
288#endif
289#ifdef FNBIO
290 { FNBIO, "FNBIO" },
291#endif
292#ifdef FSYNC
293 { FSYNC, "FSYNC" },
294#endif
295#ifdef FNOCTTY
296 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000297#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000298#ifdef O_SHLOCK
299 { O_SHLOCK, "O_SHLOCK" },
300#endif
301#ifdef O_EXLOCK
302 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000303#endif
304 { 0, NULL },
305};
306
307int
308sys_open(tcp)
309struct tcb *tcp;
310{
311 if (entering(tcp)) {
312 printpath(tcp, tcp->u_arg[0]);
313 tprintf(", ");
314 /* flags */
315 printflags(openmodes, tcp->u_arg[1] + 1);
316 if (tcp->u_arg[1] & O_CREAT) {
317 /* mode */
318 tprintf(", %#lo", tcp->u_arg[2]);
319 }
320 }
321 return 0;
322}
323
324#ifdef LINUXSPARC
Roland McGrathd9f816f2004-09-04 03:39:20 +0000325const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000326 { 0, "O_RDWR" },
327 { 1, "O_RDONLY" },
328 { 2, "O_WRONLY" },
329 { 0x80, "O_NONBLOCK" },
330 { 8, "O_APPEND" },
331 { 0x100, "O_CREAT" },
332 { 0x200, "O_TRUNC" },
333 { 0x400, "O_EXCL" },
334 { 0x800, "O_NOCTTY" },
335 { 0x10, "O_SYNC" },
336 { 0x40, "O_DSYNC" },
337 { 0x8000, "O_RSYNC" },
338 { 4, "O_NDELAY" },
339 { 0x1000, "O_PRIV" },
340 { 0, NULL },
341};
342
343int
344solaris_open(tcp)
345struct tcb *tcp;
346{
347 if (entering(tcp)) {
348 printpath(tcp, tcp->u_arg[0]);
349 tprintf(", ");
350 /* flags */
351 printflags(openmodessol, tcp->u_arg[1] + 1);
352 if (tcp->u_arg[1] & 0x100) {
353 /* mode */
354 tprintf(", %#lo", tcp->u_arg[2]);
355 }
356 }
357 return 0;
358}
359
360#endif
361
362int
363sys_creat(tcp)
364struct tcb *tcp;
365{
366 if (entering(tcp)) {
367 printpath(tcp, tcp->u_arg[0]);
368 tprintf(", %#lo", tcp->u_arg[1]);
369 }
370 return 0;
371}
372
Roland McGrathd9f816f2004-09-04 03:39:20 +0000373static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000374 { F_OK, "F_OK", },
375 { R_OK, "R_OK" },
376 { W_OK, "W_OK" },
377 { X_OK, "X_OK" },
378#ifdef EFF_ONLY_OK
379 { EFF_ONLY_OK, "EFF_ONLY_OK" },
380#endif
381#ifdef EX_OK
382 { EX_OK, "EX_OK" },
383#endif
384 { 0, NULL },
385};
386
387int
388sys_access(tcp)
389struct tcb *tcp;
390{
391 if (entering(tcp)) {
392 printpath(tcp, tcp->u_arg[0]);
393 tprintf(", ");
394 printflags(access_flags, tcp->u_arg[1]);
395 }
396 return 0;
397}
398
399int
400sys_umask(tcp)
401struct tcb *tcp;
402{
403 if (entering(tcp)) {
404 tprintf("%#lo", tcp->u_arg[0]);
405 }
406 return RVAL_OCTAL;
407}
408
Roland McGrathd9f816f2004-09-04 03:39:20 +0000409static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000410 { SEEK_SET, "SEEK_SET" },
411 { SEEK_CUR, "SEEK_CUR" },
412 { SEEK_END, "SEEK_END" },
413 { 0, NULL },
414};
415
John Hughes70623be2001-03-08 13:59:00 +0000416#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000417int
418sys_lseek(tcp)
419struct tcb *tcp;
420{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000421 off_t offset;
422 int _whence;
423
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000424 if (entering(tcp)) {
425 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000426 offset = tcp->u_arg[1];
427 _whence = tcp->u_arg[2];
428 if (_whence == SEEK_SET)
429 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000430 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000431 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000432 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000433 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000434 return RVAL_UDECIMAL;
435}
John Hughes5a826b82001-03-07 13:21:24 +0000436#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000437
Michal Ludvig53b320f2002-09-23 13:30:09 +0000438#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000439int
440sys_llseek (tcp)
441struct tcb *tcp;
442{
443 if (entering(tcp)) {
Roland McGrath8c304bc2004-10-19 22:59:55 +0000444 /*
445 * This one call takes explicitly two 32-bit arguments hi, lo,
446 * rather than one 64-bit argument for which LONG_LONG works
447 * appropriate for the native byte order.
448 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000449 if (tcp->u_arg[4] == SEEK_SET)
450 tprintf("%ld, %llu, ", tcp->u_arg[0],
Roland McGrath8c304bc2004-10-19 22:59:55 +0000451 (((long long int) tcp->u_arg[1]) << 32
452 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000453 else
454 tprintf("%ld, %lld, ", tcp->u_arg[0],
Roland McGrath8c304bc2004-10-19 22:59:55 +0000455 (((long long int) tcp->u_arg[1]) << 32
456 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000457 }
458 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000459 long long int off;
460 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000461 tprintf("%#lx, ", tcp->u_arg[3]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000462 else
463 tprintf("[%llu], ", off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000464 printxval(whence, tcp->u_arg[4], "SEEK_???");
465 }
466 return 0;
467}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000468
469int
470sys_readahead (tcp)
471struct tcb *tcp;
472{
473 if (entering(tcp)) {
474 tprintf("%ld, %lld, %ld", tcp->u_arg[0],
475# if defined IA64 || defined X86_64 || defined ALPHA
476 (long long int) tcp->u_arg[1], tcp->u_arg[2]
477# else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +0000478 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]
Roland McGrath186c5ac2002-12-15 23:58:23 +0000479# endif
480 );
481 }
482 return 0;
483}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000484#endif
485
John Hughes70623be2001-03-08 13:59:00 +0000486#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000487int
488sys_lseek64 (tcp)
489struct tcb *tcp;
490{
491 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000492 long long offset;
493 ALIGN64 (tcp, 1); /* FreeBSD aligns off_t args */
John Hughes0c79e012001-03-08 14:40:06 +0000494 offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +0000495 if (tcp->u_arg[3] == SEEK_SET)
496 tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
497 else
498 tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
499 printxval(whence, tcp->u_arg[3], "SEEK_???");
500 }
501 return RVAL_LUDECIMAL;
502}
503#endif
504
John Hughes70623be2001-03-08 13:59:00 +0000505#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000506int
507sys_truncate(tcp)
508struct tcb *tcp;
509{
510 if (entering(tcp)) {
511 printpath(tcp, tcp->u_arg[0]);
512 tprintf(", %lu", tcp->u_arg[1]);
513 }
514 return 0;
515}
John Hughes5a826b82001-03-07 13:21:24 +0000516#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517
John Hughes70623be2001-03-08 13:59:00 +0000518#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000519int
520sys_truncate64(tcp)
521struct tcb *tcp;
522{
523 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000524 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000525 printpath(tcp, tcp->u_arg[0]);
John Hughes0c79e012001-03-08 14:40:06 +0000526 tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000527 }
528 return 0;
529}
530#endif
531
John Hughes70623be2001-03-08 13:59:00 +0000532#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000533int
534sys_ftruncate(tcp)
535struct tcb *tcp;
536{
537 if (entering(tcp)) {
538 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
539 }
540 return 0;
541}
John Hughes5a826b82001-03-07 13:21:24 +0000542#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000543
John Hughes70623be2001-03-08 13:59:00 +0000544#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000545int
546sys_ftruncate64(tcp)
547struct tcb *tcp;
548{
549 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000550 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000551 tprintf("%ld, %llu", tcp->u_arg[0],
John Hughes0c79e012001-03-08 14:40:06 +0000552 LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000553 }
554 return 0;
555}
556#endif
557
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558/* several stats */
559
Roland McGrathd9f816f2004-09-04 03:39:20 +0000560static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000561 { S_IFREG, "S_IFREG" },
562 { S_IFSOCK, "S_IFSOCK" },
563 { S_IFIFO, "S_IFIFO" },
564 { S_IFLNK, "S_IFLNK" },
565 { S_IFDIR, "S_IFDIR" },
566 { S_IFBLK, "S_IFBLK" },
567 { S_IFCHR, "S_IFCHR" },
568 { 0, NULL },
569};
570
Roland McGrathf9c49b22004-10-06 22:11:54 +0000571static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000572sprintmode(mode)
573int mode;
574{
575 static char buf[64];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000576 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000577
578 if ((mode & S_IFMT) == 0)
579 s = "";
580 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
581 sprintf(buf, "%#o", mode);
582 return buf;
583 }
584 sprintf(buf, "%s%s%s%s", s,
585 (mode & S_ISUID) ? "|S_ISUID" : "",
586 (mode & S_ISGID) ? "|S_ISGID" : "",
587 (mode & S_ISVTX) ? "|S_ISVTX" : "");
588 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
589 if (mode)
590 sprintf(buf + strlen(buf), "|%#o", mode);
591 s = (*buf == '|') ? buf + 1 : buf;
592 return *s ? s : "0";
593}
594
595static char *
596sprinttime(t)
597time_t t;
598{
599 struct tm *tmp;
600 static char buf[32];
601
602 if (t == 0) {
603 sprintf(buf, "0");
604 return buf;
605 }
606 tmp = localtime(&t);
607 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
Wichert Akkerman3ed6dc22000-01-11 14:41:09 +0000608 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000609 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
610 return buf;
611}
612
613#ifdef LINUXSPARC
614typedef struct {
615 int tv_sec;
616 int tv_nsec;
617} timestruct_t;
618
619struct solstat {
620 unsigned st_dev;
621 int st_pad1[3]; /* network id */
622 unsigned st_ino;
623 unsigned st_mode;
624 unsigned st_nlink;
625 unsigned st_uid;
626 unsigned st_gid;
627 unsigned st_rdev;
628 int st_pad2[2];
629 int st_size;
630 int st_pad3; /* st_size, off_t expansion */
631 timestruct_t st_atime;
632 timestruct_t st_mtime;
633 timestruct_t st_ctime;
634 int st_blksize;
635 int st_blocks;
636 char st_fstype[16];
637 int st_pad4[8]; /* expansion area */
638};
639
640static void
641printstatsol(tcp, addr)
642struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000643long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000644{
645 struct solstat statbuf;
646
647 if (!addr) {
648 tprintf("NULL");
649 return;
650 }
651 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000652 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000653 return;
654 }
655 if (umove(tcp, addr, &statbuf) < 0) {
656 tprintf("{...}");
657 return;
658 }
659 if (!abbrev(tcp)) {
660 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
661 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
662 (unsigned long) (statbuf.st_dev & 0x3ffff),
663 (unsigned long) statbuf.st_ino,
664 sprintmode(statbuf.st_mode));
665 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
666 (unsigned long) statbuf.st_nlink,
667 (unsigned long) statbuf.st_uid,
668 (unsigned long) statbuf.st_gid);
669 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
670 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
671 }
672 else
673 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
674 switch (statbuf.st_mode & S_IFMT) {
675 case S_IFCHR: case S_IFBLK:
676 tprintf("st_rdev=makedev(%lu, %lu), ",
677 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
678 (unsigned long) (statbuf.st_rdev & 0x3ffff));
679 break;
680 default:
681 tprintf("st_size=%u, ", statbuf.st_size);
682 break;
683 }
684 if (!abbrev(tcp)) {
685 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
686 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
687 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
688 }
689 else
690 tprintf("...}");
691}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000692
693#if defined (SPARC64)
694static void
695printstat_sparc64(tcp, addr)
696struct tcb *tcp;
697long addr;
698{
699 struct stat_sparc64 statbuf;
700
701 if (!addr) {
702 tprintf("NULL");
703 return;
704 }
705 if (syserror(tcp) || !verbose(tcp)) {
706 tprintf("%#lx", addr);
707 return;
708 }
709 if (umove(tcp, addr, &statbuf) < 0) {
710 tprintf("{...}");
711 return;
712 }
713
714 if (!abbrev(tcp)) {
715 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
716 (unsigned long) major(statbuf.st_dev),
717 (unsigned long) minor(statbuf.st_dev),
718 (unsigned long) statbuf.st_ino,
719 sprintmode(statbuf.st_mode));
720 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
721 (unsigned long) statbuf.st_nlink,
722 (unsigned long) statbuf.st_uid,
723 (unsigned long) statbuf.st_gid);
724 tprintf("st_blksize=%lu, ",
725 (unsigned long) statbuf.st_blksize);
726 tprintf("st_blocks=%lu, ",
727 (unsigned long) statbuf.st_blocks);
728 }
729 else
730 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
731 switch (statbuf.st_mode & S_IFMT) {
732 case S_IFCHR: case S_IFBLK:
733 tprintf("st_rdev=makedev(%lu, %lu), ",
734 (unsigned long) major(statbuf.st_rdev),
735 (unsigned long) minor(statbuf.st_rdev));
736 break;
737 default:
738 tprintf("st_size=%lu, ", statbuf.st_size);
739 break;
740 }
741 if (!abbrev(tcp)) {
742 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
743 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
744 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
745 tprintf("}");
746 }
747 else
748 tprintf("...}");
749}
750#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000751#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000752
Roland McGrathd9f816f2004-09-04 03:39:20 +0000753const struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000754#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000755 { UF_NODUMP, "UF_NODUMP" },
756 { UF_IMMUTABLE, "UF_IMMUTABLE" },
757 { UF_APPEND, "UF_APPEND" },
758 { UF_OPAQUE, "UF_OPAQUE" },
759 { UF_NOUNLINK, "UF_NOUNLINK" },
760 { SF_ARCHIVED, "SF_ARCHIVED" },
761 { SF_IMMUTABLE, "SF_IMMUTABLE" },
762 { SF_APPEND, "SF_APPEND" },
763 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000764#elif UNIXWARE >= 2
765#ifdef _S_ISMLD
766 { _S_ISMLD, "_S_ISMLD" },
767#endif
768#ifdef _S_ISMOUNTED
769 { _S_ISMOUNTED, "_S_ISMOUNTED" },
770#endif
771#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000772 { 0, NULL },
773};
774
John Hughesc0fc3fd2001-03-08 16:10:40 +0000775#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000776int
777sys_chflags(tcp)
778struct tcb *tcp;
779{
780 if (entering(tcp)) {
781 printpath(tcp, tcp->u_arg[0]);
782 tprintf(", ");
783 if (tcp->u_arg[1])
784 printflags(fileflags, tcp->u_arg[1]);
785 else
786 tprintf("0");
787 }
788 return 0;
789}
790
791int
792sys_fchflags(tcp)
793struct tcb *tcp;
794{
795 if (entering(tcp)) {
796 tprintf("%ld, ", tcp->u_arg[0]);
797 if (tcp->u_arg[1])
798 printflags(fileflags, tcp->u_arg[1]);
799 else
800 tprintf("0");
801 }
802 return 0;
803}
804#endif
805
John Hughes70623be2001-03-08 13:59:00 +0000806#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000807static void
808realprintstat(tcp, statbuf)
809struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000810struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000811{
812 if (!abbrev(tcp)) {
813 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
814 (unsigned long) major(statbuf->st_dev),
815 (unsigned long) minor(statbuf->st_dev),
816 (unsigned long) statbuf->st_ino,
817 sprintmode(statbuf->st_mode));
818 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
819 (unsigned long) statbuf->st_nlink,
820 (unsigned long) statbuf->st_uid,
821 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000822#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000823 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000824#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
825#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000826 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000827#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000828 }
829 else
830 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
831 switch (statbuf->st_mode & S_IFMT) {
832 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000833#ifdef HAVE_STRUCT_STAT_ST_RDEV
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000834 tprintf("st_rdev=makedev(%lu, %lu), ",
835 (unsigned long) major(statbuf->st_rdev),
836 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000837#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000838 tprintf("st_size=makedev(%lu, %lu), ",
839 (unsigned long) major(statbuf->st_size),
840 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000841#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000842 break;
843 default:
844 tprintf("st_size=%lu, ", statbuf->st_size);
845 break;
846 }
847 if (!abbrev(tcp)) {
848 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
849 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000850 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000851#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000852 tprintf(", st_flags=");
853 if (statbuf->st_flags) {
854 printflags(fileflags, statbuf->st_flags);
855 } else
856 tprintf("0");
857#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000858#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000859 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
860#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000861#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000862 tprintf(", st_level=%ld", statbuf->st_level);
863#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000864#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000865 tprintf(", st_fstype=%.*s",
866 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
867#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000868#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000869 tprintf(", st_gen=%u", statbuf->st_gen);
870#endif
871 tprintf("}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000872 }
873 else
874 tprintf("...}");
875}
876
Nate Sammons771a6ff1999-04-05 22:39:31 +0000877
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000878static void
879printstat(tcp, addr)
880struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000881long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000882{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000883 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000884
885#ifdef LINUXSPARC
886 if (current_personality == 1) {
887 printstatsol(tcp, addr);
888 return;
889 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000890#ifdef SPARC64
891 else if (current_personality == 2) {
892 printstat_sparc64(tcp, addr);
893 return;
894 }
895#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000896#endif /* LINUXSPARC */
897
898 if (!addr) {
899 tprintf("NULL");
900 return;
901 }
902 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000903 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000904 return;
905 }
906 if (umove(tcp, addr, &statbuf) < 0) {
907 tprintf("{...}");
908 return;
909 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000910
911 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000912}
John Hughes70623be2001-03-08 13:59:00 +0000913#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000914
Wichert Akkermanc7926982000-04-10 22:22:31 +0000915#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000916static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000917printstat64(tcp, addr)
918struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000919long addr;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000920{
921 struct stat64 statbuf;
922
923#ifdef LINUXSPARC
924 if (current_personality == 1) {
925 printstatsol(tcp, addr);
926 return;
927 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000928#ifdef SPARC64
929 else if (current_personality == 2) {
930 printstat_sparc64(tcp, addr);
931 return;
932 }
933#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000934#endif /* LINUXSPARC */
935
936 if (!addr) {
937 tprintf("NULL");
938 return;
939 }
940 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000941 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000942 return;
943 }
944 if (umove(tcp, addr, &statbuf) < 0) {
945 tprintf("{...}");
946 return;
947 }
948
949 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +0000950#ifdef HAVE_LONG_LONG
951 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
952#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000953 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +0000954#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000955 (unsigned long) major(statbuf.st_dev),
956 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +0000957#ifdef HAVE_LONG_LONG
958 (unsigned long long) statbuf.st_ino,
959#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000960 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +0000961#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000962 sprintmode(statbuf.st_mode));
963 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
964 (unsigned long) statbuf.st_nlink,
965 (unsigned long) statbuf.st_uid,
966 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000967#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000968 tprintf("st_blksize=%lu, ",
969 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000970#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
971#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000972 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000973#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000974 }
975 else
976 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
977 switch (statbuf.st_mode & S_IFMT) {
978 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000979#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000980 tprintf("st_rdev=makedev(%lu, %lu), ",
981 (unsigned long) major(statbuf.st_rdev),
982 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000983#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000984 tprintf("st_size=makedev(%lu, %lu), ",
985 (unsigned long) major(statbuf.st_size),
986 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000987#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000988 break;
989 default:
990 tprintf("st_size=%llu, ", statbuf.st_size);
991 break;
992 }
993 if (!abbrev(tcp)) {
994 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
995 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000996 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000997#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000998 tprintf(", st_flags=");
John Hughesb8c9f772001-03-07 16:53:07 +0000999 if (statbuf.st_flags) {
1000 printflags(fileflags, statbuf.st_flags);
1001 } else
1002 tprintf("0");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001003#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001004#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001005 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1006#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001007#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001008 tprintf(", st_level=%ld", statbuf.st_level);
1009#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001010#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001011 tprintf(", st_fstype=%.*s",
1012 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1013#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001014#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001015 tprintf(", st_gen=%u", statbuf.st_gen);
1016#endif
1017 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001018 }
1019 else
1020 tprintf("...}");
1021}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001022#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001023
Roland McGrath79db8af2003-06-27 21:20:09 +00001024#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001025static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001026convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001027const struct __old_kernel_stat *oldbuf;
1028struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001029{
1030 newbuf->st_dev=oldbuf->st_dev;
1031 newbuf->st_ino=oldbuf->st_ino;
1032 newbuf->st_mode=oldbuf->st_mode;
1033 newbuf->st_nlink=oldbuf->st_nlink;
1034 newbuf->st_uid=oldbuf->st_uid;
1035 newbuf->st_gid=oldbuf->st_gid;
1036 newbuf->st_rdev=oldbuf->st_rdev;
1037 newbuf->st_size=oldbuf->st_size;
1038 newbuf->st_atime=oldbuf->st_atime;
1039 newbuf->st_mtime=oldbuf->st_mtime;
1040 newbuf->st_ctime=oldbuf->st_ctime;
1041 newbuf->st_blksize=0; /* not supported in old_stat */
1042 newbuf->st_blocks=0; /* not supported in old_stat */
1043}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001044
1045
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001046static void
1047printoldstat(tcp, addr)
1048struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001049long addr;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001050{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001051 struct __old_kernel_stat statbuf;
1052 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001053
1054#ifdef LINUXSPARC
1055 if (current_personality == 1) {
1056 printstatsol(tcp, addr);
1057 return;
1058 }
1059#endif /* LINUXSPARC */
1060
1061 if (!addr) {
1062 tprintf("NULL");
1063 return;
1064 }
1065 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001066 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001067 return;
1068 }
1069 if (umove(tcp, addr, &statbuf) < 0) {
1070 tprintf("{...}");
1071 return;
1072 }
1073
1074 convertoldstat(&statbuf, &newstatbuf);
1075 realprintstat(tcp, &newstatbuf);
1076}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001077#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001078
John Hughes70623be2001-03-08 13:59:00 +00001079#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001080int
1081sys_stat(tcp)
1082struct tcb *tcp;
1083{
1084 if (entering(tcp)) {
1085 printpath(tcp, tcp->u_arg[0]);
1086 tprintf(", ");
1087 } else {
1088 printstat(tcp, tcp->u_arg[1]);
1089 }
1090 return 0;
1091}
John Hughesb8c9f772001-03-07 16:53:07 +00001092#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001093
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001094int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001095sys_stat64(tcp)
1096struct tcb *tcp;
1097{
1098#ifdef HAVE_STAT64
1099 if (entering(tcp)) {
1100 printpath(tcp, tcp->u_arg[0]);
1101 tprintf(", ");
1102 } else {
1103 printstat64(tcp, tcp->u_arg[1]);
1104 }
1105 return 0;
1106#else
1107 return printargs(tcp);
1108#endif
1109}
1110
Roland McGrath79db8af2003-06-27 21:20:09 +00001111#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001112int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001113sys_oldstat(tcp)
1114struct tcb *tcp;
1115{
1116 if (entering(tcp)) {
1117 printpath(tcp, tcp->u_arg[0]);
1118 tprintf(", ");
1119 } else {
1120 printoldstat(tcp, tcp->u_arg[1]);
1121 }
1122 return 0;
1123}
Roland McGrath79db8af2003-06-27 21:20:09 +00001124#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001125
John Hughes70623be2001-03-08 13:59:00 +00001126#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001127int
1128sys_fstat(tcp)
1129struct tcb *tcp;
1130{
1131 if (entering(tcp))
1132 tprintf("%ld, ", tcp->u_arg[0]);
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_fstat64(tcp)
1142struct tcb *tcp;
1143{
1144#ifdef HAVE_STAT64
1145 if (entering(tcp))
1146 tprintf("%ld, ", tcp->u_arg[0]);
1147 else {
1148 printstat64(tcp, tcp->u_arg[1]);
1149 }
1150 return 0;
1151#else
1152 return printargs(tcp);
1153#endif
1154}
1155
Roland McGrath79db8af2003-06-27 21:20:09 +00001156#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001157int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001158sys_oldfstat(tcp)
1159struct tcb *tcp;
1160{
1161 if (entering(tcp))
1162 tprintf("%ld, ", tcp->u_arg[0]);
1163 else {
1164 printoldstat(tcp, tcp->u_arg[1]);
1165 }
1166 return 0;
1167}
Roland McGrath79db8af2003-06-27 21:20:09 +00001168#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001169
John Hughes70623be2001-03-08 13:59:00 +00001170#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001171int
1172sys_lstat(tcp)
1173struct tcb *tcp;
1174{
1175 if (entering(tcp)) {
1176 printpath(tcp, tcp->u_arg[0]);
1177 tprintf(", ");
1178 } else {
1179 printstat(tcp, tcp->u_arg[1]);
1180 }
1181 return 0;
1182}
John Hughesb8c9f772001-03-07 16:53:07 +00001183#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001184
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001185int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001186sys_lstat64(tcp)
1187struct tcb *tcp;
1188{
1189#ifdef HAVE_STAT64
1190 if (entering(tcp)) {
1191 printpath(tcp, tcp->u_arg[0]);
1192 tprintf(", ");
1193 } else {
1194 printstat64(tcp, tcp->u_arg[1]);
1195 }
1196 return 0;
1197#else
1198 return printargs(tcp);
1199#endif
1200}
1201
Roland McGrath79db8af2003-06-27 21:20:09 +00001202#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001203int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001204sys_oldlstat(tcp)
1205struct tcb *tcp;
1206{
1207 if (entering(tcp)) {
1208 printpath(tcp, tcp->u_arg[0]);
1209 tprintf(", ");
1210 } else {
1211 printoldstat(tcp, tcp->u_arg[1]);
1212 }
1213 return 0;
1214}
Roland McGrath79db8af2003-06-27 21:20:09 +00001215#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001216
1217
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001218#if defined(SVR4) || defined(LINUXSPARC)
1219
1220int
1221sys_xstat(tcp)
1222struct tcb *tcp;
1223{
1224 if (entering(tcp)) {
1225 tprintf("%ld, ", tcp->u_arg[0]);
1226 printpath(tcp, tcp->u_arg[1]);
1227 tprintf(", ");
1228 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001229#ifdef _STAT64_VER
1230 if (tcp->u_arg[0] == _STAT64_VER)
1231 printstat64 (tcp, tcp->u_arg[2]);
1232 else
1233#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001234 printstat(tcp, tcp->u_arg[2]);
1235 }
1236 return 0;
1237}
1238
1239int
1240sys_fxstat(tcp)
1241struct tcb *tcp;
1242{
1243 if (entering(tcp))
1244 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1245 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001246#ifdef _STAT64_VER
1247 if (tcp->u_arg[0] == _STAT64_VER)
1248 printstat64 (tcp, tcp->u_arg[2]);
1249 else
1250#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001251 printstat(tcp, tcp->u_arg[2]);
1252 }
1253 return 0;
1254}
1255
1256int
1257sys_lxstat(tcp)
1258struct tcb *tcp;
1259{
1260 if (entering(tcp)) {
1261 tprintf("%ld, ", tcp->u_arg[0]);
1262 printpath(tcp, tcp->u_arg[1]);
1263 tprintf(", ");
1264 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001265#ifdef _STAT64_VER
1266 if (tcp->u_arg[0] == _STAT64_VER)
1267 printstat64 (tcp, tcp->u_arg[2]);
1268 else
1269#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001270 printstat(tcp, tcp->u_arg[2]);
1271 }
1272 return 0;
1273}
1274
1275int
1276sys_xmknod(tcp)
1277struct tcb *tcp;
1278{
1279 int mode = tcp->u_arg[2];
1280
1281 if (entering(tcp)) {
1282 tprintf("%ld, ", tcp->u_arg[0]);
1283 printpath(tcp, tcp->u_arg[1]);
1284 tprintf(", %s", sprintmode(mode));
1285 switch (mode & S_IFMT) {
1286 case S_IFCHR: case S_IFBLK:
1287#ifdef LINUXSPARC
1288 tprintf(", makedev(%lu, %lu)",
1289 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1290 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001291#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001292 tprintf(", makedev(%lu, %lu)",
1293 (unsigned long) major(tcp->u_arg[3]),
1294 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001295#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001296 break;
1297 default:
1298 break;
1299 }
1300 }
1301 return 0;
1302}
1303
Wichert Akkerman8829a551999-06-11 13:18:40 +00001304#ifdef HAVE_SYS_ACL_H
1305
1306#include <sys/acl.h>
1307
Roland McGrathd9f816f2004-09-04 03:39:20 +00001308const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001309#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001310 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001311#endif
1312#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001313 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001314#endif
1315#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001316 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001317#endif
1318#ifdef ACL_GET
1319 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001320#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001321#ifdef ACL_SET
1322 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001323#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001324#ifdef ACL_CNT
1325 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001326#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001327 { 0, NULL },
1328};
1329
1330int
1331sys_acl(tcp)
1332struct tcb *tcp;
1333{
1334 if (entering(tcp)) {
1335 printpath(tcp, tcp->u_arg[0]);
1336 tprintf(", ");
1337 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1338 tprintf(", %ld", tcp->u_arg[2]);
1339 /*
1340 * FIXME - dump out the list of aclent_t's pointed to
1341 * by "tcp->u_arg[3]" if it's not NULL.
1342 */
1343 if (tcp->u_arg[3])
1344 tprintf(", %#lx", tcp->u_arg[3]);
1345 else
1346 tprintf(", NULL");
1347 }
1348 return 0;
1349}
1350
1351
1352int
1353sys_facl(tcp)
1354struct tcb *tcp;
1355{
1356 if (entering(tcp)) {
1357 tprintf("%ld, ", tcp->u_arg[0]);
1358 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1359 tprintf(", %ld", tcp->u_arg[2]);
1360 /*
1361 * FIXME - dump out the list of aclent_t's pointed to
1362 * by "tcp->u_arg[3]" if it's not NULL.
1363 */
1364 if (tcp->u_arg[3])
1365 tprintf(", %#lx", tcp->u_arg[3]);
1366 else
1367 tprintf(", NULL");
1368 }
1369 return 0;
1370}
1371
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001372
Roland McGrathd9f816f2004-09-04 03:39:20 +00001373const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001374#ifdef IPC_SHM
1375 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001376#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001377#ifdef IPC_SEM
1378 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001379#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001380#ifdef IPC_MSG
1381 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001382#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001383 { 0, NULL },
1384};
1385
1386
1387int
1388sys_aclipc(tcp)
1389struct tcb *tcp;
1390{
1391 if (entering(tcp)) {
1392 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1393 tprintf(", %#lx, ", tcp->u_arg[1]);
1394 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1395 tprintf(", %ld", tcp->u_arg[3]);
1396 /*
1397 * FIXME - dump out the list of aclent_t's pointed to
1398 * by "tcp->u_arg[4]" if it's not NULL.
1399 */
1400 if (tcp->u_arg[4])
1401 tprintf(", %#lx", tcp->u_arg[4]);
1402 else
1403 tprintf(", NULL");
1404 }
1405 return 0;
1406}
1407
1408
1409
Wichert Akkerman8829a551999-06-11 13:18:40 +00001410#endif /* HAVE_SYS_ACL_H */
1411
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001412#endif /* SVR4 || LINUXSPARC */
1413
Michal Ludvig53b320f2002-09-23 13:30:09 +00001414#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001415
Roland McGrathd9f816f2004-09-04 03:39:20 +00001416static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001417 { 0x73757245, "CODA_SUPER_MAGIC" },
1418 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1419 { 0x1373, "DEVFS_SUPER_MAGIC" },
1420 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1421 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001422 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1423 { 0xef53, "EXT2_SUPER_MAGIC" },
1424 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001425 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001426 { 0x9660, "ISOFS_SUPER_MAGIC" },
1427 { 0x137f, "MINIX_SUPER_MAGIC" },
1428 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001429 { 0x2468, "MINIX2_SUPER_MAGIC" },
1430 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001431 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001432 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001433 { 0x6969, "NFS_SUPER_MAGIC" },
1434 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001435 { 0x002f, "QNX4_SUPER_MAGIC" },
1436 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1437 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1438 { 0x517b, "SMB_SUPER_MAGIC" },
1439 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1440 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1441 { 0x00011954, "UFS_MAGIC" },
1442 { 0x54190100, "UFS_CIGAM" },
1443 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001444 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001445 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001446 { 0, NULL },
1447};
1448
Michal Ludvig53b320f2002-09-23 13:30:09 +00001449#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001450
1451#ifndef SVR4
1452
Roland McGrathf9c49b22004-10-06 22:11:54 +00001453static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001454sprintfstype(magic)
1455int magic;
1456{
1457 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001458#ifdef LINUX
Roland McGrathf9c49b22004-10-06 22:11:54 +00001459 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001460
1461 s = xlookup(fsmagic, magic);
1462 if (s) {
1463 sprintf(buf, "\"%s\"", s);
1464 return buf;
1465 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001466#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001467 sprintf(buf, "%#x", magic);
1468 return buf;
1469}
1470
1471static void
1472printstatfs(tcp, addr)
1473struct tcb *tcp;
1474long addr;
1475{
1476 struct statfs statbuf;
1477
1478 if (syserror(tcp) || !verbose(tcp)) {
1479 tprintf("%#lx", addr);
1480 return;
1481 }
1482 if (umove(tcp, addr, &statbuf) < 0) {
1483 tprintf("{...}");
1484 return;
1485 }
1486#ifdef ALPHA
1487
1488 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1489 sprintfstype(statbuf.f_type),
1490 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001491 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1492 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1493 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1494 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001495#else /* !ALPHA */
1496 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1497 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001498 (unsigned long)statbuf.f_bsize,
1499 (unsigned long)statbuf.f_blocks,
1500 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001501 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1502 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001503 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001504 (unsigned long)statbuf.f_ffree,
1505 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001506#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001507 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001508#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001509#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001510#ifdef _STATFS_F_FRSIZE
1511 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1512#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001513 tprintf("}");
1514}
1515
1516int
1517sys_statfs(tcp)
1518struct tcb *tcp;
1519{
1520 if (entering(tcp)) {
1521 printpath(tcp, tcp->u_arg[0]);
1522 tprintf(", ");
1523 } else {
1524 printstatfs(tcp, tcp->u_arg[1]);
1525 }
1526 return 0;
1527}
1528
1529int
1530sys_fstatfs(tcp)
1531struct tcb *tcp;
1532{
1533 if (entering(tcp)) {
1534 tprintf("%lu, ", tcp->u_arg[0]);
1535 } else {
1536 printstatfs(tcp, tcp->u_arg[1]);
1537 }
1538 return 0;
1539}
1540
Roland McGrathab147c52003-07-17 09:03:02 +00001541#ifdef LINUX
1542static void
1543printstatfs64(tcp, addr)
1544struct tcb *tcp;
1545long addr;
1546{
1547 struct statfs64 statbuf;
1548
1549 if (syserror(tcp) || !verbose(tcp)) {
1550 tprintf("%#lx", addr);
1551 return;
1552 }
1553 if (umove(tcp, addr, &statbuf) < 0) {
1554 tprintf("{...}");
1555 return;
1556 }
1557#ifdef ALPHA
1558
1559 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1560 sprintfstype(statbuf.f_type),
1561 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1562 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1563 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1564 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1565 statbuf.f_namelen);
1566#else /* !ALPHA */
1567 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1568 sprintfstype(statbuf.f_type),
1569 (unsigned long)statbuf.f_bsize,
1570 (unsigned long)statbuf.f_blocks,
1571 (unsigned long)statbuf.f_bfree);
1572 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1573 (unsigned long)statbuf.f_bavail,
1574 (unsigned long)statbuf.f_files,
1575 (unsigned long)statbuf.f_ffree,
1576 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1577 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1578#endif /* !ALPHA */
1579#ifdef _STATFS_F_FRSIZE
1580 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1581#endif
1582 tprintf("}");
1583}
1584
1585int
1586sys_statfs64(tcp)
1587struct tcb *tcp;
1588{
1589 if (entering(tcp)) {
1590 printpath(tcp, tcp->u_arg[0]);
1591 tprintf(", %lu, ", tcp->u_arg[1]);
1592 } else {
1593 if (tcp->u_arg[1] == sizeof (struct statfs64))
1594 printstatfs64(tcp, tcp->u_arg[2]);
1595 else
1596 tprintf("{???}");
1597 }
1598 return 0;
1599}
1600
1601int
1602sys_fstatfs64(tcp)
1603struct tcb *tcp;
1604{
1605 if (entering(tcp)) {
1606 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1607 } else {
1608 if (tcp->u_arg[1] == sizeof (struct statfs64))
1609 printstatfs64(tcp, tcp->u_arg[2]);
1610 else
1611 tprintf("{???}");
1612 }
1613 return 0;
1614}
1615#endif
1616
Michal Ludvig53b320f2002-09-23 13:30:09 +00001617#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001618
1619int
1620osf_statfs(tcp)
1621struct tcb *tcp;
1622{
1623 if (entering(tcp)) {
1624 printpath(tcp, tcp->u_arg[0]);
1625 tprintf(", ");
1626 } else {
1627 printstatfs(tcp, tcp->u_arg[1]);
1628 tprintf(", %lu", tcp->u_arg[2]);
1629 }
1630 return 0;
1631}
1632
1633int
1634osf_fstatfs(tcp)
1635struct tcb *tcp;
1636{
1637 if (entering(tcp)) {
1638 tprintf("%lu, ", tcp->u_arg[0]);
1639 } else {
1640 printstatfs(tcp, tcp->u_arg[1]);
1641 tprintf(", %lu", tcp->u_arg[2]);
1642 }
1643 return 0;
1644}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001645#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001646
1647#endif /* !SVR4 */
1648
1649#ifdef SUNOS4
1650
1651int
1652sys_ustat(tcp)
1653struct tcb *tcp;
1654{
1655 struct ustat statbuf;
1656
1657 if (entering(tcp)) {
1658 tprintf("makedev(%lu, %lu), ",
1659 (long) major(tcp->u_arg[0]),
1660 (long) minor(tcp->u_arg[0]));
1661 }
1662 else {
1663 if (syserror(tcp) || !verbose(tcp))
1664 tprintf("%#lx", tcp->u_arg[1]);
1665 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1666 tprintf("{...}");
1667 else {
1668 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1669 statbuf.f_tfree, statbuf.f_tinode);
1670 tprintf("f_fname=\"%.*s\", ",
1671 (int) sizeof(statbuf.f_fname),
1672 statbuf.f_fname);
1673 tprintf("f_fpack=\"%.*s\"}",
1674 (int) sizeof(statbuf.f_fpack),
1675 statbuf.f_fpack);
1676 }
1677 }
1678 return 0;
1679}
1680
1681#endif /* SUNOS4 */
1682
Wichert Akkermanc7926982000-04-10 22:22:31 +00001683int
1684sys_pivotroot(tcp)
1685struct tcb *tcp;
1686{
1687 if (entering(tcp)) {
1688 printpath(tcp, tcp->u_arg[0]);
1689 tprintf(", ");
1690 printpath(tcp, tcp->u_arg[1]);
1691 }
1692 return 0;
1693}
1694
1695
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001696/* directory */
1697int
1698sys_chdir(tcp)
1699struct tcb *tcp;
1700{
1701 if (entering(tcp)) {
1702 printpath(tcp, tcp->u_arg[0]);
1703 }
1704 return 0;
1705}
1706
1707int
1708sys_mkdir(tcp)
1709struct tcb *tcp;
1710{
1711 if (entering(tcp)) {
1712 printpath(tcp, tcp->u_arg[0]);
1713 tprintf(", %#lo", tcp->u_arg[1]);
1714 }
1715 return 0;
1716}
1717
1718int
1719sys_rmdir(tcp)
1720struct tcb *tcp;
1721{
1722 if (entering(tcp)) {
1723 printpath(tcp, tcp->u_arg[0]);
1724 }
1725 return 0;
1726}
1727
1728int
1729sys_fchdir(tcp)
1730struct tcb *tcp;
1731{
1732 if (entering(tcp)) {
1733 tprintf("%ld", tcp->u_arg[0]);
1734 }
1735 return 0;
1736}
1737
1738int
1739sys_chroot(tcp)
1740struct tcb *tcp;
1741{
1742 if (entering(tcp)) {
1743 printpath(tcp, tcp->u_arg[0]);
1744 }
1745 return 0;
1746}
1747
1748int
1749sys_fchroot(tcp)
1750struct tcb *tcp;
1751{
1752 if (entering(tcp)) {
1753 tprintf("%ld", tcp->u_arg[0]);
1754 }
1755 return 0;
1756}
1757
1758int
1759sys_link(tcp)
1760struct tcb *tcp;
1761{
1762 if (entering(tcp)) {
1763 printpath(tcp, tcp->u_arg[0]);
1764 tprintf(", ");
1765 printpath(tcp, tcp->u_arg[1]);
1766 }
1767 return 0;
1768}
1769
1770int
1771sys_unlink(tcp)
1772struct tcb *tcp;
1773{
1774 if (entering(tcp)) {
1775 printpath(tcp, tcp->u_arg[0]);
1776 }
1777 return 0;
1778}
1779
1780int
1781sys_symlink(tcp)
1782struct tcb *tcp;
1783{
1784 if (entering(tcp)) {
1785 printpath(tcp, tcp->u_arg[0]);
1786 tprintf(", ");
1787 printpath(tcp, tcp->u_arg[1]);
1788 }
1789 return 0;
1790}
1791
1792int
1793sys_readlink(tcp)
1794struct tcb *tcp;
1795{
1796 if (entering(tcp)) {
1797 printpath(tcp, tcp->u_arg[0]);
1798 tprintf(", ");
1799 } else {
1800 if (syserror(tcp))
1801 tprintf("%#lx", tcp->u_arg[1]);
1802 else
1803 printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
1804 tprintf(", %lu", tcp->u_arg[2]);
1805 }
1806 return 0;
1807}
1808
1809int
1810sys_rename(tcp)
1811struct tcb *tcp;
1812{
1813 if (entering(tcp)) {
1814 printpath(tcp, tcp->u_arg[0]);
1815 tprintf(", ");
1816 printpath(tcp, tcp->u_arg[1]);
1817 }
1818 return 0;
1819}
1820
1821int
1822sys_chown(tcp)
1823struct tcb *tcp;
1824{
1825 if (entering(tcp)) {
1826 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001827 printuid(", ", tcp->u_arg[1]);
1828 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001829 }
1830 return 0;
1831}
1832
1833int
1834sys_fchown(tcp)
1835struct tcb *tcp;
1836{
1837 if (entering(tcp)) {
Roland McGrath6bc12202003-11-13 22:32:27 +00001838 tprintf("%ld", tcp->u_arg[0]);
1839 printuid(", ", tcp->u_arg[1]);
1840 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001841 }
1842 return 0;
1843}
1844
1845int
1846sys_chmod(tcp)
1847struct tcb *tcp;
1848{
1849 if (entering(tcp)) {
1850 printpath(tcp, tcp->u_arg[0]);
1851 tprintf(", %#lo", tcp->u_arg[1]);
1852 }
1853 return 0;
1854}
1855
1856int
1857sys_fchmod(tcp)
1858struct tcb *tcp;
1859{
1860 if (entering(tcp)) {
1861 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
1862 }
1863 return 0;
1864}
1865
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001866#ifdef ALPHA
1867int
1868sys_osf_utimes(tcp)
1869struct tcb *tcp;
1870{
1871 if (entering(tcp)) {
1872 printpath(tcp, tcp->u_arg[0]);
1873 tprintf(", ");
1874 printtv32(tcp, tcp->u_arg[1]);
1875 }
1876 return 0;
1877}
1878#endif
1879
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001880int
1881sys_utimes(tcp)
1882struct tcb *tcp;
1883{
1884 if (entering(tcp)) {
1885 printpath(tcp, tcp->u_arg[0]);
1886 tprintf(", ");
1887 printtv(tcp, tcp->u_arg[1]);
1888 }
1889 return 0;
1890}
1891
1892int
1893sys_utime(tcp)
1894struct tcb *tcp;
1895{
1896 long ut[2];
1897
1898 if (entering(tcp)) {
1899 printpath(tcp, tcp->u_arg[0]);
1900 tprintf(", ");
1901 if (!tcp->u_arg[1])
1902 tprintf("NULL");
1903 else if (!verbose(tcp))
1904 tprintf("%#lx", tcp->u_arg[1]);
1905 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
1906 (char *) ut) < 0)
1907 tprintf("[?, ?]");
1908 else {
1909 tprintf("[%s,", sprinttime(ut[0]));
1910 tprintf(" %s]", sprinttime(ut[1]));
1911 }
1912 }
1913 return 0;
1914}
1915
1916int
1917sys_mknod(tcp)
1918struct tcb *tcp;
1919{
1920 int mode = tcp->u_arg[1];
1921
1922 if (entering(tcp)) {
1923 printpath(tcp, tcp->u_arg[0]);
1924 tprintf(", %s", sprintmode(mode));
1925 switch (mode & S_IFMT) {
1926 case S_IFCHR: case S_IFBLK:
1927#ifdef LINUXSPARC
1928 if (current_personality == 1)
1929 tprintf(", makedev(%lu, %lu)",
1930 (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
1931 (unsigned long) (tcp->u_arg[2] & 0x3ffff));
1932 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00001933#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001934 tprintf(", makedev(%lu, %lu)",
1935 (unsigned long) major(tcp->u_arg[2]),
1936 (unsigned long) minor(tcp->u_arg[2]));
1937 break;
1938 default:
1939 break;
1940 }
1941 }
1942 return 0;
1943}
1944
1945int
1946sys_mkfifo(tcp)
1947struct tcb *tcp;
1948{
1949 if (entering(tcp)) {
1950 printpath(tcp, tcp->u_arg[0]);
1951 tprintf(", %#lo", tcp->u_arg[1]);
1952 }
1953 return 0;
1954}
1955
1956int
1957sys_fsync(tcp)
1958struct tcb *tcp;
1959{
1960 if (entering(tcp)) {
1961 tprintf("%ld", tcp->u_arg[0]);
1962 }
1963 return 0;
1964}
1965
Michal Ludvig53b320f2002-09-23 13:30:09 +00001966#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001967
1968static void
1969printdir(tcp, addr)
1970struct tcb *tcp;
1971long addr;
1972{
1973 struct dirent d;
1974
1975 if (!verbose(tcp)) {
1976 tprintf("%#lx", addr);
1977 return;
1978 }
1979 if (umove(tcp, addr, &d) < 0) {
1980 tprintf("{...}");
1981 return;
1982 }
1983 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001984 tprintf("d_name=");
1985 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
1986 tprintf("}");
1987}
1988
1989int
1990sys_readdir(tcp)
1991struct tcb *tcp;
1992{
1993 if (entering(tcp)) {
1994 tprintf("%lu, ", tcp->u_arg[0]);
1995 } else {
1996 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
1997 tprintf("%#lx", tcp->u_arg[1]);
1998 else
1999 printdir(tcp, tcp->u_arg[1]);
2000 /* Not much point in printing this out, it is always 1. */
2001 if (tcp->u_arg[2] != 1)
2002 tprintf(", %lu", tcp->u_arg[2]);
2003 }
2004 return 0;
2005}
2006
Michal Ludvig53b320f2002-09-23 13:30:09 +00002007#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002008
Roland McGrath40542842004-01-13 09:47:49 +00002009#if defined FREEBSD || defined LINUX
Roland McGrathd9f816f2004-09-04 03:39:20 +00002010const struct xlat direnttypes[] = {
Roland McGrath40542842004-01-13 09:47:49 +00002011 { DT_UNKNOWN, "DT_UNKNOWN" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002012 { DT_FIFO, "DT_FIFO" },
2013 { DT_CHR, "DT_CHR" },
2014 { DT_DIR, "DT_DIR" },
2015 { DT_BLK, "DT_BLK" },
2016 { DT_REG, "DT_REG" },
2017 { DT_LNK, "DT_LNK" },
2018 { DT_SOCK, "DT_SOCK" },
2019 { DT_WHT, "DT_WHT" },
2020 { 0, NULL },
2021};
2022
2023#endif
2024
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002025int
2026sys_getdents(tcp)
2027struct tcb *tcp;
2028{
2029 int i, len, dents = 0;
2030 char *buf;
2031
2032 if (entering(tcp)) {
2033 tprintf("%lu, ", tcp->u_arg[0]);
2034 return 0;
2035 }
2036 if (syserror(tcp) || !verbose(tcp)) {
2037 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2038 return 0;
2039 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002040 len = tcp->u_rval;
2041 if ((buf = malloc(len)) == NULL) {
2042 tprintf("out of memory\n");
2043 return 0;
2044 }
2045 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2046 tprintf("{...}, %lu", tcp->u_arg[2]);
2047 free(buf);
2048 return 0;
2049 }
2050 if (!abbrev(tcp))
2051 tprintf("{");
2052 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002053 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002054#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002055 if (!abbrev(tcp)) {
2056 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2057 i ? " " : "", d->d_ino, d->d_off);
2058 tprintf("d_reclen=%u, d_name=\"%s\"}",
2059 d->d_reclen, d->d_name);
2060 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002061#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002062#ifdef SVR4
2063 if (!abbrev(tcp)) {
2064 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002065 i ? " " : "",
2066 (unsigned long) d->d_ino,
2067 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002068 tprintf("d_reclen=%u, d_name=\"%s\"}",
2069 d->d_reclen, d->d_name);
2070 }
2071#endif /* SVR4 */
2072#ifdef SUNOS4
2073 if (!abbrev(tcp)) {
2074 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2075 i ? " " : "", d->d_off, d->d_fileno,
2076 d->d_reclen);
2077 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2078 d->d_namlen, d->d_namlen, d->d_name);
2079 }
2080#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002081#ifdef FREEBSD
2082 if (!abbrev(tcp)) {
2083 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2084 i ? " " : "", d->d_fileno, d->d_reclen);
2085 printxval(direnttypes, d->d_type, "DT_???");
2086 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2087 d->d_namlen, d->d_namlen, d->d_name);
2088 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002089#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002090 if (!d->d_reclen) {
2091 tprintf("/* d_reclen == 0, problem here */");
2092 break;
2093 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002094 i += d->d_reclen;
2095 dents++;
2096 }
2097 if (!abbrev(tcp))
2098 tprintf("}");
2099 else
2100 tprintf("/* %u entries */", dents);
2101 tprintf(", %lu", tcp->u_arg[2]);
2102 free(buf);
2103 return 0;
2104}
2105
John Hughesbdf48f52001-03-06 15:08:09 +00002106
2107#if _LFS64_LARGEFILE
2108int
2109sys_getdents64(tcp)
2110struct tcb *tcp;
2111{
2112 int i, len, dents = 0;
2113 char *buf;
2114
2115 if (entering(tcp)) {
2116 tprintf("%lu, ", tcp->u_arg[0]);
2117 return 0;
2118 }
2119 if (syserror(tcp) || !verbose(tcp)) {
2120 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2121 return 0;
2122 }
2123 len = tcp->u_rval;
2124 if ((buf = malloc(len)) == NULL) {
2125 tprintf("out of memory\n");
2126 return 0;
2127 }
2128 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2129 tprintf("{...}, %lu", tcp->u_arg[2]);
2130 free(buf);
2131 return 0;
2132 }
2133 if (!abbrev(tcp))
2134 tprintf("{");
2135 for (i = 0; i < len;) {
2136 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002137#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002138 if (!abbrev(tcp)) {
Roland McGrath92053242004-01-13 10:16:47 +00002139 tprintf("%s{d_ino=%llu, d_off=%llu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002140 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002141 d->d_ino,
2142 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002143#ifdef LINUX
2144 tprintf("d_type=");
2145 printxval(direnttypes, d->d_type, "DT_???");
2146 tprintf(", ");
2147#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002148 tprintf("d_reclen=%u, d_name=\"%s\"}",
2149 d->d_reclen, d->d_name);
2150 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002151#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002152#ifdef SUNOS4
2153 if (!abbrev(tcp)) {
2154 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2155 i ? " " : "", d->d_off, d->d_fileno,
2156 d->d_reclen);
2157 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2158 d->d_namlen, d->d_namlen, d->d_name);
2159 }
2160#endif /* SUNOS4 */
2161 i += d->d_reclen;
2162 dents++;
2163 }
2164 if (!abbrev(tcp))
2165 tprintf("}");
2166 else
2167 tprintf("/* %u entries */", dents);
2168 tprintf(", %lu", tcp->u_arg[2]);
2169 free(buf);
2170 return 0;
2171}
2172#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002173
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002174#ifdef FREEBSD
2175int
2176sys_getdirentries(tcp)
2177struct tcb * tcp;
2178{
2179 int i, len, dents = 0;
2180 long basep;
2181 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002182
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002183 if (entering(tcp)) {
2184 tprintf("%lu, ", tcp->u_arg[0]);
2185 return 0;
2186 }
2187 if (syserror(tcp) || !verbose(tcp)) {
2188 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2189 return 0;
2190 }
2191 len = tcp->u_rval;
2192 if ((buf = malloc(len)) == NULL) {
2193 tprintf("out of memory\n");
2194 return 0;
2195 }
2196 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2197 tprintf("{...}, %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3]);
2198 free(buf);
2199 return 0;
2200 }
2201 if (!abbrev(tcp))
2202 tprintf("{");
2203 for (i = 0; i < len;) {
2204 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2205 if (!abbrev(tcp)) {
2206 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2207 i ? " " : "", d->d_fileno, d->d_reclen);
2208 printxval(direnttypes, d->d_type, "DT_???");
2209 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2210 d->d_namlen, d->d_namlen, d->d_name);
2211 }
2212 i += d->d_reclen;
2213 dents++;
2214 }
2215 if (!abbrev(tcp))
2216 tprintf("}");
2217 else
2218 tprintf("/* %u entries */", dents);
2219 free(buf);
2220 tprintf(", %lu", tcp->u_arg[2]);
2221 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2222 tprintf(", %#lx", tcp->u_arg[3]);
2223 else
2224 tprintf(", [%lu]", basep);
2225 return 0;
2226}
2227#endif
2228
Michal Ludvig53b320f2002-09-23 13:30:09 +00002229#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002230int
2231sys_getcwd(tcp)
2232struct tcb *tcp;
2233{
2234 if (exiting(tcp)) {
2235 if (syserror(tcp))
2236 tprintf("%#lx", tcp->u_arg[0]);
2237 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002238 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002239 tprintf(", %lu", tcp->u_arg[1]);
2240 }
2241 return 0;
2242}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002243#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002244
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002245#ifdef FREEBSD
2246int
2247sys___getcwd(tcp)
2248struct tcb *tcp;
2249{
2250 if (exiting(tcp)) {
2251 if (syserror(tcp))
2252 tprintf("%#lx", tcp->u_arg[0]);
2253 else
2254 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2255 tprintf(", %lu", tcp->u_arg[1]);
2256 }
2257 return 0;
2258}
2259#endif
2260
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002261#ifdef HAVE_SYS_ASYNCH_H
2262
2263int
2264sys_aioread(tcp)
2265struct tcb *tcp;
2266{
2267 struct aio_result_t res;
2268
2269 if (entering(tcp)) {
2270 tprintf("%lu, ", tcp->u_arg[0]);
2271 } else {
2272 if (syserror(tcp))
2273 tprintf("%#lx", tcp->u_arg[1]);
2274 else
2275 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2276 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2277 printxval(whence, tcp->u_arg[4], "L_???");
2278 if (syserror(tcp) || tcp->u_arg[5] == 0
2279 || umove(tcp, tcp->u_arg[5], &res) < 0)
2280 tprintf(", %#lx", tcp->u_arg[5]);
2281 else
2282 tprintf(", {aio_return %d aio_errno %d}",
2283 res.aio_return, res.aio_errno);
2284 }
2285 return 0;
2286}
2287
2288int
2289sys_aiowrite(tcp)
2290struct tcb *tcp;
2291{
2292 struct aio_result_t res;
2293
2294 if (entering(tcp)) {
2295 tprintf("%lu, ", tcp->u_arg[0]);
2296 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2297 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2298 printxval(whence, tcp->u_arg[4], "L_???");
2299 }
2300 else {
2301 if (tcp->u_arg[5] == 0)
2302 tprintf(", NULL");
2303 else if (syserror(tcp)
2304 || umove(tcp, tcp->u_arg[5], &res) < 0)
2305 tprintf(", %#lx", tcp->u_arg[5]);
2306 else
2307 tprintf(", {aio_return %d aio_errno %d}",
2308 res.aio_return, res.aio_errno);
2309 }
2310 return 0;
2311}
2312
2313int
2314sys_aiowait(tcp)
2315struct tcb *tcp;
2316{
2317 if (entering(tcp))
2318 printtv(tcp, tcp->u_arg[0]);
2319 return 0;
2320}
2321
2322int
2323sys_aiocancel(tcp)
2324struct tcb *tcp;
2325{
2326 struct aio_result_t res;
2327
2328 if (exiting(tcp)) {
2329 if (tcp->u_arg[0] == 0)
2330 tprintf("NULL");
2331 else if (syserror(tcp)
2332 || umove(tcp, tcp->u_arg[0], &res) < 0)
2333 tprintf("%#lx", tcp->u_arg[0]);
2334 else
2335 tprintf("{aio_return %d aio_errno %d}",
2336 res.aio_return, res.aio_errno);
2337 }
2338 return 0;
2339}
2340
2341#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002342
Roland McGrathd9f816f2004-09-04 03:39:20 +00002343const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002344#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002345 { XATTR_CREATE, "XATTR_CREATE" },
2346 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002347#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002348 { 0, NULL }
2349};
2350
Roland McGrath3292e222004-08-31 06:30:48 +00002351static void
2352print_xattr_val(tcp, failed, arg, insize, size)
2353struct tcb *tcp;
2354int failed;
2355unsigned long arg;
Roland McGrath883567c2005-02-02 03:38:32 +00002356long insize, size;
Roland McGrath3292e222004-08-31 06:30:48 +00002357{
Roland McGrath883567c2005-02-02 03:38:32 +00002358 if (!failed) {
2359 unsigned char *buf = malloc(4 * size + 1);
2360 if (buf == NULL || /* probably a bogus size argument */
Roland McGrathf7746422005-03-01 23:02:32 +00002361 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
Roland McGrath883567c2005-02-02 03:38:32 +00002362 failed = 1;
2363 }
2364 else {
2365 unsigned char *out = buf;
2366 unsigned char *in = &buf[3 * size];
2367 size_t i;
2368 for (i = 0; i < size; ++i)
2369 if (isprint(in[i]))
2370 *out++ = in[i];
2371 else {
Roland McGrath3292e222004-08-31 06:30:48 +00002372#define tohex(n) "0123456789abcdef"[n]
Roland McGrath883567c2005-02-02 03:38:32 +00002373 *out++ = '\\';
2374 *out++ = 'x';
2375 *out++ = tohex(in[i] / 16);
2376 *out++ = tohex(in[i] % 16);
2377 }
2378 /* Don't print terminating NUL if there is one. */
2379 if (in[i - 1] == '\0')
2380 out -= 4;
2381 *out = '\0';
2382 tprintf(", \"%s\", %ld", buf, insize);
2383 }
2384 free(buf);
2385 }
2386 if (failed)
2387 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002388}
2389
Roland McGrath186c5ac2002-12-15 23:58:23 +00002390int
2391sys_setxattr(tcp)
2392struct tcb *tcp;
2393{
2394 if (entering(tcp)) {
2395 printpath(tcp, tcp->u_arg[0]);
2396 tprintf(", ");
2397 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002398 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2399 tprintf(", ");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002400 printflags(xattrflags, tcp->u_arg[4]);
2401 }
2402 return 0;
2403}
2404
2405int
2406sys_fsetxattr(tcp)
2407struct tcb *tcp;
2408{
2409 if (entering(tcp)) {
2410 tprintf("%ld, ", tcp->u_arg[0]);
2411 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002412 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2413 tprintf(", ");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002414 printflags(xattrflags, tcp->u_arg[4]);
2415 }
2416 return 0;
2417}
2418
2419int
2420sys_getxattr(tcp)
2421struct tcb *tcp;
2422{
2423 if (entering(tcp)) {
2424 printpath(tcp, tcp->u_arg[0]);
2425 tprintf(", ");
2426 printstr(tcp, tcp->u_arg[1], -1);
2427 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002428 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2429 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002430 }
2431 return 0;
2432}
2433
2434int
2435sys_fgetxattr(tcp)
2436struct tcb *tcp;
2437{
2438 if (entering(tcp)) {
2439 tprintf("%ld, ", tcp->u_arg[0]);
2440 printstr(tcp, tcp->u_arg[1], -1);
2441 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002442 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2443 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002444 }
2445 return 0;
2446}
2447
2448int
2449sys_listxattr(tcp)
2450struct tcb *tcp;
2451{
2452 if (entering(tcp)) {
2453 printpath(tcp, tcp->u_arg[0]);
2454 } else {
2455 /* XXX Print value in format */
2456 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2457 }
2458 return 0;
2459}
2460
2461int
2462sys_flistxattr(tcp)
2463struct tcb *tcp;
2464{
2465 if (entering(tcp)) {
2466 tprintf("%ld", tcp->u_arg[0]);
2467 } else {
2468 /* XXX Print value in format */
2469 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2470 }
2471 return 0;
2472}
2473
2474int
2475sys_removexattr(tcp)
2476struct tcb *tcp;
2477{
2478 if (entering(tcp)) {
2479 printpath(tcp, tcp->u_arg[0]);
2480 tprintf(", ");
2481 printstr(tcp, tcp->u_arg[1], -1);
2482 }
2483 return 0;
2484}
2485
2486int
2487sys_fremovexattr(tcp)
2488struct tcb *tcp;
2489{
2490 if (entering(tcp)) {
2491 tprintf("%ld, ", tcp->u_arg[0]);
2492 printstr(tcp, tcp->u_arg[1], -1);
2493 }
2494 return 0;
2495}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002496
2497
2498static const struct xlat advise[] = {
2499 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2500 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2501 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2502 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2503 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2504 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2505 { 0, NULL }
2506};
2507
2508
Roland McGrathe27ed342004-10-20 02:24:19 +00002509#ifdef LINUX
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002510int
2511sys_fadvise64(tcp)
2512struct tcb *tcp;
2513{
2514 if (entering(tcp)) {
2515 tprintf("%ld, %lld, %ld, ",
2516 tcp->u_arg[0],
2517# if defined IA64 || defined X86_64 || defined ALPHA
2518 (long long int) tcp->u_arg[1], tcp->u_arg[2]);
2519 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2520#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002521 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
2522 printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002523#endif
2524 }
2525 return 0;
2526}
2527#endif
2528
2529
2530int
2531sys_fadvise64_64(tcp)
2532struct tcb *tcp;
2533{
2534 if (entering(tcp)) {
2535 tprintf("%ld, %lld, %lld, ",
2536 tcp->u_arg[0],
2537# if defined IA64 || defined X86_64 || defined ALPHA
2538 (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
2539 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2540#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002541 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
2542 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002543 printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
2544#endif
2545 }
2546 return 0;
2547}