blob: 8a3432f3403a921922e291801d660c3682b72e6a [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
Roland McGrath1025c3e2005-05-09 07:40:35 +0000258#ifdef O_NOATIME
259 { O_NOATIME, "O_NOATIME" },
260#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000261
262#ifdef FNDELAY
263 { FNDELAY, "FNDELAY" },
264#endif
265#ifdef FAPPEND
266 { FAPPEND, "FAPPEND" },
267#endif
268#ifdef FMARK
269 { FMARK, "FMARK" },
270#endif
271#ifdef FDEFER
272 { FDEFER, "FDEFER" },
273#endif
274#ifdef FASYNC
275 { FASYNC, "FASYNC" },
276#endif
277#ifdef FSHLOCK
278 { FSHLOCK, "FSHLOCK" },
279#endif
280#ifdef FEXLOCK
281 { FEXLOCK, "FEXLOCK" },
282#endif
283#ifdef FCREAT
284 { FCREAT, "FCREAT" },
285#endif
286#ifdef FTRUNC
287 { FTRUNC, "FTRUNC" },
288#endif
289#ifdef FEXCL
290 { FEXCL, "FEXCL" },
291#endif
292#ifdef FNBIO
293 { FNBIO, "FNBIO" },
294#endif
295#ifdef FSYNC
296 { FSYNC, "FSYNC" },
297#endif
298#ifdef FNOCTTY
299 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000300#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000301#ifdef O_SHLOCK
302 { O_SHLOCK, "O_SHLOCK" },
303#endif
304#ifdef O_EXLOCK
305 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000306#endif
307 { 0, NULL },
308};
309
310int
311sys_open(tcp)
312struct tcb *tcp;
313{
314 if (entering(tcp)) {
315 printpath(tcp, tcp->u_arg[0]);
316 tprintf(", ");
317 /* flags */
318 printflags(openmodes, tcp->u_arg[1] + 1);
319 if (tcp->u_arg[1] & O_CREAT) {
320 /* mode */
321 tprintf(", %#lo", tcp->u_arg[2]);
322 }
323 }
324 return 0;
325}
326
327#ifdef LINUXSPARC
Roland McGrathd9f816f2004-09-04 03:39:20 +0000328const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000329 { 0, "O_RDWR" },
330 { 1, "O_RDONLY" },
331 { 2, "O_WRONLY" },
332 { 0x80, "O_NONBLOCK" },
333 { 8, "O_APPEND" },
334 { 0x100, "O_CREAT" },
335 { 0x200, "O_TRUNC" },
336 { 0x400, "O_EXCL" },
337 { 0x800, "O_NOCTTY" },
338 { 0x10, "O_SYNC" },
339 { 0x40, "O_DSYNC" },
340 { 0x8000, "O_RSYNC" },
341 { 4, "O_NDELAY" },
342 { 0x1000, "O_PRIV" },
343 { 0, NULL },
344};
345
346int
347solaris_open(tcp)
348struct tcb *tcp;
349{
350 if (entering(tcp)) {
351 printpath(tcp, tcp->u_arg[0]);
352 tprintf(", ");
353 /* flags */
354 printflags(openmodessol, tcp->u_arg[1] + 1);
355 if (tcp->u_arg[1] & 0x100) {
356 /* mode */
357 tprintf(", %#lo", tcp->u_arg[2]);
358 }
359 }
360 return 0;
361}
362
363#endif
364
365int
366sys_creat(tcp)
367struct tcb *tcp;
368{
369 if (entering(tcp)) {
370 printpath(tcp, tcp->u_arg[0]);
371 tprintf(", %#lo", tcp->u_arg[1]);
372 }
373 return 0;
374}
375
Roland McGrathd9f816f2004-09-04 03:39:20 +0000376static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000377 { F_OK, "F_OK", },
378 { R_OK, "R_OK" },
379 { W_OK, "W_OK" },
380 { X_OK, "X_OK" },
381#ifdef EFF_ONLY_OK
382 { EFF_ONLY_OK, "EFF_ONLY_OK" },
383#endif
384#ifdef EX_OK
385 { EX_OK, "EX_OK" },
386#endif
387 { 0, NULL },
388};
389
390int
391sys_access(tcp)
392struct tcb *tcp;
393{
394 if (entering(tcp)) {
395 printpath(tcp, tcp->u_arg[0]);
396 tprintf(", ");
397 printflags(access_flags, tcp->u_arg[1]);
398 }
399 return 0;
400}
401
402int
403sys_umask(tcp)
404struct tcb *tcp;
405{
406 if (entering(tcp)) {
407 tprintf("%#lo", tcp->u_arg[0]);
408 }
409 return RVAL_OCTAL;
410}
411
Roland McGrathd9f816f2004-09-04 03:39:20 +0000412static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000413 { SEEK_SET, "SEEK_SET" },
414 { SEEK_CUR, "SEEK_CUR" },
415 { SEEK_END, "SEEK_END" },
416 { 0, NULL },
417};
418
John Hughes70623be2001-03-08 13:59:00 +0000419#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000420int
421sys_lseek(tcp)
422struct tcb *tcp;
423{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000424 off_t offset;
425 int _whence;
426
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000427 if (entering(tcp)) {
428 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000429 offset = tcp->u_arg[1];
430 _whence = tcp->u_arg[2];
431 if (_whence == SEEK_SET)
432 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000433 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000434 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000435 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000436 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000437 return RVAL_UDECIMAL;
438}
John Hughes5a826b82001-03-07 13:21:24 +0000439#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000440
Michal Ludvig53b320f2002-09-23 13:30:09 +0000441#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000442int
443sys_llseek (tcp)
444struct tcb *tcp;
445{
446 if (entering(tcp)) {
Roland McGrath8c304bc2004-10-19 22:59:55 +0000447 /*
448 * This one call takes explicitly two 32-bit arguments hi, lo,
449 * rather than one 64-bit argument for which LONG_LONG works
450 * appropriate for the native byte order.
451 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000452 if (tcp->u_arg[4] == SEEK_SET)
453 tprintf("%ld, %llu, ", tcp->u_arg[0],
Roland McGrath8c304bc2004-10-19 22:59:55 +0000454 (((long long int) tcp->u_arg[1]) << 32
455 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000456 else
457 tprintf("%ld, %lld, ", tcp->u_arg[0],
Roland McGrath8c304bc2004-10-19 22:59:55 +0000458 (((long long int) tcp->u_arg[1]) << 32
459 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000460 }
461 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000462 long long int off;
463 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000464 tprintf("%#lx, ", tcp->u_arg[3]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000465 else
466 tprintf("[%llu], ", off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000467 printxval(whence, tcp->u_arg[4], "SEEK_???");
468 }
469 return 0;
470}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000471
472int
473sys_readahead (tcp)
474struct tcb *tcp;
475{
476 if (entering(tcp)) {
477 tprintf("%ld, %lld, %ld", tcp->u_arg[0],
478# if defined IA64 || defined X86_64 || defined ALPHA
479 (long long int) tcp->u_arg[1], tcp->u_arg[2]
480# else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +0000481 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]
Roland McGrath186c5ac2002-12-15 23:58:23 +0000482# endif
483 );
484 }
485 return 0;
486}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000487#endif
488
John Hughes70623be2001-03-08 13:59:00 +0000489#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000490int
491sys_lseek64 (tcp)
492struct tcb *tcp;
493{
494 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000495 long long offset;
496 ALIGN64 (tcp, 1); /* FreeBSD aligns off_t args */
John Hughes0c79e012001-03-08 14:40:06 +0000497 offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +0000498 if (tcp->u_arg[3] == SEEK_SET)
499 tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
500 else
501 tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
502 printxval(whence, tcp->u_arg[3], "SEEK_???");
503 }
504 return RVAL_LUDECIMAL;
505}
506#endif
507
John Hughes70623be2001-03-08 13:59:00 +0000508#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000509int
510sys_truncate(tcp)
511struct tcb *tcp;
512{
513 if (entering(tcp)) {
514 printpath(tcp, tcp->u_arg[0]);
515 tprintf(", %lu", tcp->u_arg[1]);
516 }
517 return 0;
518}
John Hughes5a826b82001-03-07 13:21:24 +0000519#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520
John Hughes70623be2001-03-08 13:59:00 +0000521#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000522int
523sys_truncate64(tcp)
524struct tcb *tcp;
525{
526 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000527 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000528 printpath(tcp, tcp->u_arg[0]);
John Hughes0c79e012001-03-08 14:40:06 +0000529 tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000530 }
531 return 0;
532}
533#endif
534
John Hughes70623be2001-03-08 13:59:00 +0000535#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000536int
537sys_ftruncate(tcp)
538struct tcb *tcp;
539{
540 if (entering(tcp)) {
541 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
542 }
543 return 0;
544}
John Hughes5a826b82001-03-07 13:21:24 +0000545#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000546
John Hughes70623be2001-03-08 13:59:00 +0000547#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000548int
549sys_ftruncate64(tcp)
550struct tcb *tcp;
551{
552 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000553 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000554 tprintf("%ld, %llu", tcp->u_arg[0],
John Hughes0c79e012001-03-08 14:40:06 +0000555 LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000556 }
557 return 0;
558}
559#endif
560
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000561/* several stats */
562
Roland McGrathd9f816f2004-09-04 03:39:20 +0000563static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564 { S_IFREG, "S_IFREG" },
565 { S_IFSOCK, "S_IFSOCK" },
566 { S_IFIFO, "S_IFIFO" },
567 { S_IFLNK, "S_IFLNK" },
568 { S_IFDIR, "S_IFDIR" },
569 { S_IFBLK, "S_IFBLK" },
570 { S_IFCHR, "S_IFCHR" },
571 { 0, NULL },
572};
573
Roland McGrathf9c49b22004-10-06 22:11:54 +0000574static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000575sprintmode(mode)
576int mode;
577{
578 static char buf[64];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000579 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000580
581 if ((mode & S_IFMT) == 0)
582 s = "";
583 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
584 sprintf(buf, "%#o", mode);
585 return buf;
586 }
587 sprintf(buf, "%s%s%s%s", s,
588 (mode & S_ISUID) ? "|S_ISUID" : "",
589 (mode & S_ISGID) ? "|S_ISGID" : "",
590 (mode & S_ISVTX) ? "|S_ISVTX" : "");
591 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
592 if (mode)
593 sprintf(buf + strlen(buf), "|%#o", mode);
594 s = (*buf == '|') ? buf + 1 : buf;
595 return *s ? s : "0";
596}
597
598static char *
599sprinttime(t)
600time_t t;
601{
602 struct tm *tmp;
603 static char buf[32];
604
605 if (t == 0) {
606 sprintf(buf, "0");
607 return buf;
608 }
609 tmp = localtime(&t);
610 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
Wichert Akkerman3ed6dc22000-01-11 14:41:09 +0000611 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000612 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
613 return buf;
614}
615
616#ifdef LINUXSPARC
617typedef struct {
618 int tv_sec;
619 int tv_nsec;
620} timestruct_t;
621
622struct solstat {
623 unsigned st_dev;
624 int st_pad1[3]; /* network id */
625 unsigned st_ino;
626 unsigned st_mode;
627 unsigned st_nlink;
628 unsigned st_uid;
629 unsigned st_gid;
630 unsigned st_rdev;
631 int st_pad2[2];
632 int st_size;
633 int st_pad3; /* st_size, off_t expansion */
634 timestruct_t st_atime;
635 timestruct_t st_mtime;
636 timestruct_t st_ctime;
637 int st_blksize;
638 int st_blocks;
639 char st_fstype[16];
640 int st_pad4[8]; /* expansion area */
641};
642
643static void
644printstatsol(tcp, addr)
645struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000646long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000647{
648 struct solstat statbuf;
649
650 if (!addr) {
651 tprintf("NULL");
652 return;
653 }
654 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000655 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000656 return;
657 }
658 if (umove(tcp, addr, &statbuf) < 0) {
659 tprintf("{...}");
660 return;
661 }
662 if (!abbrev(tcp)) {
663 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
664 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
665 (unsigned long) (statbuf.st_dev & 0x3ffff),
666 (unsigned long) statbuf.st_ino,
667 sprintmode(statbuf.st_mode));
668 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
669 (unsigned long) statbuf.st_nlink,
670 (unsigned long) statbuf.st_uid,
671 (unsigned long) statbuf.st_gid);
672 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
673 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
674 }
675 else
676 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
677 switch (statbuf.st_mode & S_IFMT) {
678 case S_IFCHR: case S_IFBLK:
679 tprintf("st_rdev=makedev(%lu, %lu), ",
680 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
681 (unsigned long) (statbuf.st_rdev & 0x3ffff));
682 break;
683 default:
684 tprintf("st_size=%u, ", statbuf.st_size);
685 break;
686 }
687 if (!abbrev(tcp)) {
688 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
689 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
690 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
691 }
692 else
693 tprintf("...}");
694}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000695
696#if defined (SPARC64)
697static void
698printstat_sparc64(tcp, addr)
699struct tcb *tcp;
700long addr;
701{
702 struct stat_sparc64 statbuf;
703
704 if (!addr) {
705 tprintf("NULL");
706 return;
707 }
708 if (syserror(tcp) || !verbose(tcp)) {
709 tprintf("%#lx", addr);
710 return;
711 }
712 if (umove(tcp, addr, &statbuf) < 0) {
713 tprintf("{...}");
714 return;
715 }
716
717 if (!abbrev(tcp)) {
718 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
719 (unsigned long) major(statbuf.st_dev),
720 (unsigned long) minor(statbuf.st_dev),
721 (unsigned long) statbuf.st_ino,
722 sprintmode(statbuf.st_mode));
723 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
724 (unsigned long) statbuf.st_nlink,
725 (unsigned long) statbuf.st_uid,
726 (unsigned long) statbuf.st_gid);
727 tprintf("st_blksize=%lu, ",
728 (unsigned long) statbuf.st_blksize);
729 tprintf("st_blocks=%lu, ",
730 (unsigned long) statbuf.st_blocks);
731 }
732 else
733 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
734 switch (statbuf.st_mode & S_IFMT) {
735 case S_IFCHR: case S_IFBLK:
736 tprintf("st_rdev=makedev(%lu, %lu), ",
737 (unsigned long) major(statbuf.st_rdev),
738 (unsigned long) minor(statbuf.st_rdev));
739 break;
740 default:
741 tprintf("st_size=%lu, ", statbuf.st_size);
742 break;
743 }
744 if (!abbrev(tcp)) {
745 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
746 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
747 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
748 tprintf("}");
749 }
750 else
751 tprintf("...}");
752}
753#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000754#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000755
Roland McGrathd9f816f2004-09-04 03:39:20 +0000756const struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000757#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000758 { UF_NODUMP, "UF_NODUMP" },
759 { UF_IMMUTABLE, "UF_IMMUTABLE" },
760 { UF_APPEND, "UF_APPEND" },
761 { UF_OPAQUE, "UF_OPAQUE" },
762 { UF_NOUNLINK, "UF_NOUNLINK" },
763 { SF_ARCHIVED, "SF_ARCHIVED" },
764 { SF_IMMUTABLE, "SF_IMMUTABLE" },
765 { SF_APPEND, "SF_APPEND" },
766 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000767#elif UNIXWARE >= 2
768#ifdef _S_ISMLD
769 { _S_ISMLD, "_S_ISMLD" },
770#endif
771#ifdef _S_ISMOUNTED
772 { _S_ISMOUNTED, "_S_ISMOUNTED" },
773#endif
774#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000775 { 0, NULL },
776};
777
John Hughesc0fc3fd2001-03-08 16:10:40 +0000778#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000779int
780sys_chflags(tcp)
781struct tcb *tcp;
782{
783 if (entering(tcp)) {
784 printpath(tcp, tcp->u_arg[0]);
785 tprintf(", ");
786 if (tcp->u_arg[1])
787 printflags(fileflags, tcp->u_arg[1]);
788 else
789 tprintf("0");
790 }
791 return 0;
792}
793
794int
795sys_fchflags(tcp)
796struct tcb *tcp;
797{
798 if (entering(tcp)) {
799 tprintf("%ld, ", tcp->u_arg[0]);
800 if (tcp->u_arg[1])
801 printflags(fileflags, tcp->u_arg[1]);
802 else
803 tprintf("0");
804 }
805 return 0;
806}
807#endif
808
John Hughes70623be2001-03-08 13:59:00 +0000809#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000810static void
811realprintstat(tcp, statbuf)
812struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000813struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000814{
815 if (!abbrev(tcp)) {
816 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
817 (unsigned long) major(statbuf->st_dev),
818 (unsigned long) minor(statbuf->st_dev),
819 (unsigned long) statbuf->st_ino,
820 sprintmode(statbuf->st_mode));
821 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
822 (unsigned long) statbuf->st_nlink,
823 (unsigned long) statbuf->st_uid,
824 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000825#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000826 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000827#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
828#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000829 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000830#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000831 }
832 else
833 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
834 switch (statbuf->st_mode & S_IFMT) {
835 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000836#ifdef HAVE_STRUCT_STAT_ST_RDEV
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000837 tprintf("st_rdev=makedev(%lu, %lu), ",
838 (unsigned long) major(statbuf->st_rdev),
839 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000840#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000841 tprintf("st_size=makedev(%lu, %lu), ",
842 (unsigned long) major(statbuf->st_size),
843 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000844#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000845 break;
846 default:
847 tprintf("st_size=%lu, ", statbuf->st_size);
848 break;
849 }
850 if (!abbrev(tcp)) {
851 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
852 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000853 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000854#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000855 tprintf(", st_flags=");
856 if (statbuf->st_flags) {
857 printflags(fileflags, statbuf->st_flags);
858 } else
859 tprintf("0");
860#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000861#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000862 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
863#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000864#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000865 tprintf(", st_level=%ld", statbuf->st_level);
866#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000867#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000868 tprintf(", st_fstype=%.*s",
869 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
870#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000871#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000872 tprintf(", st_gen=%u", statbuf->st_gen);
873#endif
874 tprintf("}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000875 }
876 else
877 tprintf("...}");
878}
879
Nate Sammons771a6ff1999-04-05 22:39:31 +0000880
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000881static void
882printstat(tcp, addr)
883struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000884long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000885{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000886 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000887
888#ifdef LINUXSPARC
889 if (current_personality == 1) {
890 printstatsol(tcp, addr);
891 return;
892 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000893#ifdef SPARC64
894 else if (current_personality == 2) {
895 printstat_sparc64(tcp, addr);
896 return;
897 }
898#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000899#endif /* LINUXSPARC */
900
901 if (!addr) {
902 tprintf("NULL");
903 return;
904 }
905 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000906 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000907 return;
908 }
909 if (umove(tcp, addr, &statbuf) < 0) {
910 tprintf("{...}");
911 return;
912 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000913
914 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000915}
John Hughes70623be2001-03-08 13:59:00 +0000916#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000917
Wichert Akkermanc7926982000-04-10 22:22:31 +0000918#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000919static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000920printstat64(tcp, addr)
921struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000922long addr;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000923{
924 struct stat64 statbuf;
925
926#ifdef LINUXSPARC
927 if (current_personality == 1) {
928 printstatsol(tcp, addr);
929 return;
930 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000931#ifdef SPARC64
932 else if (current_personality == 2) {
933 printstat_sparc64(tcp, addr);
934 return;
935 }
936#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000937#endif /* LINUXSPARC */
938
939 if (!addr) {
940 tprintf("NULL");
941 return;
942 }
943 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000944 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000945 return;
946 }
947 if (umove(tcp, addr, &statbuf) < 0) {
948 tprintf("{...}");
949 return;
950 }
951
952 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +0000953#ifdef HAVE_LONG_LONG
954 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
955#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000956 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +0000957#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000958 (unsigned long) major(statbuf.st_dev),
959 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +0000960#ifdef HAVE_LONG_LONG
961 (unsigned long long) statbuf.st_ino,
962#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000963 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +0000964#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000965 sprintmode(statbuf.st_mode));
966 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
967 (unsigned long) statbuf.st_nlink,
968 (unsigned long) statbuf.st_uid,
969 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000970#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000971 tprintf("st_blksize=%lu, ",
972 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000973#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
974#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000975 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000976#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000977 }
978 else
979 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
980 switch (statbuf.st_mode & S_IFMT) {
981 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000982#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000983 tprintf("st_rdev=makedev(%lu, %lu), ",
984 (unsigned long) major(statbuf.st_rdev),
985 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000986#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000987 tprintf("st_size=makedev(%lu, %lu), ",
988 (unsigned long) major(statbuf.st_size),
989 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000990#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000991 break;
992 default:
993 tprintf("st_size=%llu, ", statbuf.st_size);
994 break;
995 }
996 if (!abbrev(tcp)) {
997 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
998 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000999 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +00001000#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +00001001 tprintf(", st_flags=");
John Hughesb8c9f772001-03-07 16:53:07 +00001002 if (statbuf.st_flags) {
1003 printflags(fileflags, statbuf.st_flags);
1004 } else
1005 tprintf("0");
John Hughesc0fc3fd2001-03-08 16:10:40 +00001006#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001007#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +00001008 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1009#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001010#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +00001011 tprintf(", st_level=%ld", statbuf.st_level);
1012#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001013#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +00001014 tprintf(", st_fstype=%.*s",
1015 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1016#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001017#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001018 tprintf(", st_gen=%u", statbuf.st_gen);
1019#endif
1020 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001021 }
1022 else
1023 tprintf("...}");
1024}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001025#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001026
Roland McGrath79db8af2003-06-27 21:20:09 +00001027#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001028static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001029convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001030const struct __old_kernel_stat *oldbuf;
1031struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001032{
1033 newbuf->st_dev=oldbuf->st_dev;
1034 newbuf->st_ino=oldbuf->st_ino;
1035 newbuf->st_mode=oldbuf->st_mode;
1036 newbuf->st_nlink=oldbuf->st_nlink;
1037 newbuf->st_uid=oldbuf->st_uid;
1038 newbuf->st_gid=oldbuf->st_gid;
1039 newbuf->st_rdev=oldbuf->st_rdev;
1040 newbuf->st_size=oldbuf->st_size;
1041 newbuf->st_atime=oldbuf->st_atime;
1042 newbuf->st_mtime=oldbuf->st_mtime;
1043 newbuf->st_ctime=oldbuf->st_ctime;
1044 newbuf->st_blksize=0; /* not supported in old_stat */
1045 newbuf->st_blocks=0; /* not supported in old_stat */
1046}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001047
1048
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001049static void
1050printoldstat(tcp, addr)
1051struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001052long addr;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001053{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001054 struct __old_kernel_stat statbuf;
1055 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001056
1057#ifdef LINUXSPARC
1058 if (current_personality == 1) {
1059 printstatsol(tcp, addr);
1060 return;
1061 }
1062#endif /* LINUXSPARC */
1063
1064 if (!addr) {
1065 tprintf("NULL");
1066 return;
1067 }
1068 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001069 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001070 return;
1071 }
1072 if (umove(tcp, addr, &statbuf) < 0) {
1073 tprintf("{...}");
1074 return;
1075 }
1076
1077 convertoldstat(&statbuf, &newstatbuf);
1078 realprintstat(tcp, &newstatbuf);
1079}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001080#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001081
John Hughes70623be2001-03-08 13:59:00 +00001082#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001083int
1084sys_stat(tcp)
1085struct tcb *tcp;
1086{
1087 if (entering(tcp)) {
1088 printpath(tcp, tcp->u_arg[0]);
1089 tprintf(", ");
1090 } else {
1091 printstat(tcp, tcp->u_arg[1]);
1092 }
1093 return 0;
1094}
John Hughesb8c9f772001-03-07 16:53:07 +00001095#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001096
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001097int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001098sys_stat64(tcp)
1099struct tcb *tcp;
1100{
1101#ifdef HAVE_STAT64
1102 if (entering(tcp)) {
1103 printpath(tcp, tcp->u_arg[0]);
1104 tprintf(", ");
1105 } else {
1106 printstat64(tcp, tcp->u_arg[1]);
1107 }
1108 return 0;
1109#else
1110 return printargs(tcp);
1111#endif
1112}
1113
Roland McGrath79db8af2003-06-27 21:20:09 +00001114#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001115int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001116sys_oldstat(tcp)
1117struct tcb *tcp;
1118{
1119 if (entering(tcp)) {
1120 printpath(tcp, tcp->u_arg[0]);
1121 tprintf(", ");
1122 } else {
1123 printoldstat(tcp, tcp->u_arg[1]);
1124 }
1125 return 0;
1126}
Roland McGrath79db8af2003-06-27 21:20:09 +00001127#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001128
John Hughes70623be2001-03-08 13:59:00 +00001129#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001130int
1131sys_fstat(tcp)
1132struct tcb *tcp;
1133{
1134 if (entering(tcp))
1135 tprintf("%ld, ", tcp->u_arg[0]);
1136 else {
1137 printstat(tcp, tcp->u_arg[1]);
1138 }
1139 return 0;
1140}
John Hughesb8c9f772001-03-07 16:53:07 +00001141#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001142
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001143int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001144sys_fstat64(tcp)
1145struct tcb *tcp;
1146{
1147#ifdef HAVE_STAT64
1148 if (entering(tcp))
1149 tprintf("%ld, ", tcp->u_arg[0]);
1150 else {
1151 printstat64(tcp, tcp->u_arg[1]);
1152 }
1153 return 0;
1154#else
1155 return printargs(tcp);
1156#endif
1157}
1158
Roland McGrath79db8af2003-06-27 21:20:09 +00001159#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001160int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001161sys_oldfstat(tcp)
1162struct tcb *tcp;
1163{
1164 if (entering(tcp))
1165 tprintf("%ld, ", tcp->u_arg[0]);
1166 else {
1167 printoldstat(tcp, tcp->u_arg[1]);
1168 }
1169 return 0;
1170}
Roland McGrath79db8af2003-06-27 21:20:09 +00001171#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001172
John Hughes70623be2001-03-08 13:59:00 +00001173#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001174int
1175sys_lstat(tcp)
1176struct tcb *tcp;
1177{
1178 if (entering(tcp)) {
1179 printpath(tcp, tcp->u_arg[0]);
1180 tprintf(", ");
1181 } else {
1182 printstat(tcp, tcp->u_arg[1]);
1183 }
1184 return 0;
1185}
John Hughesb8c9f772001-03-07 16:53:07 +00001186#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001187
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001188int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001189sys_lstat64(tcp)
1190struct tcb *tcp;
1191{
1192#ifdef HAVE_STAT64
1193 if (entering(tcp)) {
1194 printpath(tcp, tcp->u_arg[0]);
1195 tprintf(", ");
1196 } else {
1197 printstat64(tcp, tcp->u_arg[1]);
1198 }
1199 return 0;
1200#else
1201 return printargs(tcp);
1202#endif
1203}
1204
Roland McGrath79db8af2003-06-27 21:20:09 +00001205#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001206int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001207sys_oldlstat(tcp)
1208struct tcb *tcp;
1209{
1210 if (entering(tcp)) {
1211 printpath(tcp, tcp->u_arg[0]);
1212 tprintf(", ");
1213 } else {
1214 printoldstat(tcp, tcp->u_arg[1]);
1215 }
1216 return 0;
1217}
Roland McGrath79db8af2003-06-27 21:20:09 +00001218#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001219
1220
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001221#if defined(SVR4) || defined(LINUXSPARC)
1222
1223int
1224sys_xstat(tcp)
1225struct tcb *tcp;
1226{
1227 if (entering(tcp)) {
1228 tprintf("%ld, ", tcp->u_arg[0]);
1229 printpath(tcp, tcp->u_arg[1]);
1230 tprintf(", ");
1231 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001232#ifdef _STAT64_VER
1233 if (tcp->u_arg[0] == _STAT64_VER)
1234 printstat64 (tcp, tcp->u_arg[2]);
1235 else
1236#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001237 printstat(tcp, tcp->u_arg[2]);
1238 }
1239 return 0;
1240}
1241
1242int
1243sys_fxstat(tcp)
1244struct tcb *tcp;
1245{
1246 if (entering(tcp))
1247 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1248 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001249#ifdef _STAT64_VER
1250 if (tcp->u_arg[0] == _STAT64_VER)
1251 printstat64 (tcp, tcp->u_arg[2]);
1252 else
1253#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001254 printstat(tcp, tcp->u_arg[2]);
1255 }
1256 return 0;
1257}
1258
1259int
1260sys_lxstat(tcp)
1261struct tcb *tcp;
1262{
1263 if (entering(tcp)) {
1264 tprintf("%ld, ", tcp->u_arg[0]);
1265 printpath(tcp, tcp->u_arg[1]);
1266 tprintf(", ");
1267 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001268#ifdef _STAT64_VER
1269 if (tcp->u_arg[0] == _STAT64_VER)
1270 printstat64 (tcp, tcp->u_arg[2]);
1271 else
1272#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001273 printstat(tcp, tcp->u_arg[2]);
1274 }
1275 return 0;
1276}
1277
1278int
1279sys_xmknod(tcp)
1280struct tcb *tcp;
1281{
1282 int mode = tcp->u_arg[2];
1283
1284 if (entering(tcp)) {
1285 tprintf("%ld, ", tcp->u_arg[0]);
1286 printpath(tcp, tcp->u_arg[1]);
1287 tprintf(", %s", sprintmode(mode));
1288 switch (mode & S_IFMT) {
1289 case S_IFCHR: case S_IFBLK:
1290#ifdef LINUXSPARC
1291 tprintf(", makedev(%lu, %lu)",
1292 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1293 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001294#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001295 tprintf(", makedev(%lu, %lu)",
1296 (unsigned long) major(tcp->u_arg[3]),
1297 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001298#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001299 break;
1300 default:
1301 break;
1302 }
1303 }
1304 return 0;
1305}
1306
Wichert Akkerman8829a551999-06-11 13:18:40 +00001307#ifdef HAVE_SYS_ACL_H
1308
1309#include <sys/acl.h>
1310
Roland McGrathd9f816f2004-09-04 03:39:20 +00001311const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001312#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001313 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001314#endif
1315#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001316 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001317#endif
1318#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001319 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001320#endif
1321#ifdef ACL_GET
1322 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001323#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001324#ifdef ACL_SET
1325 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001326#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001327#ifdef ACL_CNT
1328 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001329#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001330 { 0, NULL },
1331};
1332
1333int
1334sys_acl(tcp)
1335struct tcb *tcp;
1336{
1337 if (entering(tcp)) {
1338 printpath(tcp, tcp->u_arg[0]);
1339 tprintf(", ");
1340 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1341 tprintf(", %ld", tcp->u_arg[2]);
1342 /*
1343 * FIXME - dump out the list of aclent_t's pointed to
1344 * by "tcp->u_arg[3]" if it's not NULL.
1345 */
1346 if (tcp->u_arg[3])
1347 tprintf(", %#lx", tcp->u_arg[3]);
1348 else
1349 tprintf(", NULL");
1350 }
1351 return 0;
1352}
1353
1354
1355int
1356sys_facl(tcp)
1357struct tcb *tcp;
1358{
1359 if (entering(tcp)) {
1360 tprintf("%ld, ", tcp->u_arg[0]);
1361 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1362 tprintf(", %ld", tcp->u_arg[2]);
1363 /*
1364 * FIXME - dump out the list of aclent_t's pointed to
1365 * by "tcp->u_arg[3]" if it's not NULL.
1366 */
1367 if (tcp->u_arg[3])
1368 tprintf(", %#lx", tcp->u_arg[3]);
1369 else
1370 tprintf(", NULL");
1371 }
1372 return 0;
1373}
1374
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001375
Roland McGrathd9f816f2004-09-04 03:39:20 +00001376const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001377#ifdef IPC_SHM
1378 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001379#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001380#ifdef IPC_SEM
1381 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001382#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001383#ifdef IPC_MSG
1384 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001385#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001386 { 0, NULL },
1387};
1388
1389
1390int
1391sys_aclipc(tcp)
1392struct tcb *tcp;
1393{
1394 if (entering(tcp)) {
1395 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1396 tprintf(", %#lx, ", tcp->u_arg[1]);
1397 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1398 tprintf(", %ld", tcp->u_arg[3]);
1399 /*
1400 * FIXME - dump out the list of aclent_t's pointed to
1401 * by "tcp->u_arg[4]" if it's not NULL.
1402 */
1403 if (tcp->u_arg[4])
1404 tprintf(", %#lx", tcp->u_arg[4]);
1405 else
1406 tprintf(", NULL");
1407 }
1408 return 0;
1409}
1410
1411
1412
Wichert Akkerman8829a551999-06-11 13:18:40 +00001413#endif /* HAVE_SYS_ACL_H */
1414
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001415#endif /* SVR4 || LINUXSPARC */
1416
Michal Ludvig53b320f2002-09-23 13:30:09 +00001417#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001418
Roland McGrathd9f816f2004-09-04 03:39:20 +00001419static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001420 { 0x73757245, "CODA_SUPER_MAGIC" },
1421 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1422 { 0x1373, "DEVFS_SUPER_MAGIC" },
1423 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1424 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001425 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1426 { 0xef53, "EXT2_SUPER_MAGIC" },
1427 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001428 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001429 { 0x9660, "ISOFS_SUPER_MAGIC" },
1430 { 0x137f, "MINIX_SUPER_MAGIC" },
1431 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001432 { 0x2468, "MINIX2_SUPER_MAGIC" },
1433 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001434 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001435 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001436 { 0x6969, "NFS_SUPER_MAGIC" },
1437 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001438 { 0x002f, "QNX4_SUPER_MAGIC" },
1439 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1440 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1441 { 0x517b, "SMB_SUPER_MAGIC" },
1442 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1443 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1444 { 0x00011954, "UFS_MAGIC" },
1445 { 0x54190100, "UFS_CIGAM" },
1446 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001447 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001448 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001449 { 0, NULL },
1450};
1451
Michal Ludvig53b320f2002-09-23 13:30:09 +00001452#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001453
1454#ifndef SVR4
1455
Roland McGrathf9c49b22004-10-06 22:11:54 +00001456static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001457sprintfstype(magic)
1458int magic;
1459{
1460 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001461#ifdef LINUX
Roland McGrathf9c49b22004-10-06 22:11:54 +00001462 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001463
1464 s = xlookup(fsmagic, magic);
1465 if (s) {
1466 sprintf(buf, "\"%s\"", s);
1467 return buf;
1468 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001469#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001470 sprintf(buf, "%#x", magic);
1471 return buf;
1472}
1473
1474static void
1475printstatfs(tcp, addr)
1476struct tcb *tcp;
1477long addr;
1478{
1479 struct statfs statbuf;
1480
1481 if (syserror(tcp) || !verbose(tcp)) {
1482 tprintf("%#lx", addr);
1483 return;
1484 }
1485 if (umove(tcp, addr, &statbuf) < 0) {
1486 tprintf("{...}");
1487 return;
1488 }
1489#ifdef ALPHA
1490
1491 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1492 sprintfstype(statbuf.f_type),
1493 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001494 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1495 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1496 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1497 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001498#else /* !ALPHA */
1499 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1500 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001501 (unsigned long)statbuf.f_bsize,
1502 (unsigned long)statbuf.f_blocks,
1503 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001504 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1505 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001506 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001507 (unsigned long)statbuf.f_ffree,
1508 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001509#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001510 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001511#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001512#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001513#ifdef _STATFS_F_FRSIZE
1514 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1515#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001516 tprintf("}");
1517}
1518
1519int
1520sys_statfs(tcp)
1521struct tcb *tcp;
1522{
1523 if (entering(tcp)) {
1524 printpath(tcp, tcp->u_arg[0]);
1525 tprintf(", ");
1526 } else {
1527 printstatfs(tcp, tcp->u_arg[1]);
1528 }
1529 return 0;
1530}
1531
1532int
1533sys_fstatfs(tcp)
1534struct tcb *tcp;
1535{
1536 if (entering(tcp)) {
1537 tprintf("%lu, ", tcp->u_arg[0]);
1538 } else {
1539 printstatfs(tcp, tcp->u_arg[1]);
1540 }
1541 return 0;
1542}
1543
Roland McGrathab147c52003-07-17 09:03:02 +00001544#ifdef LINUX
1545static void
1546printstatfs64(tcp, addr)
1547struct tcb *tcp;
1548long addr;
1549{
1550 struct statfs64 statbuf;
1551
1552 if (syserror(tcp) || !verbose(tcp)) {
1553 tprintf("%#lx", addr);
1554 return;
1555 }
1556 if (umove(tcp, addr, &statbuf) < 0) {
1557 tprintf("{...}");
1558 return;
1559 }
1560#ifdef ALPHA
1561
1562 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1563 sprintfstype(statbuf.f_type),
1564 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1565 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1566 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1567 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1568 statbuf.f_namelen);
1569#else /* !ALPHA */
1570 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1571 sprintfstype(statbuf.f_type),
1572 (unsigned long)statbuf.f_bsize,
1573 (unsigned long)statbuf.f_blocks,
1574 (unsigned long)statbuf.f_bfree);
1575 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1576 (unsigned long)statbuf.f_bavail,
1577 (unsigned long)statbuf.f_files,
1578 (unsigned long)statbuf.f_ffree,
1579 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1580 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1581#endif /* !ALPHA */
1582#ifdef _STATFS_F_FRSIZE
1583 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1584#endif
1585 tprintf("}");
1586}
1587
1588int
1589sys_statfs64(tcp)
1590struct tcb *tcp;
1591{
1592 if (entering(tcp)) {
1593 printpath(tcp, tcp->u_arg[0]);
1594 tprintf(", %lu, ", tcp->u_arg[1]);
1595 } else {
1596 if (tcp->u_arg[1] == sizeof (struct statfs64))
1597 printstatfs64(tcp, tcp->u_arg[2]);
1598 else
1599 tprintf("{???}");
1600 }
1601 return 0;
1602}
1603
1604int
1605sys_fstatfs64(tcp)
1606struct tcb *tcp;
1607{
1608 if (entering(tcp)) {
1609 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1610 } else {
1611 if (tcp->u_arg[1] == sizeof (struct statfs64))
1612 printstatfs64(tcp, tcp->u_arg[2]);
1613 else
1614 tprintf("{???}");
1615 }
1616 return 0;
1617}
1618#endif
1619
Michal Ludvig53b320f2002-09-23 13:30:09 +00001620#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001621
1622int
1623osf_statfs(tcp)
1624struct tcb *tcp;
1625{
1626 if (entering(tcp)) {
1627 printpath(tcp, tcp->u_arg[0]);
1628 tprintf(", ");
1629 } else {
1630 printstatfs(tcp, tcp->u_arg[1]);
1631 tprintf(", %lu", tcp->u_arg[2]);
1632 }
1633 return 0;
1634}
1635
1636int
1637osf_fstatfs(tcp)
1638struct tcb *tcp;
1639{
1640 if (entering(tcp)) {
1641 tprintf("%lu, ", tcp->u_arg[0]);
1642 } else {
1643 printstatfs(tcp, tcp->u_arg[1]);
1644 tprintf(", %lu", tcp->u_arg[2]);
1645 }
1646 return 0;
1647}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001648#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001649
1650#endif /* !SVR4 */
1651
1652#ifdef SUNOS4
1653
1654int
1655sys_ustat(tcp)
1656struct tcb *tcp;
1657{
1658 struct ustat statbuf;
1659
1660 if (entering(tcp)) {
1661 tprintf("makedev(%lu, %lu), ",
1662 (long) major(tcp->u_arg[0]),
1663 (long) minor(tcp->u_arg[0]));
1664 }
1665 else {
1666 if (syserror(tcp) || !verbose(tcp))
1667 tprintf("%#lx", tcp->u_arg[1]);
1668 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1669 tprintf("{...}");
1670 else {
1671 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1672 statbuf.f_tfree, statbuf.f_tinode);
1673 tprintf("f_fname=\"%.*s\", ",
1674 (int) sizeof(statbuf.f_fname),
1675 statbuf.f_fname);
1676 tprintf("f_fpack=\"%.*s\"}",
1677 (int) sizeof(statbuf.f_fpack),
1678 statbuf.f_fpack);
1679 }
1680 }
1681 return 0;
1682}
1683
1684#endif /* SUNOS4 */
1685
Wichert Akkermanc7926982000-04-10 22:22:31 +00001686int
1687sys_pivotroot(tcp)
1688struct tcb *tcp;
1689{
1690 if (entering(tcp)) {
1691 printpath(tcp, tcp->u_arg[0]);
1692 tprintf(", ");
1693 printpath(tcp, tcp->u_arg[1]);
1694 }
1695 return 0;
1696}
1697
1698
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001699/* directory */
1700int
1701sys_chdir(tcp)
1702struct tcb *tcp;
1703{
1704 if (entering(tcp)) {
1705 printpath(tcp, tcp->u_arg[0]);
1706 }
1707 return 0;
1708}
1709
1710int
1711sys_mkdir(tcp)
1712struct tcb *tcp;
1713{
1714 if (entering(tcp)) {
1715 printpath(tcp, tcp->u_arg[0]);
1716 tprintf(", %#lo", tcp->u_arg[1]);
1717 }
1718 return 0;
1719}
1720
1721int
1722sys_rmdir(tcp)
1723struct tcb *tcp;
1724{
1725 if (entering(tcp)) {
1726 printpath(tcp, tcp->u_arg[0]);
1727 }
1728 return 0;
1729}
1730
1731int
1732sys_fchdir(tcp)
1733struct tcb *tcp;
1734{
1735 if (entering(tcp)) {
1736 tprintf("%ld", tcp->u_arg[0]);
1737 }
1738 return 0;
1739}
1740
1741int
1742sys_chroot(tcp)
1743struct tcb *tcp;
1744{
1745 if (entering(tcp)) {
1746 printpath(tcp, tcp->u_arg[0]);
1747 }
1748 return 0;
1749}
1750
1751int
1752sys_fchroot(tcp)
1753struct tcb *tcp;
1754{
1755 if (entering(tcp)) {
1756 tprintf("%ld", tcp->u_arg[0]);
1757 }
1758 return 0;
1759}
1760
1761int
1762sys_link(tcp)
1763struct tcb *tcp;
1764{
1765 if (entering(tcp)) {
1766 printpath(tcp, tcp->u_arg[0]);
1767 tprintf(", ");
1768 printpath(tcp, tcp->u_arg[1]);
1769 }
1770 return 0;
1771}
1772
1773int
1774sys_unlink(tcp)
1775struct tcb *tcp;
1776{
1777 if (entering(tcp)) {
1778 printpath(tcp, tcp->u_arg[0]);
1779 }
1780 return 0;
1781}
1782
1783int
1784sys_symlink(tcp)
1785struct tcb *tcp;
1786{
1787 if (entering(tcp)) {
1788 printpath(tcp, tcp->u_arg[0]);
1789 tprintf(", ");
1790 printpath(tcp, tcp->u_arg[1]);
1791 }
1792 return 0;
1793}
1794
1795int
1796sys_readlink(tcp)
1797struct tcb *tcp;
1798{
1799 if (entering(tcp)) {
1800 printpath(tcp, tcp->u_arg[0]);
1801 tprintf(", ");
1802 } else {
1803 if (syserror(tcp))
1804 tprintf("%#lx", tcp->u_arg[1]);
1805 else
1806 printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
1807 tprintf(", %lu", tcp->u_arg[2]);
1808 }
1809 return 0;
1810}
1811
1812int
1813sys_rename(tcp)
1814struct tcb *tcp;
1815{
1816 if (entering(tcp)) {
1817 printpath(tcp, tcp->u_arg[0]);
1818 tprintf(", ");
1819 printpath(tcp, tcp->u_arg[1]);
1820 }
1821 return 0;
1822}
1823
1824int
1825sys_chown(tcp)
1826struct tcb *tcp;
1827{
1828 if (entering(tcp)) {
1829 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001830 printuid(", ", tcp->u_arg[1]);
1831 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001832 }
1833 return 0;
1834}
1835
1836int
1837sys_fchown(tcp)
1838struct tcb *tcp;
1839{
1840 if (entering(tcp)) {
Roland McGrath6bc12202003-11-13 22:32:27 +00001841 tprintf("%ld", tcp->u_arg[0]);
1842 printuid(", ", tcp->u_arg[1]);
1843 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001844 }
1845 return 0;
1846}
1847
1848int
1849sys_chmod(tcp)
1850struct tcb *tcp;
1851{
1852 if (entering(tcp)) {
1853 printpath(tcp, tcp->u_arg[0]);
1854 tprintf(", %#lo", tcp->u_arg[1]);
1855 }
1856 return 0;
1857}
1858
1859int
1860sys_fchmod(tcp)
1861struct tcb *tcp;
1862{
1863 if (entering(tcp)) {
1864 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
1865 }
1866 return 0;
1867}
1868
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001869#ifdef ALPHA
1870int
1871sys_osf_utimes(tcp)
1872struct tcb *tcp;
1873{
1874 if (entering(tcp)) {
1875 printpath(tcp, tcp->u_arg[0]);
1876 tprintf(", ");
1877 printtv32(tcp, tcp->u_arg[1]);
1878 }
1879 return 0;
1880}
1881#endif
1882
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001883int
1884sys_utimes(tcp)
1885struct tcb *tcp;
1886{
1887 if (entering(tcp)) {
1888 printpath(tcp, tcp->u_arg[0]);
1889 tprintf(", ");
1890 printtv(tcp, tcp->u_arg[1]);
1891 }
1892 return 0;
1893}
1894
1895int
1896sys_utime(tcp)
1897struct tcb *tcp;
1898{
1899 long ut[2];
1900
1901 if (entering(tcp)) {
1902 printpath(tcp, tcp->u_arg[0]);
1903 tprintf(", ");
1904 if (!tcp->u_arg[1])
1905 tprintf("NULL");
1906 else if (!verbose(tcp))
1907 tprintf("%#lx", tcp->u_arg[1]);
1908 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
1909 (char *) ut) < 0)
1910 tprintf("[?, ?]");
1911 else {
1912 tprintf("[%s,", sprinttime(ut[0]));
1913 tprintf(" %s]", sprinttime(ut[1]));
1914 }
1915 }
1916 return 0;
1917}
1918
1919int
1920sys_mknod(tcp)
1921struct tcb *tcp;
1922{
1923 int mode = tcp->u_arg[1];
1924
1925 if (entering(tcp)) {
1926 printpath(tcp, tcp->u_arg[0]);
1927 tprintf(", %s", sprintmode(mode));
1928 switch (mode & S_IFMT) {
1929 case S_IFCHR: case S_IFBLK:
1930#ifdef LINUXSPARC
1931 if (current_personality == 1)
1932 tprintf(", makedev(%lu, %lu)",
1933 (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
1934 (unsigned long) (tcp->u_arg[2] & 0x3ffff));
1935 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00001936#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001937 tprintf(", makedev(%lu, %lu)",
1938 (unsigned long) major(tcp->u_arg[2]),
1939 (unsigned long) minor(tcp->u_arg[2]));
1940 break;
1941 default:
1942 break;
1943 }
1944 }
1945 return 0;
1946}
1947
1948int
1949sys_mkfifo(tcp)
1950struct tcb *tcp;
1951{
1952 if (entering(tcp)) {
1953 printpath(tcp, tcp->u_arg[0]);
1954 tprintf(", %#lo", tcp->u_arg[1]);
1955 }
1956 return 0;
1957}
1958
1959int
1960sys_fsync(tcp)
1961struct tcb *tcp;
1962{
1963 if (entering(tcp)) {
1964 tprintf("%ld", tcp->u_arg[0]);
1965 }
1966 return 0;
1967}
1968
Michal Ludvig53b320f2002-09-23 13:30:09 +00001969#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001970
1971static void
1972printdir(tcp, addr)
1973struct tcb *tcp;
1974long addr;
1975{
1976 struct dirent d;
1977
1978 if (!verbose(tcp)) {
1979 tprintf("%#lx", addr);
1980 return;
1981 }
1982 if (umove(tcp, addr, &d) < 0) {
1983 tprintf("{...}");
1984 return;
1985 }
1986 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001987 tprintf("d_name=");
1988 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
1989 tprintf("}");
1990}
1991
1992int
1993sys_readdir(tcp)
1994struct tcb *tcp;
1995{
1996 if (entering(tcp)) {
1997 tprintf("%lu, ", tcp->u_arg[0]);
1998 } else {
1999 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2000 tprintf("%#lx", tcp->u_arg[1]);
2001 else
2002 printdir(tcp, tcp->u_arg[1]);
2003 /* Not much point in printing this out, it is always 1. */
2004 if (tcp->u_arg[2] != 1)
2005 tprintf(", %lu", tcp->u_arg[2]);
2006 }
2007 return 0;
2008}
2009
Michal Ludvig53b320f2002-09-23 13:30:09 +00002010#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002011
Roland McGrath40542842004-01-13 09:47:49 +00002012#if defined FREEBSD || defined LINUX
Roland McGrathd9f816f2004-09-04 03:39:20 +00002013const struct xlat direnttypes[] = {
Roland McGrath40542842004-01-13 09:47:49 +00002014 { DT_UNKNOWN, "DT_UNKNOWN" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002015 { DT_FIFO, "DT_FIFO" },
2016 { DT_CHR, "DT_CHR" },
2017 { DT_DIR, "DT_DIR" },
2018 { DT_BLK, "DT_BLK" },
2019 { DT_REG, "DT_REG" },
2020 { DT_LNK, "DT_LNK" },
2021 { DT_SOCK, "DT_SOCK" },
2022 { DT_WHT, "DT_WHT" },
2023 { 0, NULL },
2024};
2025
2026#endif
2027
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002028int
2029sys_getdents(tcp)
2030struct tcb *tcp;
2031{
2032 int i, len, dents = 0;
2033 char *buf;
2034
2035 if (entering(tcp)) {
2036 tprintf("%lu, ", tcp->u_arg[0]);
2037 return 0;
2038 }
2039 if (syserror(tcp) || !verbose(tcp)) {
2040 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2041 return 0;
2042 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002043 len = tcp->u_rval;
2044 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002045 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2046 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002047 return 0;
2048 }
2049 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002050 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002051 free(buf);
2052 return 0;
2053 }
2054 if (!abbrev(tcp))
2055 tprintf("{");
2056 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002057 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002058#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002059 if (!abbrev(tcp)) {
2060 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2061 i ? " " : "", d->d_ino, d->d_off);
2062 tprintf("d_reclen=%u, d_name=\"%s\"}",
2063 d->d_reclen, d->d_name);
2064 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002065#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002066#ifdef SVR4
2067 if (!abbrev(tcp)) {
2068 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002069 i ? " " : "",
2070 (unsigned long) d->d_ino,
2071 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002072 tprintf("d_reclen=%u, d_name=\"%s\"}",
2073 d->d_reclen, d->d_name);
2074 }
2075#endif /* SVR4 */
2076#ifdef SUNOS4
2077 if (!abbrev(tcp)) {
2078 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2079 i ? " " : "", d->d_off, d->d_fileno,
2080 d->d_reclen);
2081 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2082 d->d_namlen, d->d_namlen, d->d_name);
2083 }
2084#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002085#ifdef FREEBSD
2086 if (!abbrev(tcp)) {
2087 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2088 i ? " " : "", d->d_fileno, d->d_reclen);
2089 printxval(direnttypes, d->d_type, "DT_???");
2090 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2091 d->d_namlen, d->d_namlen, d->d_name);
2092 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002093#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002094 if (!d->d_reclen) {
2095 tprintf("/* d_reclen == 0, problem here */");
2096 break;
2097 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002098 i += d->d_reclen;
2099 dents++;
2100 }
2101 if (!abbrev(tcp))
2102 tprintf("}");
2103 else
2104 tprintf("/* %u entries */", dents);
2105 tprintf(", %lu", tcp->u_arg[2]);
2106 free(buf);
2107 return 0;
2108}
2109
John Hughesbdf48f52001-03-06 15:08:09 +00002110
2111#if _LFS64_LARGEFILE
2112int
2113sys_getdents64(tcp)
2114struct tcb *tcp;
2115{
2116 int i, len, dents = 0;
2117 char *buf;
2118
2119 if (entering(tcp)) {
2120 tprintf("%lu, ", tcp->u_arg[0]);
2121 return 0;
2122 }
2123 if (syserror(tcp) || !verbose(tcp)) {
2124 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2125 return 0;
2126 }
2127 len = tcp->u_rval;
2128 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002129 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2130 fprintf(stderr, "out of memory\n");
John Hughesbdf48f52001-03-06 15:08:09 +00002131 return 0;
2132 }
2133 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002134 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +00002135 free(buf);
2136 return 0;
2137 }
2138 if (!abbrev(tcp))
2139 tprintf("{");
2140 for (i = 0; i < len;) {
2141 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002142#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002143 if (!abbrev(tcp)) {
Roland McGrath92053242004-01-13 10:16:47 +00002144 tprintf("%s{d_ino=%llu, d_off=%llu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002145 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002146 d->d_ino,
2147 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002148#ifdef LINUX
2149 tprintf("d_type=");
2150 printxval(direnttypes, d->d_type, "DT_???");
2151 tprintf(", ");
2152#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002153 tprintf("d_reclen=%u, d_name=\"%s\"}",
2154 d->d_reclen, d->d_name);
2155 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002156#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002157#ifdef SUNOS4
2158 if (!abbrev(tcp)) {
2159 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2160 i ? " " : "", d->d_off, d->d_fileno,
2161 d->d_reclen);
2162 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2163 d->d_namlen, d->d_namlen, d->d_name);
2164 }
2165#endif /* SUNOS4 */
2166 i += d->d_reclen;
2167 dents++;
2168 }
2169 if (!abbrev(tcp))
2170 tprintf("}");
2171 else
2172 tprintf("/* %u entries */", dents);
2173 tprintf(", %lu", tcp->u_arg[2]);
2174 free(buf);
2175 return 0;
2176}
2177#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002178
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002179#ifdef FREEBSD
2180int
2181sys_getdirentries(tcp)
2182struct tcb * tcp;
2183{
2184 int i, len, dents = 0;
2185 long basep;
2186 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002187
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002188 if (entering(tcp)) {
2189 tprintf("%lu, ", tcp->u_arg[0]);
2190 return 0;
2191 }
2192 if (syserror(tcp) || !verbose(tcp)) {
2193 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2194 return 0;
2195 }
2196 len = tcp->u_rval;
2197 if ((buf = malloc(len)) == NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +00002198 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2199 fprintf(stderr, "out of memory\n");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002200 return 0;
2201 }
2202 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
Roland McGrath46100d02005-06-01 18:55:42 +00002203 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002204 free(buf);
2205 return 0;
2206 }
2207 if (!abbrev(tcp))
2208 tprintf("{");
2209 for (i = 0; i < len;) {
2210 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2211 if (!abbrev(tcp)) {
2212 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2213 i ? " " : "", d->d_fileno, d->d_reclen);
2214 printxval(direnttypes, d->d_type, "DT_???");
2215 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2216 d->d_namlen, d->d_namlen, d->d_name);
2217 }
2218 i += d->d_reclen;
2219 dents++;
2220 }
2221 if (!abbrev(tcp))
2222 tprintf("}");
2223 else
2224 tprintf("/* %u entries */", dents);
2225 free(buf);
2226 tprintf(", %lu", tcp->u_arg[2]);
2227 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2228 tprintf(", %#lx", tcp->u_arg[3]);
2229 else
2230 tprintf(", [%lu]", basep);
2231 return 0;
2232}
2233#endif
2234
Michal Ludvig53b320f2002-09-23 13:30:09 +00002235#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002236int
2237sys_getcwd(tcp)
2238struct tcb *tcp;
2239{
2240 if (exiting(tcp)) {
2241 if (syserror(tcp))
2242 tprintf("%#lx", tcp->u_arg[0]);
2243 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002244 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002245 tprintf(", %lu", tcp->u_arg[1]);
2246 }
2247 return 0;
2248}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002249#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002250
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002251#ifdef FREEBSD
2252int
2253sys___getcwd(tcp)
2254struct tcb *tcp;
2255{
2256 if (exiting(tcp)) {
2257 if (syserror(tcp))
2258 tprintf("%#lx", tcp->u_arg[0]);
2259 else
2260 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2261 tprintf(", %lu", tcp->u_arg[1]);
2262 }
2263 return 0;
2264}
2265#endif
2266
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002267#ifdef HAVE_SYS_ASYNCH_H
2268
2269int
2270sys_aioread(tcp)
2271struct tcb *tcp;
2272{
2273 struct aio_result_t res;
2274
2275 if (entering(tcp)) {
2276 tprintf("%lu, ", tcp->u_arg[0]);
2277 } else {
2278 if (syserror(tcp))
2279 tprintf("%#lx", tcp->u_arg[1]);
2280 else
2281 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2282 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2283 printxval(whence, tcp->u_arg[4], "L_???");
2284 if (syserror(tcp) || tcp->u_arg[5] == 0
2285 || umove(tcp, tcp->u_arg[5], &res) < 0)
2286 tprintf(", %#lx", tcp->u_arg[5]);
2287 else
2288 tprintf(", {aio_return %d aio_errno %d}",
2289 res.aio_return, res.aio_errno);
2290 }
2291 return 0;
2292}
2293
2294int
2295sys_aiowrite(tcp)
2296struct tcb *tcp;
2297{
2298 struct aio_result_t res;
2299
2300 if (entering(tcp)) {
2301 tprintf("%lu, ", tcp->u_arg[0]);
2302 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2303 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2304 printxval(whence, tcp->u_arg[4], "L_???");
2305 }
2306 else {
2307 if (tcp->u_arg[5] == 0)
2308 tprintf(", NULL");
2309 else if (syserror(tcp)
2310 || umove(tcp, tcp->u_arg[5], &res) < 0)
2311 tprintf(", %#lx", tcp->u_arg[5]);
2312 else
2313 tprintf(", {aio_return %d aio_errno %d}",
2314 res.aio_return, res.aio_errno);
2315 }
2316 return 0;
2317}
2318
2319int
2320sys_aiowait(tcp)
2321struct tcb *tcp;
2322{
2323 if (entering(tcp))
2324 printtv(tcp, tcp->u_arg[0]);
2325 return 0;
2326}
2327
2328int
2329sys_aiocancel(tcp)
2330struct tcb *tcp;
2331{
2332 struct aio_result_t res;
2333
2334 if (exiting(tcp)) {
2335 if (tcp->u_arg[0] == 0)
2336 tprintf("NULL");
2337 else if (syserror(tcp)
2338 || umove(tcp, tcp->u_arg[0], &res) < 0)
2339 tprintf("%#lx", tcp->u_arg[0]);
2340 else
2341 tprintf("{aio_return %d aio_errno %d}",
2342 res.aio_return, res.aio_errno);
2343 }
2344 return 0;
2345}
2346
2347#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002348
Roland McGrathd9f816f2004-09-04 03:39:20 +00002349const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002350#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002351 { XATTR_CREATE, "XATTR_CREATE" },
2352 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002353#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002354 { 0, NULL }
2355};
2356
Roland McGrath3292e222004-08-31 06:30:48 +00002357static void
2358print_xattr_val(tcp, failed, arg, insize, size)
2359struct tcb *tcp;
2360int failed;
2361unsigned long arg;
Roland McGrath883567c2005-02-02 03:38:32 +00002362long insize, size;
Roland McGrath3292e222004-08-31 06:30:48 +00002363{
Roland McGrath883567c2005-02-02 03:38:32 +00002364 if (!failed) {
2365 unsigned char *buf = malloc(4 * size + 1);
2366 if (buf == NULL || /* probably a bogus size argument */
Roland McGrathf7746422005-03-01 23:02:32 +00002367 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
Roland McGrath883567c2005-02-02 03:38:32 +00002368 failed = 1;
2369 }
2370 else {
2371 unsigned char *out = buf;
2372 unsigned char *in = &buf[3 * size];
2373 size_t i;
2374 for (i = 0; i < size; ++i)
2375 if (isprint(in[i]))
2376 *out++ = in[i];
2377 else {
Roland McGrath3292e222004-08-31 06:30:48 +00002378#define tohex(n) "0123456789abcdef"[n]
Roland McGrath883567c2005-02-02 03:38:32 +00002379 *out++ = '\\';
2380 *out++ = 'x';
2381 *out++ = tohex(in[i] / 16);
2382 *out++ = tohex(in[i] % 16);
2383 }
2384 /* Don't print terminating NUL if there is one. */
2385 if (in[i - 1] == '\0')
2386 out -= 4;
2387 *out = '\0';
2388 tprintf(", \"%s\", %ld", buf, insize);
2389 }
2390 free(buf);
2391 }
2392 if (failed)
2393 tprintf(", 0x%lx, %ld", arg, insize);
Roland McGrath3292e222004-08-31 06:30:48 +00002394}
2395
Roland McGrath186c5ac2002-12-15 23:58:23 +00002396int
2397sys_setxattr(tcp)
2398struct tcb *tcp;
2399{
2400 if (entering(tcp)) {
2401 printpath(tcp, tcp->u_arg[0]);
2402 tprintf(", ");
2403 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002404 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2405 tprintf(", ");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002406 printflags(xattrflags, tcp->u_arg[4]);
2407 }
2408 return 0;
2409}
2410
2411int
2412sys_fsetxattr(tcp)
2413struct tcb *tcp;
2414{
2415 if (entering(tcp)) {
2416 tprintf("%ld, ", tcp->u_arg[0]);
2417 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002418 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2419 tprintf(", ");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002420 printflags(xattrflags, tcp->u_arg[4]);
2421 }
2422 return 0;
2423}
2424
2425int
2426sys_getxattr(tcp)
2427struct tcb *tcp;
2428{
2429 if (entering(tcp)) {
2430 printpath(tcp, tcp->u_arg[0]);
2431 tprintf(", ");
2432 printstr(tcp, tcp->u_arg[1], -1);
2433 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002434 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2435 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002436 }
2437 return 0;
2438}
2439
2440int
2441sys_fgetxattr(tcp)
2442struct tcb *tcp;
2443{
2444 if (entering(tcp)) {
2445 tprintf("%ld, ", tcp->u_arg[0]);
2446 printstr(tcp, tcp->u_arg[1], -1);
2447 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002448 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2449 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002450 }
2451 return 0;
2452}
2453
2454int
2455sys_listxattr(tcp)
2456struct tcb *tcp;
2457{
2458 if (entering(tcp)) {
2459 printpath(tcp, tcp->u_arg[0]);
2460 } else {
2461 /* XXX Print value in format */
2462 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2463 }
2464 return 0;
2465}
2466
2467int
2468sys_flistxattr(tcp)
2469struct tcb *tcp;
2470{
2471 if (entering(tcp)) {
2472 tprintf("%ld", tcp->u_arg[0]);
2473 } else {
2474 /* XXX Print value in format */
2475 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2476 }
2477 return 0;
2478}
2479
2480int
2481sys_removexattr(tcp)
2482struct tcb *tcp;
2483{
2484 if (entering(tcp)) {
2485 printpath(tcp, tcp->u_arg[0]);
2486 tprintf(", ");
2487 printstr(tcp, tcp->u_arg[1], -1);
2488 }
2489 return 0;
2490}
2491
2492int
2493sys_fremovexattr(tcp)
2494struct tcb *tcp;
2495{
2496 if (entering(tcp)) {
2497 tprintf("%ld, ", tcp->u_arg[0]);
2498 printstr(tcp, tcp->u_arg[1], -1);
2499 }
2500 return 0;
2501}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002502
2503
2504static const struct xlat advise[] = {
2505 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2506 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2507 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2508 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2509 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2510 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2511 { 0, NULL }
2512};
2513
2514
Roland McGrathe27ed342004-10-20 02:24:19 +00002515#ifdef LINUX
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002516int
2517sys_fadvise64(tcp)
2518struct tcb *tcp;
2519{
2520 if (entering(tcp)) {
2521 tprintf("%ld, %lld, %ld, ",
2522 tcp->u_arg[0],
2523# if defined IA64 || defined X86_64 || defined ALPHA
2524 (long long int) tcp->u_arg[1], tcp->u_arg[2]);
2525 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2526#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002527 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
2528 printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002529#endif
2530 }
2531 return 0;
2532}
2533#endif
2534
2535
2536int
2537sys_fadvise64_64(tcp)
2538struct tcb *tcp;
2539{
2540 if (entering(tcp)) {
2541 tprintf("%ld, %lld, %lld, ",
2542 tcp->u_arg[0],
2543# if defined IA64 || defined X86_64 || defined ALPHA
2544 (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
2545 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2546#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002547 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
2548 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002549 printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
2550#endif
2551 }
2552 return 0;
2553}