blob: ed1064492ae10ed470075a1a8bb56d0d4c921bc0 [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 */
208struct xlat openmodes[] = {
209 { 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
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000240 { O_LARGEFILE, "O_LARGEFILE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000241#endif
242#ifdef O_DIRECTORY
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000243 { O_DIRECTORY, "O_DIRECTORY" },
244#endif
245#ifdef O_NOFOLLOW
246 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000247#endif
248
249#ifdef FNDELAY
250 { FNDELAY, "FNDELAY" },
251#endif
252#ifdef FAPPEND
253 { FAPPEND, "FAPPEND" },
254#endif
255#ifdef FMARK
256 { FMARK, "FMARK" },
257#endif
258#ifdef FDEFER
259 { FDEFER, "FDEFER" },
260#endif
261#ifdef FASYNC
262 { FASYNC, "FASYNC" },
263#endif
264#ifdef FSHLOCK
265 { FSHLOCK, "FSHLOCK" },
266#endif
267#ifdef FEXLOCK
268 { FEXLOCK, "FEXLOCK" },
269#endif
270#ifdef FCREAT
271 { FCREAT, "FCREAT" },
272#endif
273#ifdef FTRUNC
274 { FTRUNC, "FTRUNC" },
275#endif
276#ifdef FEXCL
277 { FEXCL, "FEXCL" },
278#endif
279#ifdef FNBIO
280 { FNBIO, "FNBIO" },
281#endif
282#ifdef FSYNC
283 { FSYNC, "FSYNC" },
284#endif
285#ifdef FNOCTTY
286 { FNOCTTY, "FNOCTTY" },
Roland McGrath186c5ac2002-12-15 23:58:23 +0000287#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000288#ifdef O_SHLOCK
289 { O_SHLOCK, "O_SHLOCK" },
290#endif
291#ifdef O_EXLOCK
292 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000293#endif
294 { 0, NULL },
295};
296
297int
298sys_open(tcp)
299struct tcb *tcp;
300{
301 if (entering(tcp)) {
302 printpath(tcp, tcp->u_arg[0]);
303 tprintf(", ");
304 /* flags */
305 printflags(openmodes, tcp->u_arg[1] + 1);
306 if (tcp->u_arg[1] & O_CREAT) {
307 /* mode */
308 tprintf(", %#lo", tcp->u_arg[2]);
309 }
310 }
311 return 0;
312}
313
314#ifdef LINUXSPARC
315struct xlat openmodessol[] = {
316 { 0, "O_RDWR" },
317 { 1, "O_RDONLY" },
318 { 2, "O_WRONLY" },
319 { 0x80, "O_NONBLOCK" },
320 { 8, "O_APPEND" },
321 { 0x100, "O_CREAT" },
322 { 0x200, "O_TRUNC" },
323 { 0x400, "O_EXCL" },
324 { 0x800, "O_NOCTTY" },
325 { 0x10, "O_SYNC" },
326 { 0x40, "O_DSYNC" },
327 { 0x8000, "O_RSYNC" },
328 { 4, "O_NDELAY" },
329 { 0x1000, "O_PRIV" },
330 { 0, NULL },
331};
332
333int
334solaris_open(tcp)
335struct tcb *tcp;
336{
337 if (entering(tcp)) {
338 printpath(tcp, tcp->u_arg[0]);
339 tprintf(", ");
340 /* flags */
341 printflags(openmodessol, tcp->u_arg[1] + 1);
342 if (tcp->u_arg[1] & 0x100) {
343 /* mode */
344 tprintf(", %#lo", tcp->u_arg[2]);
345 }
346 }
347 return 0;
348}
349
350#endif
351
352int
353sys_creat(tcp)
354struct tcb *tcp;
355{
356 if (entering(tcp)) {
357 printpath(tcp, tcp->u_arg[0]);
358 tprintf(", %#lo", tcp->u_arg[1]);
359 }
360 return 0;
361}
362
363static struct xlat access_flags[] = {
364 { F_OK, "F_OK", },
365 { R_OK, "R_OK" },
366 { W_OK, "W_OK" },
367 { X_OK, "X_OK" },
368#ifdef EFF_ONLY_OK
369 { EFF_ONLY_OK, "EFF_ONLY_OK" },
370#endif
371#ifdef EX_OK
372 { EX_OK, "EX_OK" },
373#endif
374 { 0, NULL },
375};
376
377int
378sys_access(tcp)
379struct tcb *tcp;
380{
381 if (entering(tcp)) {
382 printpath(tcp, tcp->u_arg[0]);
383 tprintf(", ");
384 printflags(access_flags, tcp->u_arg[1]);
385 }
386 return 0;
387}
388
389int
390sys_umask(tcp)
391struct tcb *tcp;
392{
393 if (entering(tcp)) {
394 tprintf("%#lo", tcp->u_arg[0]);
395 }
396 return RVAL_OCTAL;
397}
398
399static struct xlat whence[] = {
400 { SEEK_SET, "SEEK_SET" },
401 { SEEK_CUR, "SEEK_CUR" },
402 { SEEK_END, "SEEK_END" },
403 { 0, NULL },
404};
405
John Hughes70623be2001-03-08 13:59:00 +0000406#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000407int
408sys_lseek(tcp)
409struct tcb *tcp;
410{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000411 off_t offset;
412 int _whence;
413
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000414 if (entering(tcp)) {
415 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000416 offset = tcp->u_arg[1];
417 _whence = tcp->u_arg[2];
418 if (_whence == SEEK_SET)
419 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000420 else
Roland McGrath186c5ac2002-12-15 23:58:23 +0000421 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000422 printxval(whence, _whence, "SEEK_???");
Roland McGrath186c5ac2002-12-15 23:58:23 +0000423 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000424 return RVAL_UDECIMAL;
425}
John Hughes5a826b82001-03-07 13:21:24 +0000426#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000427
Michal Ludvig53b320f2002-09-23 13:30:09 +0000428#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000429int
430sys_llseek (tcp)
431struct tcb *tcp;
432{
433 if (entering(tcp)) {
434 if (tcp->u_arg[4] == SEEK_SET)
435 tprintf("%ld, %llu, ", tcp->u_arg[0],
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000436 (((long long int) tcp->u_arg[1]) << 32
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000437 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438 else
439 tprintf("%ld, %lld, ", tcp->u_arg[0],
440 (((long long int) tcp->u_arg[1]) << 32
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000441 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000442 }
443 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000444 long long int off;
445 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000446 tprintf("%#lx, ", tcp->u_arg[3]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000447 else
448 tprintf("[%llu], ", off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000449 printxval(whence, tcp->u_arg[4], "SEEK_???");
450 }
451 return 0;
452}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000453
454int
455sys_readahead (tcp)
456struct tcb *tcp;
457{
458 if (entering(tcp)) {
459 tprintf("%ld, %lld, %ld", tcp->u_arg[0],
460# if defined IA64 || defined X86_64 || defined ALPHA
461 (long long int) tcp->u_arg[1], tcp->u_arg[2]
462# else
463 (((long long int) tcp->u_arg[1]) << 32
464 | ((unsigned long *) tcp->u_arg)[2]),
465 tcp->u_arg[3]
466# endif
467 );
468 }
469 return 0;
470}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000471#endif
472
John Hughes70623be2001-03-08 13:59:00 +0000473#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000474int
475sys_lseek64 (tcp)
476struct tcb *tcp;
477{
478 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000479 long long offset;
480 ALIGN64 (tcp, 1); /* FreeBSD aligns off_t args */
John Hughes0c79e012001-03-08 14:40:06 +0000481 offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +0000482 if (tcp->u_arg[3] == SEEK_SET)
483 tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
484 else
485 tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
486 printxval(whence, tcp->u_arg[3], "SEEK_???");
487 }
488 return RVAL_LUDECIMAL;
489}
490#endif
491
John Hughes70623be2001-03-08 13:59:00 +0000492#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000493int
494sys_truncate(tcp)
495struct tcb *tcp;
496{
497 if (entering(tcp)) {
498 printpath(tcp, tcp->u_arg[0]);
499 tprintf(", %lu", tcp->u_arg[1]);
500 }
501 return 0;
502}
John Hughes5a826b82001-03-07 13:21:24 +0000503#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000504
John Hughes70623be2001-03-08 13:59:00 +0000505#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000506int
507sys_truncate64(tcp)
508struct tcb *tcp;
509{
510 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000511 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000512 printpath(tcp, tcp->u_arg[0]);
John Hughes0c79e012001-03-08 14:40:06 +0000513 tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000514 }
515 return 0;
516}
517#endif
518
John Hughes70623be2001-03-08 13:59:00 +0000519#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520int
521sys_ftruncate(tcp)
522struct tcb *tcp;
523{
524 if (entering(tcp)) {
525 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
526 }
527 return 0;
528}
John Hughes5a826b82001-03-07 13:21:24 +0000529#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000530
John Hughes70623be2001-03-08 13:59:00 +0000531#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000532int
533sys_ftruncate64(tcp)
534struct tcb *tcp;
535{
536 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000537 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000538 tprintf("%ld, %llu", tcp->u_arg[0],
John Hughes0c79e012001-03-08 14:40:06 +0000539 LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000540 }
541 return 0;
542}
543#endif
544
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000545/* several stats */
546
547static struct xlat modetypes[] = {
548 { S_IFREG, "S_IFREG" },
549 { S_IFSOCK, "S_IFSOCK" },
550 { S_IFIFO, "S_IFIFO" },
551 { S_IFLNK, "S_IFLNK" },
552 { S_IFDIR, "S_IFDIR" },
553 { S_IFBLK, "S_IFBLK" },
554 { S_IFCHR, "S_IFCHR" },
555 { 0, NULL },
556};
557
558static char *
559sprintmode(mode)
560int mode;
561{
562 static char buf[64];
563 char *s;
564
565 if ((mode & S_IFMT) == 0)
566 s = "";
567 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
568 sprintf(buf, "%#o", mode);
569 return buf;
570 }
571 sprintf(buf, "%s%s%s%s", s,
572 (mode & S_ISUID) ? "|S_ISUID" : "",
573 (mode & S_ISGID) ? "|S_ISGID" : "",
574 (mode & S_ISVTX) ? "|S_ISVTX" : "");
575 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
576 if (mode)
577 sprintf(buf + strlen(buf), "|%#o", mode);
578 s = (*buf == '|') ? buf + 1 : buf;
579 return *s ? s : "0";
580}
581
582static char *
583sprinttime(t)
584time_t t;
585{
586 struct tm *tmp;
587 static char buf[32];
588
589 if (t == 0) {
590 sprintf(buf, "0");
591 return buf;
592 }
593 tmp = localtime(&t);
594 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
Wichert Akkerman3ed6dc22000-01-11 14:41:09 +0000595 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000596 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
597 return buf;
598}
599
600#ifdef LINUXSPARC
601typedef struct {
602 int tv_sec;
603 int tv_nsec;
604} timestruct_t;
605
606struct solstat {
607 unsigned st_dev;
608 int st_pad1[3]; /* network id */
609 unsigned st_ino;
610 unsigned st_mode;
611 unsigned st_nlink;
612 unsigned st_uid;
613 unsigned st_gid;
614 unsigned st_rdev;
615 int st_pad2[2];
616 int st_size;
617 int st_pad3; /* st_size, off_t expansion */
618 timestruct_t st_atime;
619 timestruct_t st_mtime;
620 timestruct_t st_ctime;
621 int st_blksize;
622 int st_blocks;
623 char st_fstype[16];
624 int st_pad4[8]; /* expansion area */
625};
626
627static void
628printstatsol(tcp, addr)
629struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000630long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000631{
632 struct solstat statbuf;
633
634 if (!addr) {
635 tprintf("NULL");
636 return;
637 }
638 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000639 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000640 return;
641 }
642 if (umove(tcp, addr, &statbuf) < 0) {
643 tprintf("{...}");
644 return;
645 }
646 if (!abbrev(tcp)) {
647 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
648 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
649 (unsigned long) (statbuf.st_dev & 0x3ffff),
650 (unsigned long) statbuf.st_ino,
651 sprintmode(statbuf.st_mode));
652 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
653 (unsigned long) statbuf.st_nlink,
654 (unsigned long) statbuf.st_uid,
655 (unsigned long) statbuf.st_gid);
656 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
657 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
658 }
659 else
660 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
661 switch (statbuf.st_mode & S_IFMT) {
662 case S_IFCHR: case S_IFBLK:
663 tprintf("st_rdev=makedev(%lu, %lu), ",
664 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
665 (unsigned long) (statbuf.st_rdev & 0x3ffff));
666 break;
667 default:
668 tprintf("st_size=%u, ", statbuf.st_size);
669 break;
670 }
671 if (!abbrev(tcp)) {
672 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
673 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
674 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
675 }
676 else
677 tprintf("...}");
678}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000679
680#if defined (SPARC64)
681static void
682printstat_sparc64(tcp, addr)
683struct tcb *tcp;
684long addr;
685{
686 struct stat_sparc64 statbuf;
687
688 if (!addr) {
689 tprintf("NULL");
690 return;
691 }
692 if (syserror(tcp) || !verbose(tcp)) {
693 tprintf("%#lx", addr);
694 return;
695 }
696 if (umove(tcp, addr, &statbuf) < 0) {
697 tprintf("{...}");
698 return;
699 }
700
701 if (!abbrev(tcp)) {
702 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
703 (unsigned long) major(statbuf.st_dev),
704 (unsigned long) minor(statbuf.st_dev),
705 (unsigned long) statbuf.st_ino,
706 sprintmode(statbuf.st_mode));
707 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
708 (unsigned long) statbuf.st_nlink,
709 (unsigned long) statbuf.st_uid,
710 (unsigned long) statbuf.st_gid);
711 tprintf("st_blksize=%lu, ",
712 (unsigned long) statbuf.st_blksize);
713 tprintf("st_blocks=%lu, ",
714 (unsigned long) statbuf.st_blocks);
715 }
716 else
717 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
718 switch (statbuf.st_mode & S_IFMT) {
719 case S_IFCHR: case S_IFBLK:
720 tprintf("st_rdev=makedev(%lu, %lu), ",
721 (unsigned long) major(statbuf.st_rdev),
722 (unsigned long) minor(statbuf.st_rdev));
723 break;
724 default:
725 tprintf("st_size=%lu, ", statbuf.st_size);
726 break;
727 }
728 if (!abbrev(tcp)) {
729 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
730 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
731 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
732 tprintf("}");
733 }
734 else
735 tprintf("...}");
736}
737#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000738#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000739
Michal Ludvig53b320f2002-09-23 13:30:09 +0000740struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000741#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000742 { UF_NODUMP, "UF_NODUMP" },
743 { UF_IMMUTABLE, "UF_IMMUTABLE" },
744 { UF_APPEND, "UF_APPEND" },
745 { UF_OPAQUE, "UF_OPAQUE" },
746 { UF_NOUNLINK, "UF_NOUNLINK" },
747 { SF_ARCHIVED, "SF_ARCHIVED" },
748 { SF_IMMUTABLE, "SF_IMMUTABLE" },
749 { SF_APPEND, "SF_APPEND" },
750 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000751#elif UNIXWARE >= 2
752#ifdef _S_ISMLD
753 { _S_ISMLD, "_S_ISMLD" },
754#endif
755#ifdef _S_ISMOUNTED
756 { _S_ISMOUNTED, "_S_ISMOUNTED" },
757#endif
758#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000759 { 0, NULL },
760};
761
John Hughesc0fc3fd2001-03-08 16:10:40 +0000762#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000763int
764sys_chflags(tcp)
765struct tcb *tcp;
766{
767 if (entering(tcp)) {
768 printpath(tcp, tcp->u_arg[0]);
769 tprintf(", ");
770 if (tcp->u_arg[1])
771 printflags(fileflags, tcp->u_arg[1]);
772 else
773 tprintf("0");
774 }
775 return 0;
776}
777
778int
779sys_fchflags(tcp)
780struct tcb *tcp;
781{
782 if (entering(tcp)) {
783 tprintf("%ld, ", tcp->u_arg[0]);
784 if (tcp->u_arg[1])
785 printflags(fileflags, tcp->u_arg[1]);
786 else
787 tprintf("0");
788 }
789 return 0;
790}
791#endif
792
John Hughes70623be2001-03-08 13:59:00 +0000793#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000794static void
795realprintstat(tcp, statbuf)
796struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000797struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000798{
799 if (!abbrev(tcp)) {
800 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
801 (unsigned long) major(statbuf->st_dev),
802 (unsigned long) minor(statbuf->st_dev),
803 (unsigned long) statbuf->st_ino,
804 sprintmode(statbuf->st_mode));
805 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
806 (unsigned long) statbuf->st_nlink,
807 (unsigned long) statbuf->st_uid,
808 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000809#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000810 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000811#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
812#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000813 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000814#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000815 }
816 else
817 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
818 switch (statbuf->st_mode & S_IFMT) {
819 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000820#ifdef HAVE_STRUCT_STAT_ST_RDEV
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000821 tprintf("st_rdev=makedev(%lu, %lu), ",
822 (unsigned long) major(statbuf->st_rdev),
823 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000824#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000825 tprintf("st_size=makedev(%lu, %lu), ",
826 (unsigned long) major(statbuf->st_size),
827 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000828#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000829 break;
830 default:
831 tprintf("st_size=%lu, ", statbuf->st_size);
832 break;
833 }
834 if (!abbrev(tcp)) {
835 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
836 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000837 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000838#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000839 tprintf(", st_flags=");
840 if (statbuf->st_flags) {
841 printflags(fileflags, statbuf->st_flags);
842 } else
843 tprintf("0");
844#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000845#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000846 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
847#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000848#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000849 tprintf(", st_level=%ld", statbuf->st_level);
850#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000851#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000852 tprintf(", st_fstype=%.*s",
853 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
854#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000855#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000856 tprintf(", st_gen=%u", statbuf->st_gen);
857#endif
858 tprintf("}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000859 }
860 else
861 tprintf("...}");
862}
863
Nate Sammons771a6ff1999-04-05 22:39:31 +0000864
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000865static void
866printstat(tcp, addr)
867struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000868long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000869{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000870 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000871
872#ifdef LINUXSPARC
873 if (current_personality == 1) {
874 printstatsol(tcp, addr);
875 return;
876 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000877#ifdef SPARC64
878 else if (current_personality == 2) {
879 printstat_sparc64(tcp, addr);
880 return;
881 }
882#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000883#endif /* LINUXSPARC */
884
885 if (!addr) {
886 tprintf("NULL");
887 return;
888 }
889 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000890 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000891 return;
892 }
893 if (umove(tcp, addr, &statbuf) < 0) {
894 tprintf("{...}");
895 return;
896 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000897
898 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000899}
John Hughes70623be2001-03-08 13:59:00 +0000900#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000901
Wichert Akkermanc7926982000-04-10 22:22:31 +0000902#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000903static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000904printstat64(tcp, addr)
905struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000906long addr;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000907{
908 struct stat64 statbuf;
909
910#ifdef LINUXSPARC
911 if (current_personality == 1) {
912 printstatsol(tcp, addr);
913 return;
914 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000915#ifdef SPARC64
916 else if (current_personality == 2) {
917 printstat_sparc64(tcp, addr);
918 return;
919 }
920#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000921#endif /* LINUXSPARC */
922
923 if (!addr) {
924 tprintf("NULL");
925 return;
926 }
927 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000928 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000929 return;
930 }
931 if (umove(tcp, addr, &statbuf) < 0) {
932 tprintf("{...}");
933 return;
934 }
935
936 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +0000937#ifdef HAVE_LONG_LONG
938 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
939#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000940 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +0000941#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000942 (unsigned long) major(statbuf.st_dev),
943 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +0000944#ifdef HAVE_LONG_LONG
945 (unsigned long long) statbuf.st_ino,
946#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000947 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +0000948#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000949 sprintmode(statbuf.st_mode));
950 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
951 (unsigned long) statbuf.st_nlink,
952 (unsigned long) statbuf.st_uid,
953 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000954#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000955 tprintf("st_blksize=%lu, ",
956 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000957#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
958#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000959 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000960#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000961 }
962 else
963 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
964 switch (statbuf.st_mode & S_IFMT) {
965 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000966#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000967 tprintf("st_rdev=makedev(%lu, %lu), ",
968 (unsigned long) major(statbuf.st_rdev),
969 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000970#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000971 tprintf("st_size=makedev(%lu, %lu), ",
972 (unsigned long) major(statbuf.st_size),
973 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000974#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000975 break;
976 default:
977 tprintf("st_size=%llu, ", statbuf.st_size);
978 break;
979 }
980 if (!abbrev(tcp)) {
981 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
982 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000983 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000984#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000985 tprintf(", st_flags=");
John Hughesb8c9f772001-03-07 16:53:07 +0000986 if (statbuf.st_flags) {
987 printflags(fileflags, statbuf.st_flags);
988 } else
989 tprintf("0");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000990#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000991#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000992 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
993#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000994#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000995 tprintf(", st_level=%ld", statbuf.st_level);
996#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000997#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000998 tprintf(", st_fstype=%.*s",
999 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1000#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +00001001#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +00001002 tprintf(", st_gen=%u", statbuf.st_gen);
1003#endif
1004 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001005 }
1006 else
1007 tprintf("...}");
1008}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001009#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001010
Roland McGrath79db8af2003-06-27 21:20:09 +00001011#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001012static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001013convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001014const struct __old_kernel_stat *oldbuf;
1015struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001016{
1017 newbuf->st_dev=oldbuf->st_dev;
1018 newbuf->st_ino=oldbuf->st_ino;
1019 newbuf->st_mode=oldbuf->st_mode;
1020 newbuf->st_nlink=oldbuf->st_nlink;
1021 newbuf->st_uid=oldbuf->st_uid;
1022 newbuf->st_gid=oldbuf->st_gid;
1023 newbuf->st_rdev=oldbuf->st_rdev;
1024 newbuf->st_size=oldbuf->st_size;
1025 newbuf->st_atime=oldbuf->st_atime;
1026 newbuf->st_mtime=oldbuf->st_mtime;
1027 newbuf->st_ctime=oldbuf->st_ctime;
1028 newbuf->st_blksize=0; /* not supported in old_stat */
1029 newbuf->st_blocks=0; /* not supported in old_stat */
1030}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001031
1032
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001033static void
1034printoldstat(tcp, addr)
1035struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001036long addr;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001037{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001038 struct __old_kernel_stat statbuf;
1039 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001040
1041#ifdef LINUXSPARC
1042 if (current_personality == 1) {
1043 printstatsol(tcp, addr);
1044 return;
1045 }
1046#endif /* LINUXSPARC */
1047
1048 if (!addr) {
1049 tprintf("NULL");
1050 return;
1051 }
1052 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001053 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001054 return;
1055 }
1056 if (umove(tcp, addr, &statbuf) < 0) {
1057 tprintf("{...}");
1058 return;
1059 }
1060
1061 convertoldstat(&statbuf, &newstatbuf);
1062 realprintstat(tcp, &newstatbuf);
1063}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001064#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001065
John Hughes70623be2001-03-08 13:59:00 +00001066#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001067int
1068sys_stat(tcp)
1069struct tcb *tcp;
1070{
1071 if (entering(tcp)) {
1072 printpath(tcp, tcp->u_arg[0]);
1073 tprintf(", ");
1074 } else {
1075 printstat(tcp, tcp->u_arg[1]);
1076 }
1077 return 0;
1078}
John Hughesb8c9f772001-03-07 16:53:07 +00001079#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001080
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001081int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001082sys_stat64(tcp)
1083struct tcb *tcp;
1084{
1085#ifdef HAVE_STAT64
1086 if (entering(tcp)) {
1087 printpath(tcp, tcp->u_arg[0]);
1088 tprintf(", ");
1089 } else {
1090 printstat64(tcp, tcp->u_arg[1]);
1091 }
1092 return 0;
1093#else
1094 return printargs(tcp);
1095#endif
1096}
1097
Roland McGrath79db8af2003-06-27 21:20:09 +00001098#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001099int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001100sys_oldstat(tcp)
1101struct tcb *tcp;
1102{
1103 if (entering(tcp)) {
1104 printpath(tcp, tcp->u_arg[0]);
1105 tprintf(", ");
1106 } else {
1107 printoldstat(tcp, tcp->u_arg[1]);
1108 }
1109 return 0;
1110}
Roland McGrath79db8af2003-06-27 21:20:09 +00001111#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001112
John Hughes70623be2001-03-08 13:59:00 +00001113#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001114int
1115sys_fstat(tcp)
1116struct tcb *tcp;
1117{
1118 if (entering(tcp))
1119 tprintf("%ld, ", tcp->u_arg[0]);
1120 else {
1121 printstat(tcp, tcp->u_arg[1]);
1122 }
1123 return 0;
1124}
John Hughesb8c9f772001-03-07 16:53:07 +00001125#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001126
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001127int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001128sys_fstat64(tcp)
1129struct tcb *tcp;
1130{
1131#ifdef HAVE_STAT64
1132 if (entering(tcp))
1133 tprintf("%ld, ", tcp->u_arg[0]);
1134 else {
1135 printstat64(tcp, tcp->u_arg[1]);
1136 }
1137 return 0;
1138#else
1139 return printargs(tcp);
1140#endif
1141}
1142
Roland McGrath79db8af2003-06-27 21:20:09 +00001143#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001144int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001145sys_oldfstat(tcp)
1146struct tcb *tcp;
1147{
1148 if (entering(tcp))
1149 tprintf("%ld, ", tcp->u_arg[0]);
1150 else {
1151 printoldstat(tcp, tcp->u_arg[1]);
1152 }
1153 return 0;
1154}
Roland McGrath79db8af2003-06-27 21:20:09 +00001155#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001156
John Hughes70623be2001-03-08 13:59:00 +00001157#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001158int
1159sys_lstat(tcp)
1160struct tcb *tcp;
1161{
1162 if (entering(tcp)) {
1163 printpath(tcp, tcp->u_arg[0]);
1164 tprintf(", ");
1165 } else {
1166 printstat(tcp, tcp->u_arg[1]);
1167 }
1168 return 0;
1169}
John Hughesb8c9f772001-03-07 16:53:07 +00001170#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001171
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001172int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001173sys_lstat64(tcp)
1174struct tcb *tcp;
1175{
1176#ifdef HAVE_STAT64
1177 if (entering(tcp)) {
1178 printpath(tcp, tcp->u_arg[0]);
1179 tprintf(", ");
1180 } else {
1181 printstat64(tcp, tcp->u_arg[1]);
1182 }
1183 return 0;
1184#else
1185 return printargs(tcp);
1186#endif
1187}
1188
Roland McGrath79db8af2003-06-27 21:20:09 +00001189#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001190int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001191sys_oldlstat(tcp)
1192struct tcb *tcp;
1193{
1194 if (entering(tcp)) {
1195 printpath(tcp, tcp->u_arg[0]);
1196 tprintf(", ");
1197 } else {
1198 printoldstat(tcp, tcp->u_arg[1]);
1199 }
1200 return 0;
1201}
Roland McGrath79db8af2003-06-27 21:20:09 +00001202#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001203
1204
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001205#if defined(SVR4) || defined(LINUXSPARC)
1206
1207int
1208sys_xstat(tcp)
1209struct tcb *tcp;
1210{
1211 if (entering(tcp)) {
1212 tprintf("%ld, ", tcp->u_arg[0]);
1213 printpath(tcp, tcp->u_arg[1]);
1214 tprintf(", ");
1215 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001216#ifdef _STAT64_VER
1217 if (tcp->u_arg[0] == _STAT64_VER)
1218 printstat64 (tcp, tcp->u_arg[2]);
1219 else
1220#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001221 printstat(tcp, tcp->u_arg[2]);
1222 }
1223 return 0;
1224}
1225
1226int
1227sys_fxstat(tcp)
1228struct tcb *tcp;
1229{
1230 if (entering(tcp))
1231 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1232 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001233#ifdef _STAT64_VER
1234 if (tcp->u_arg[0] == _STAT64_VER)
1235 printstat64 (tcp, tcp->u_arg[2]);
1236 else
1237#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001238 printstat(tcp, tcp->u_arg[2]);
1239 }
1240 return 0;
1241}
1242
1243int
1244sys_lxstat(tcp)
1245struct tcb *tcp;
1246{
1247 if (entering(tcp)) {
1248 tprintf("%ld, ", tcp->u_arg[0]);
1249 printpath(tcp, tcp->u_arg[1]);
1250 tprintf(", ");
1251 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001252#ifdef _STAT64_VER
1253 if (tcp->u_arg[0] == _STAT64_VER)
1254 printstat64 (tcp, tcp->u_arg[2]);
1255 else
1256#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001257 printstat(tcp, tcp->u_arg[2]);
1258 }
1259 return 0;
1260}
1261
1262int
1263sys_xmknod(tcp)
1264struct tcb *tcp;
1265{
1266 int mode = tcp->u_arg[2];
1267
1268 if (entering(tcp)) {
1269 tprintf("%ld, ", tcp->u_arg[0]);
1270 printpath(tcp, tcp->u_arg[1]);
1271 tprintf(", %s", sprintmode(mode));
1272 switch (mode & S_IFMT) {
1273 case S_IFCHR: case S_IFBLK:
1274#ifdef LINUXSPARC
1275 tprintf(", makedev(%lu, %lu)",
1276 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1277 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001278#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001279 tprintf(", makedev(%lu, %lu)",
1280 (unsigned long) major(tcp->u_arg[3]),
1281 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001282#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001283 break;
1284 default:
1285 break;
1286 }
1287 }
1288 return 0;
1289}
1290
Wichert Akkerman8829a551999-06-11 13:18:40 +00001291#ifdef HAVE_SYS_ACL_H
1292
1293#include <sys/acl.h>
1294
1295struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001296#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001297 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001298#endif
1299#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001300 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001301#endif
1302#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001303 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001304#endif
1305#ifdef ACL_GET
1306 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001307#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001308#ifdef ACL_SET
1309 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001310#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001311#ifdef ACL_CNT
1312 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001313#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001314 { 0, NULL },
1315};
1316
1317int
1318sys_acl(tcp)
1319struct tcb *tcp;
1320{
1321 if (entering(tcp)) {
1322 printpath(tcp, tcp->u_arg[0]);
1323 tprintf(", ");
1324 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1325 tprintf(", %ld", tcp->u_arg[2]);
1326 /*
1327 * FIXME - dump out the list of aclent_t's pointed to
1328 * by "tcp->u_arg[3]" if it's not NULL.
1329 */
1330 if (tcp->u_arg[3])
1331 tprintf(", %#lx", tcp->u_arg[3]);
1332 else
1333 tprintf(", NULL");
1334 }
1335 return 0;
1336}
1337
1338
1339int
1340sys_facl(tcp)
1341struct tcb *tcp;
1342{
1343 if (entering(tcp)) {
1344 tprintf("%ld, ", tcp->u_arg[0]);
1345 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1346 tprintf(", %ld", tcp->u_arg[2]);
1347 /*
1348 * FIXME - dump out the list of aclent_t's pointed to
1349 * by "tcp->u_arg[3]" if it's not NULL.
1350 */
1351 if (tcp->u_arg[3])
1352 tprintf(", %#lx", tcp->u_arg[3]);
1353 else
1354 tprintf(", NULL");
1355 }
1356 return 0;
1357}
1358
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001359
1360struct xlat aclipc[] = {
1361#ifdef IPC_SHM
1362 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001363#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001364#ifdef IPC_SEM
1365 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001366#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001367#ifdef IPC_MSG
1368 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001369#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001370 { 0, NULL },
1371};
1372
1373
1374int
1375sys_aclipc(tcp)
1376struct tcb *tcp;
1377{
1378 if (entering(tcp)) {
1379 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1380 tprintf(", %#lx, ", tcp->u_arg[1]);
1381 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1382 tprintf(", %ld", tcp->u_arg[3]);
1383 /*
1384 * FIXME - dump out the list of aclent_t's pointed to
1385 * by "tcp->u_arg[4]" if it's not NULL.
1386 */
1387 if (tcp->u_arg[4])
1388 tprintf(", %#lx", tcp->u_arg[4]);
1389 else
1390 tprintf(", NULL");
1391 }
1392 return 0;
1393}
1394
1395
1396
Wichert Akkerman8829a551999-06-11 13:18:40 +00001397#endif /* HAVE_SYS_ACL_H */
1398
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001399#endif /* SVR4 || LINUXSPARC */
1400
Michal Ludvig53b320f2002-09-23 13:30:09 +00001401#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001402
1403static struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001404 { 0x73757245, "CODA_SUPER_MAGIC" },
1405 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1406 { 0x1373, "DEVFS_SUPER_MAGIC" },
1407 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1408 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001409 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1410 { 0xef53, "EXT2_SUPER_MAGIC" },
1411 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001412 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413 { 0x9660, "ISOFS_SUPER_MAGIC" },
1414 { 0x137f, "MINIX_SUPER_MAGIC" },
1415 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001416 { 0x2468, "MINIX2_SUPER_MAGIC" },
1417 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001418 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001419 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001420 { 0x6969, "NFS_SUPER_MAGIC" },
1421 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001422 { 0x002f, "QNX4_SUPER_MAGIC" },
1423 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1424 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1425 { 0x517b, "SMB_SUPER_MAGIC" },
1426 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1427 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1428 { 0x00011954, "UFS_MAGIC" },
1429 { 0x54190100, "UFS_CIGAM" },
1430 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001431 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001432 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001433 { 0, NULL },
1434};
1435
Michal Ludvig53b320f2002-09-23 13:30:09 +00001436#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001437
1438#ifndef SVR4
1439
1440static char *
1441sprintfstype(magic)
1442int magic;
1443{
1444 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001445#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001446 char *s;
1447
1448 s = xlookup(fsmagic, magic);
1449 if (s) {
1450 sprintf(buf, "\"%s\"", s);
1451 return buf;
1452 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001453#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001454 sprintf(buf, "%#x", magic);
1455 return buf;
1456}
1457
1458static void
1459printstatfs(tcp, addr)
1460struct tcb *tcp;
1461long addr;
1462{
1463 struct statfs statbuf;
1464
1465 if (syserror(tcp) || !verbose(tcp)) {
1466 tprintf("%#lx", addr);
1467 return;
1468 }
1469 if (umove(tcp, addr, &statbuf) < 0) {
1470 tprintf("{...}");
1471 return;
1472 }
1473#ifdef ALPHA
1474
1475 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1476 sprintfstype(statbuf.f_type),
1477 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001478 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1479 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1480 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1481 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001482#else /* !ALPHA */
1483 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1484 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001485 (unsigned long)statbuf.f_bsize,
1486 (unsigned long)statbuf.f_blocks,
1487 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001488 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1489 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001490 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001491 (unsigned long)statbuf.f_ffree,
1492 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001493#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001494 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001495#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001496#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001497#ifdef _STATFS_F_FRSIZE
1498 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1499#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001500 tprintf("}");
1501}
1502
1503int
1504sys_statfs(tcp)
1505struct tcb *tcp;
1506{
1507 if (entering(tcp)) {
1508 printpath(tcp, tcp->u_arg[0]);
1509 tprintf(", ");
1510 } else {
1511 printstatfs(tcp, tcp->u_arg[1]);
1512 }
1513 return 0;
1514}
1515
1516int
1517sys_fstatfs(tcp)
1518struct tcb *tcp;
1519{
1520 if (entering(tcp)) {
1521 tprintf("%lu, ", tcp->u_arg[0]);
1522 } else {
1523 printstatfs(tcp, tcp->u_arg[1]);
1524 }
1525 return 0;
1526}
1527
Roland McGrathab147c52003-07-17 09:03:02 +00001528#ifdef LINUX
1529static void
1530printstatfs64(tcp, addr)
1531struct tcb *tcp;
1532long addr;
1533{
1534 struct statfs64 statbuf;
1535
1536 if (syserror(tcp) || !verbose(tcp)) {
1537 tprintf("%#lx", addr);
1538 return;
1539 }
1540 if (umove(tcp, addr, &statbuf) < 0) {
1541 tprintf("{...}");
1542 return;
1543 }
1544#ifdef ALPHA
1545
1546 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1547 sprintfstype(statbuf.f_type),
1548 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1549 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1550 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1551 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1552 statbuf.f_namelen);
1553#else /* !ALPHA */
1554 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1555 sprintfstype(statbuf.f_type),
1556 (unsigned long)statbuf.f_bsize,
1557 (unsigned long)statbuf.f_blocks,
1558 (unsigned long)statbuf.f_bfree);
1559 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1560 (unsigned long)statbuf.f_bavail,
1561 (unsigned long)statbuf.f_files,
1562 (unsigned long)statbuf.f_ffree,
1563 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1564 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1565#endif /* !ALPHA */
1566#ifdef _STATFS_F_FRSIZE
1567 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1568#endif
1569 tprintf("}");
1570}
1571
1572int
1573sys_statfs64(tcp)
1574struct tcb *tcp;
1575{
1576 if (entering(tcp)) {
1577 printpath(tcp, tcp->u_arg[0]);
1578 tprintf(", %lu, ", tcp->u_arg[1]);
1579 } else {
1580 if (tcp->u_arg[1] == sizeof (struct statfs64))
1581 printstatfs64(tcp, tcp->u_arg[2]);
1582 else
1583 tprintf("{???}");
1584 }
1585 return 0;
1586}
1587
1588int
1589sys_fstatfs64(tcp)
1590struct tcb *tcp;
1591{
1592 if (entering(tcp)) {
1593 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1594 } else {
1595 if (tcp->u_arg[1] == sizeof (struct statfs64))
1596 printstatfs64(tcp, tcp->u_arg[2]);
1597 else
1598 tprintf("{???}");
1599 }
1600 return 0;
1601}
1602#endif
1603
Michal Ludvig53b320f2002-09-23 13:30:09 +00001604#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001605
1606int
1607osf_statfs(tcp)
1608struct tcb *tcp;
1609{
1610 if (entering(tcp)) {
1611 printpath(tcp, tcp->u_arg[0]);
1612 tprintf(", ");
1613 } else {
1614 printstatfs(tcp, tcp->u_arg[1]);
1615 tprintf(", %lu", tcp->u_arg[2]);
1616 }
1617 return 0;
1618}
1619
1620int
1621osf_fstatfs(tcp)
1622struct tcb *tcp;
1623{
1624 if (entering(tcp)) {
1625 tprintf("%lu, ", tcp->u_arg[0]);
1626 } else {
1627 printstatfs(tcp, tcp->u_arg[1]);
1628 tprintf(", %lu", tcp->u_arg[2]);
1629 }
1630 return 0;
1631}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001632#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001633
1634#endif /* !SVR4 */
1635
1636#ifdef SUNOS4
1637
1638int
1639sys_ustat(tcp)
1640struct tcb *tcp;
1641{
1642 struct ustat statbuf;
1643
1644 if (entering(tcp)) {
1645 tprintf("makedev(%lu, %lu), ",
1646 (long) major(tcp->u_arg[0]),
1647 (long) minor(tcp->u_arg[0]));
1648 }
1649 else {
1650 if (syserror(tcp) || !verbose(tcp))
1651 tprintf("%#lx", tcp->u_arg[1]);
1652 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1653 tprintf("{...}");
1654 else {
1655 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1656 statbuf.f_tfree, statbuf.f_tinode);
1657 tprintf("f_fname=\"%.*s\", ",
1658 (int) sizeof(statbuf.f_fname),
1659 statbuf.f_fname);
1660 tprintf("f_fpack=\"%.*s\"}",
1661 (int) sizeof(statbuf.f_fpack),
1662 statbuf.f_fpack);
1663 }
1664 }
1665 return 0;
1666}
1667
1668#endif /* SUNOS4 */
1669
Wichert Akkermanc7926982000-04-10 22:22:31 +00001670int
1671sys_pivotroot(tcp)
1672struct tcb *tcp;
1673{
1674 if (entering(tcp)) {
1675 printpath(tcp, tcp->u_arg[0]);
1676 tprintf(", ");
1677 printpath(tcp, tcp->u_arg[1]);
1678 }
1679 return 0;
1680}
1681
1682
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001683/* directory */
1684int
1685sys_chdir(tcp)
1686struct tcb *tcp;
1687{
1688 if (entering(tcp)) {
1689 printpath(tcp, tcp->u_arg[0]);
1690 }
1691 return 0;
1692}
1693
1694int
1695sys_mkdir(tcp)
1696struct tcb *tcp;
1697{
1698 if (entering(tcp)) {
1699 printpath(tcp, tcp->u_arg[0]);
1700 tprintf(", %#lo", tcp->u_arg[1]);
1701 }
1702 return 0;
1703}
1704
1705int
1706sys_rmdir(tcp)
1707struct tcb *tcp;
1708{
1709 if (entering(tcp)) {
1710 printpath(tcp, tcp->u_arg[0]);
1711 }
1712 return 0;
1713}
1714
1715int
1716sys_fchdir(tcp)
1717struct tcb *tcp;
1718{
1719 if (entering(tcp)) {
1720 tprintf("%ld", tcp->u_arg[0]);
1721 }
1722 return 0;
1723}
1724
1725int
1726sys_chroot(tcp)
1727struct tcb *tcp;
1728{
1729 if (entering(tcp)) {
1730 printpath(tcp, tcp->u_arg[0]);
1731 }
1732 return 0;
1733}
1734
1735int
1736sys_fchroot(tcp)
1737struct tcb *tcp;
1738{
1739 if (entering(tcp)) {
1740 tprintf("%ld", tcp->u_arg[0]);
1741 }
1742 return 0;
1743}
1744
1745int
1746sys_link(tcp)
1747struct tcb *tcp;
1748{
1749 if (entering(tcp)) {
1750 printpath(tcp, tcp->u_arg[0]);
1751 tprintf(", ");
1752 printpath(tcp, tcp->u_arg[1]);
1753 }
1754 return 0;
1755}
1756
1757int
1758sys_unlink(tcp)
1759struct tcb *tcp;
1760{
1761 if (entering(tcp)) {
1762 printpath(tcp, tcp->u_arg[0]);
1763 }
1764 return 0;
1765}
1766
1767int
1768sys_symlink(tcp)
1769struct tcb *tcp;
1770{
1771 if (entering(tcp)) {
1772 printpath(tcp, tcp->u_arg[0]);
1773 tprintf(", ");
1774 printpath(tcp, tcp->u_arg[1]);
1775 }
1776 return 0;
1777}
1778
1779int
1780sys_readlink(tcp)
1781struct tcb *tcp;
1782{
1783 if (entering(tcp)) {
1784 printpath(tcp, tcp->u_arg[0]);
1785 tprintf(", ");
1786 } else {
1787 if (syserror(tcp))
1788 tprintf("%#lx", tcp->u_arg[1]);
1789 else
1790 printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
1791 tprintf(", %lu", tcp->u_arg[2]);
1792 }
1793 return 0;
1794}
1795
1796int
1797sys_rename(tcp)
1798struct tcb *tcp;
1799{
1800 if (entering(tcp)) {
1801 printpath(tcp, tcp->u_arg[0]);
1802 tprintf(", ");
1803 printpath(tcp, tcp->u_arg[1]);
1804 }
1805 return 0;
1806}
1807
1808int
1809sys_chown(tcp)
1810struct tcb *tcp;
1811{
1812 if (entering(tcp)) {
1813 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001814 printuid(", ", tcp->u_arg[1]);
1815 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001816 }
1817 return 0;
1818}
1819
1820int
1821sys_fchown(tcp)
1822struct tcb *tcp;
1823{
1824 if (entering(tcp)) {
Roland McGrath6bc12202003-11-13 22:32:27 +00001825 tprintf("%ld", tcp->u_arg[0]);
1826 printuid(", ", tcp->u_arg[1]);
1827 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001828 }
1829 return 0;
1830}
1831
1832int
1833sys_chmod(tcp)
1834struct tcb *tcp;
1835{
1836 if (entering(tcp)) {
1837 printpath(tcp, tcp->u_arg[0]);
1838 tprintf(", %#lo", tcp->u_arg[1]);
1839 }
1840 return 0;
1841}
1842
1843int
1844sys_fchmod(tcp)
1845struct tcb *tcp;
1846{
1847 if (entering(tcp)) {
1848 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
1849 }
1850 return 0;
1851}
1852
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001853#ifdef ALPHA
1854int
1855sys_osf_utimes(tcp)
1856struct tcb *tcp;
1857{
1858 if (entering(tcp)) {
1859 printpath(tcp, tcp->u_arg[0]);
1860 tprintf(", ");
1861 printtv32(tcp, tcp->u_arg[1]);
1862 }
1863 return 0;
1864}
1865#endif
1866
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001867int
1868sys_utimes(tcp)
1869struct tcb *tcp;
1870{
1871 if (entering(tcp)) {
1872 printpath(tcp, tcp->u_arg[0]);
1873 tprintf(", ");
1874 printtv(tcp, tcp->u_arg[1]);
1875 }
1876 return 0;
1877}
1878
1879int
1880sys_utime(tcp)
1881struct tcb *tcp;
1882{
1883 long ut[2];
1884
1885 if (entering(tcp)) {
1886 printpath(tcp, tcp->u_arg[0]);
1887 tprintf(", ");
1888 if (!tcp->u_arg[1])
1889 tprintf("NULL");
1890 else if (!verbose(tcp))
1891 tprintf("%#lx", tcp->u_arg[1]);
1892 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
1893 (char *) ut) < 0)
1894 tprintf("[?, ?]");
1895 else {
1896 tprintf("[%s,", sprinttime(ut[0]));
1897 tprintf(" %s]", sprinttime(ut[1]));
1898 }
1899 }
1900 return 0;
1901}
1902
1903int
1904sys_mknod(tcp)
1905struct tcb *tcp;
1906{
1907 int mode = tcp->u_arg[1];
1908
1909 if (entering(tcp)) {
1910 printpath(tcp, tcp->u_arg[0]);
1911 tprintf(", %s", sprintmode(mode));
1912 switch (mode & S_IFMT) {
1913 case S_IFCHR: case S_IFBLK:
1914#ifdef LINUXSPARC
1915 if (current_personality == 1)
1916 tprintf(", makedev(%lu, %lu)",
1917 (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
1918 (unsigned long) (tcp->u_arg[2] & 0x3ffff));
1919 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00001920#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001921 tprintf(", makedev(%lu, %lu)",
1922 (unsigned long) major(tcp->u_arg[2]),
1923 (unsigned long) minor(tcp->u_arg[2]));
1924 break;
1925 default:
1926 break;
1927 }
1928 }
1929 return 0;
1930}
1931
1932int
1933sys_mkfifo(tcp)
1934struct tcb *tcp;
1935{
1936 if (entering(tcp)) {
1937 printpath(tcp, tcp->u_arg[0]);
1938 tprintf(", %#lo", tcp->u_arg[1]);
1939 }
1940 return 0;
1941}
1942
1943int
1944sys_fsync(tcp)
1945struct tcb *tcp;
1946{
1947 if (entering(tcp)) {
1948 tprintf("%ld", tcp->u_arg[0]);
1949 }
1950 return 0;
1951}
1952
Michal Ludvig53b320f2002-09-23 13:30:09 +00001953#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001954
1955static void
1956printdir(tcp, addr)
1957struct tcb *tcp;
1958long addr;
1959{
1960 struct dirent d;
1961
1962 if (!verbose(tcp)) {
1963 tprintf("%#lx", addr);
1964 return;
1965 }
1966 if (umove(tcp, addr, &d) < 0) {
1967 tprintf("{...}");
1968 return;
1969 }
1970 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001971 tprintf("d_name=");
1972 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
1973 tprintf("}");
1974}
1975
1976int
1977sys_readdir(tcp)
1978struct tcb *tcp;
1979{
1980 if (entering(tcp)) {
1981 tprintf("%lu, ", tcp->u_arg[0]);
1982 } else {
1983 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
1984 tprintf("%#lx", tcp->u_arg[1]);
1985 else
1986 printdir(tcp, tcp->u_arg[1]);
1987 /* Not much point in printing this out, it is always 1. */
1988 if (tcp->u_arg[2] != 1)
1989 tprintf(", %lu", tcp->u_arg[2]);
1990 }
1991 return 0;
1992}
1993
Michal Ludvig53b320f2002-09-23 13:30:09 +00001994#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001995
Roland McGrath40542842004-01-13 09:47:49 +00001996#if defined FREEBSD || defined LINUX
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001997struct xlat direnttypes[] = {
Roland McGrath40542842004-01-13 09:47:49 +00001998 { DT_UNKNOWN, "DT_UNKNOWN" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001999 { DT_FIFO, "DT_FIFO" },
2000 { DT_CHR, "DT_CHR" },
2001 { DT_DIR, "DT_DIR" },
2002 { DT_BLK, "DT_BLK" },
2003 { DT_REG, "DT_REG" },
2004 { DT_LNK, "DT_LNK" },
2005 { DT_SOCK, "DT_SOCK" },
2006 { DT_WHT, "DT_WHT" },
2007 { 0, NULL },
2008};
2009
2010#endif
2011
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002012int
2013sys_getdents(tcp)
2014struct tcb *tcp;
2015{
2016 int i, len, dents = 0;
2017 char *buf;
2018
2019 if (entering(tcp)) {
2020 tprintf("%lu, ", tcp->u_arg[0]);
2021 return 0;
2022 }
2023 if (syserror(tcp) || !verbose(tcp)) {
2024 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2025 return 0;
2026 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002027 len = tcp->u_rval;
2028 if ((buf = malloc(len)) == NULL) {
2029 tprintf("out of memory\n");
2030 return 0;
2031 }
2032 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2033 tprintf("{...}, %lu", tcp->u_arg[2]);
2034 free(buf);
2035 return 0;
2036 }
2037 if (!abbrev(tcp))
2038 tprintf("{");
2039 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002040 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002041#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002042 if (!abbrev(tcp)) {
2043 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2044 i ? " " : "", d->d_ino, d->d_off);
2045 tprintf("d_reclen=%u, d_name=\"%s\"}",
2046 d->d_reclen, d->d_name);
2047 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002048#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002049#ifdef SVR4
2050 if (!abbrev(tcp)) {
2051 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002052 i ? " " : "",
2053 (unsigned long) d->d_ino,
2054 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002055 tprintf("d_reclen=%u, d_name=\"%s\"}",
2056 d->d_reclen, d->d_name);
2057 }
2058#endif /* SVR4 */
2059#ifdef SUNOS4
2060 if (!abbrev(tcp)) {
2061 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2062 i ? " " : "", d->d_off, d->d_fileno,
2063 d->d_reclen);
2064 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2065 d->d_namlen, d->d_namlen, d->d_name);
2066 }
2067#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002068#ifdef FREEBSD
2069 if (!abbrev(tcp)) {
2070 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2071 i ? " " : "", d->d_fileno, d->d_reclen);
2072 printxval(direnttypes, d->d_type, "DT_???");
2073 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2074 d->d_namlen, d->d_namlen, d->d_name);
2075 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002076#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002077 if (!d->d_reclen) {
2078 tprintf("/* d_reclen == 0, problem here */");
2079 break;
2080 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002081 i += d->d_reclen;
2082 dents++;
2083 }
2084 if (!abbrev(tcp))
2085 tprintf("}");
2086 else
2087 tprintf("/* %u entries */", dents);
2088 tprintf(", %lu", tcp->u_arg[2]);
2089 free(buf);
2090 return 0;
2091}
2092
John Hughesbdf48f52001-03-06 15:08:09 +00002093
2094#if _LFS64_LARGEFILE
2095int
2096sys_getdents64(tcp)
2097struct tcb *tcp;
2098{
2099 int i, len, dents = 0;
2100 char *buf;
2101
2102 if (entering(tcp)) {
2103 tprintf("%lu, ", tcp->u_arg[0]);
2104 return 0;
2105 }
2106 if (syserror(tcp) || !verbose(tcp)) {
2107 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2108 return 0;
2109 }
2110 len = tcp->u_rval;
2111 if ((buf = malloc(len)) == NULL) {
2112 tprintf("out of memory\n");
2113 return 0;
2114 }
2115 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2116 tprintf("{...}, %lu", tcp->u_arg[2]);
2117 free(buf);
2118 return 0;
2119 }
2120 if (!abbrev(tcp))
2121 tprintf("{");
2122 for (i = 0; i < len;) {
2123 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002124#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002125 if (!abbrev(tcp)) {
Roland McGrath92053242004-01-13 10:16:47 +00002126 tprintf("%s{d_ino=%llu, d_off=%llu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002127 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002128 d->d_ino,
2129 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002130#ifdef LINUX
2131 tprintf("d_type=");
2132 printxval(direnttypes, d->d_type, "DT_???");
2133 tprintf(", ");
2134#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002135 tprintf("d_reclen=%u, d_name=\"%s\"}",
2136 d->d_reclen, d->d_name);
2137 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002138#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002139#ifdef SUNOS4
2140 if (!abbrev(tcp)) {
2141 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2142 i ? " " : "", d->d_off, d->d_fileno,
2143 d->d_reclen);
2144 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2145 d->d_namlen, d->d_namlen, d->d_name);
2146 }
2147#endif /* SUNOS4 */
2148 i += d->d_reclen;
2149 dents++;
2150 }
2151 if (!abbrev(tcp))
2152 tprintf("}");
2153 else
2154 tprintf("/* %u entries */", dents);
2155 tprintf(", %lu", tcp->u_arg[2]);
2156 free(buf);
2157 return 0;
2158}
2159#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002160
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002161#ifdef FREEBSD
2162int
2163sys_getdirentries(tcp)
2164struct tcb * tcp;
2165{
2166 int i, len, dents = 0;
2167 long basep;
2168 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002169
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002170 if (entering(tcp)) {
2171 tprintf("%lu, ", tcp->u_arg[0]);
2172 return 0;
2173 }
2174 if (syserror(tcp) || !verbose(tcp)) {
2175 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2176 return 0;
2177 }
2178 len = tcp->u_rval;
2179 if ((buf = malloc(len)) == NULL) {
2180 tprintf("out of memory\n");
2181 return 0;
2182 }
2183 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2184 tprintf("{...}, %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3]);
2185 free(buf);
2186 return 0;
2187 }
2188 if (!abbrev(tcp))
2189 tprintf("{");
2190 for (i = 0; i < len;) {
2191 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2192 if (!abbrev(tcp)) {
2193 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2194 i ? " " : "", d->d_fileno, d->d_reclen);
2195 printxval(direnttypes, d->d_type, "DT_???");
2196 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2197 d->d_namlen, d->d_namlen, d->d_name);
2198 }
2199 i += d->d_reclen;
2200 dents++;
2201 }
2202 if (!abbrev(tcp))
2203 tprintf("}");
2204 else
2205 tprintf("/* %u entries */", dents);
2206 free(buf);
2207 tprintf(", %lu", tcp->u_arg[2]);
2208 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2209 tprintf(", %#lx", tcp->u_arg[3]);
2210 else
2211 tprintf(", [%lu]", basep);
2212 return 0;
2213}
2214#endif
2215
Michal Ludvig53b320f2002-09-23 13:30:09 +00002216#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002217int
2218sys_getcwd(tcp)
2219struct tcb *tcp;
2220{
2221 if (exiting(tcp)) {
2222 if (syserror(tcp))
2223 tprintf("%#lx", tcp->u_arg[0]);
2224 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002225 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002226 tprintf(", %lu", tcp->u_arg[1]);
2227 }
2228 return 0;
2229}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002230#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002231
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002232#ifdef FREEBSD
2233int
2234sys___getcwd(tcp)
2235struct tcb *tcp;
2236{
2237 if (exiting(tcp)) {
2238 if (syserror(tcp))
2239 tprintf("%#lx", tcp->u_arg[0]);
2240 else
2241 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2242 tprintf(", %lu", tcp->u_arg[1]);
2243 }
2244 return 0;
2245}
2246#endif
2247
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002248#ifdef HAVE_SYS_ASYNCH_H
2249
2250int
2251sys_aioread(tcp)
2252struct tcb *tcp;
2253{
2254 struct aio_result_t res;
2255
2256 if (entering(tcp)) {
2257 tprintf("%lu, ", tcp->u_arg[0]);
2258 } else {
2259 if (syserror(tcp))
2260 tprintf("%#lx", tcp->u_arg[1]);
2261 else
2262 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2263 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2264 printxval(whence, tcp->u_arg[4], "L_???");
2265 if (syserror(tcp) || tcp->u_arg[5] == 0
2266 || umove(tcp, tcp->u_arg[5], &res) < 0)
2267 tprintf(", %#lx", tcp->u_arg[5]);
2268 else
2269 tprintf(", {aio_return %d aio_errno %d}",
2270 res.aio_return, res.aio_errno);
2271 }
2272 return 0;
2273}
2274
2275int
2276sys_aiowrite(tcp)
2277struct tcb *tcp;
2278{
2279 struct aio_result_t res;
2280
2281 if (entering(tcp)) {
2282 tprintf("%lu, ", tcp->u_arg[0]);
2283 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2284 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2285 printxval(whence, tcp->u_arg[4], "L_???");
2286 }
2287 else {
2288 if (tcp->u_arg[5] == 0)
2289 tprintf(", NULL");
2290 else if (syserror(tcp)
2291 || umove(tcp, tcp->u_arg[5], &res) < 0)
2292 tprintf(", %#lx", tcp->u_arg[5]);
2293 else
2294 tprintf(", {aio_return %d aio_errno %d}",
2295 res.aio_return, res.aio_errno);
2296 }
2297 return 0;
2298}
2299
2300int
2301sys_aiowait(tcp)
2302struct tcb *tcp;
2303{
2304 if (entering(tcp))
2305 printtv(tcp, tcp->u_arg[0]);
2306 return 0;
2307}
2308
2309int
2310sys_aiocancel(tcp)
2311struct tcb *tcp;
2312{
2313 struct aio_result_t res;
2314
2315 if (exiting(tcp)) {
2316 if (tcp->u_arg[0] == 0)
2317 tprintf("NULL");
2318 else if (syserror(tcp)
2319 || umove(tcp, tcp->u_arg[0], &res) < 0)
2320 tprintf("%#lx", tcp->u_arg[0]);
2321 else
2322 tprintf("{aio_return %d aio_errno %d}",
2323 res.aio_return, res.aio_errno);
2324 }
2325 return 0;
2326}
2327
2328#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002329
Roland McGrath186c5ac2002-12-15 23:58:23 +00002330struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002331#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002332 { XATTR_CREATE, "XATTR_CREATE" },
2333 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002334#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002335 { 0, NULL }
2336};
2337
Roland McGrath3292e222004-08-31 06:30:48 +00002338static void
2339print_xattr_val(tcp, failed, arg, insize, size)
2340struct tcb *tcp;
2341int failed;
2342unsigned long arg;
2343size_t size;
2344{
2345 unsigned char buf[4 * size + 1];
2346 if (!failed && umoven(tcp, arg, size, &buf[3 * size]) >= 0) {
2347 unsigned char *out = buf;
2348 unsigned char *in = &buf[3 * size];
2349 size_t i;
2350 for (i = 0; i < size; ++i)
2351 if (isprint(in[i]))
2352 *out++ = in[i];
2353 else {
2354#define tohex(n) "0123456789abcdef"[n]
2355 *out++ = '\\';
2356 *out++ = 'x';
2357 *out++ = tohex(in[i] / 16);
2358 *out++ = tohex(in[i] % 16);
2359 }
2360 /* Don't print terminating NUL if there is one. */
2361 if (in[i - 1] == '\0')
2362 out -= 4;
2363 *out = '\0';
2364 tprintf(", \"%s\", %zd", buf, insize);
2365 } else
2366 tprintf(", 0x%lx, %zd", arg, insize);
2367}
2368
Roland McGrath186c5ac2002-12-15 23:58:23 +00002369int
2370sys_setxattr(tcp)
2371struct tcb *tcp;
2372{
2373 if (entering(tcp)) {
2374 printpath(tcp, tcp->u_arg[0]);
2375 tprintf(", ");
2376 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002377 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2378 tprintf(", ");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002379 printflags(xattrflags, tcp->u_arg[4]);
2380 }
2381 return 0;
2382}
2383
2384int
2385sys_fsetxattr(tcp)
2386struct tcb *tcp;
2387{
2388 if (entering(tcp)) {
2389 tprintf("%ld, ", tcp->u_arg[0]);
2390 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002391 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2392 tprintf(", ");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002393 printflags(xattrflags, tcp->u_arg[4]);
2394 }
2395 return 0;
2396}
2397
2398int
2399sys_getxattr(tcp)
2400struct tcb *tcp;
2401{
2402 if (entering(tcp)) {
2403 printpath(tcp, tcp->u_arg[0]);
2404 tprintf(", ");
2405 printstr(tcp, tcp->u_arg[1], -1);
2406 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002407 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2408 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002409 }
2410 return 0;
2411}
2412
2413int
2414sys_fgetxattr(tcp)
2415struct tcb *tcp;
2416{
2417 if (entering(tcp)) {
2418 tprintf("%ld, ", tcp->u_arg[0]);
2419 printstr(tcp, tcp->u_arg[1], -1);
2420 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002421 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2422 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002423 }
2424 return 0;
2425}
2426
2427int
2428sys_listxattr(tcp)
2429struct tcb *tcp;
2430{
2431 if (entering(tcp)) {
2432 printpath(tcp, tcp->u_arg[0]);
2433 } else {
2434 /* XXX Print value in format */
2435 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2436 }
2437 return 0;
2438}
2439
2440int
2441sys_flistxattr(tcp)
2442struct tcb *tcp;
2443{
2444 if (entering(tcp)) {
2445 tprintf("%ld", tcp->u_arg[0]);
2446 } else {
2447 /* XXX Print value in format */
2448 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2449 }
2450 return 0;
2451}
2452
2453int
2454sys_removexattr(tcp)
2455struct tcb *tcp;
2456{
2457 if (entering(tcp)) {
2458 printpath(tcp, tcp->u_arg[0]);
2459 tprintf(", ");
2460 printstr(tcp, tcp->u_arg[1], -1);
2461 }
2462 return 0;
2463}
2464
2465int
2466sys_fremovexattr(tcp)
2467struct tcb *tcp;
2468{
2469 if (entering(tcp)) {
2470 tprintf("%ld, ", tcp->u_arg[0]);
2471 printstr(tcp, tcp->u_arg[1], -1);
2472 }
2473 return 0;
2474}