blob: 2f1275a47094e7bc92042232c592b86a2e684e14 [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
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
Roland McGrathd9f816f2004-09-04 03:39:20 +0000315const struct xlat openmodessol[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000316 { 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
Roland McGrathd9f816f2004-09-04 03:39:20 +0000363static const struct xlat access_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000364 { 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
Roland McGrathd9f816f2004-09-04 03:39:20 +0000399static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000400 { 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],
Roland McGrath2fe2a3e2004-10-07 19:09:16 +0000436 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000437 else
438 tprintf("%ld, %lld, ", tcp->u_arg[0],
Roland McGrath2fe2a3e2004-10-07 19:09:16 +0000439 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000440 }
441 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000442 long long int off;
443 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000444 tprintf("%#lx, ", tcp->u_arg[3]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000445 else
446 tprintf("[%llu], ", off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000447 printxval(whence, tcp->u_arg[4], "SEEK_???");
448 }
449 return 0;
450}
Roland McGrath186c5ac2002-12-15 23:58:23 +0000451
452int
453sys_readahead (tcp)
454struct tcb *tcp;
455{
456 if (entering(tcp)) {
457 tprintf("%ld, %lld, %ld", tcp->u_arg[0],
458# if defined IA64 || defined X86_64 || defined ALPHA
459 (long long int) tcp->u_arg[1], tcp->u_arg[2]
460# else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +0000461 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]
Roland McGrath186c5ac2002-12-15 23:58:23 +0000462# endif
463 );
464 }
465 return 0;
466}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000467#endif
468
John Hughes70623be2001-03-08 13:59:00 +0000469#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000470int
471sys_lseek64 (tcp)
472struct tcb *tcp;
473{
474 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000475 long long offset;
476 ALIGN64 (tcp, 1); /* FreeBSD aligns off_t args */
John Hughes0c79e012001-03-08 14:40:06 +0000477 offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +0000478 if (tcp->u_arg[3] == SEEK_SET)
479 tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
480 else
481 tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
482 printxval(whence, tcp->u_arg[3], "SEEK_???");
483 }
484 return RVAL_LUDECIMAL;
485}
486#endif
487
John Hughes70623be2001-03-08 13:59:00 +0000488#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000489int
490sys_truncate(tcp)
491struct tcb *tcp;
492{
493 if (entering(tcp)) {
494 printpath(tcp, tcp->u_arg[0]);
495 tprintf(", %lu", tcp->u_arg[1]);
496 }
497 return 0;
498}
John Hughes5a826b82001-03-07 13:21:24 +0000499#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000500
John Hughes70623be2001-03-08 13:59:00 +0000501#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000502int
503sys_truncate64(tcp)
504struct tcb *tcp;
505{
506 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000507 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000508 printpath(tcp, tcp->u_arg[0]);
John Hughes0c79e012001-03-08 14:40:06 +0000509 tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000510 }
511 return 0;
512}
513#endif
514
John Hughes70623be2001-03-08 13:59:00 +0000515#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000516int
517sys_ftruncate(tcp)
518struct tcb *tcp;
519{
520 if (entering(tcp)) {
521 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
522 }
523 return 0;
524}
John Hughes5a826b82001-03-07 13:21:24 +0000525#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000526
John Hughes70623be2001-03-08 13:59:00 +0000527#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000528int
529sys_ftruncate64(tcp)
530struct tcb *tcp;
531{
532 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000533 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000534 tprintf("%ld, %llu", tcp->u_arg[0],
John Hughes0c79e012001-03-08 14:40:06 +0000535 LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000536 }
537 return 0;
538}
539#endif
540
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541/* several stats */
542
Roland McGrathd9f816f2004-09-04 03:39:20 +0000543static const struct xlat modetypes[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000544 { S_IFREG, "S_IFREG" },
545 { S_IFSOCK, "S_IFSOCK" },
546 { S_IFIFO, "S_IFIFO" },
547 { S_IFLNK, "S_IFLNK" },
548 { S_IFDIR, "S_IFDIR" },
549 { S_IFBLK, "S_IFBLK" },
550 { S_IFCHR, "S_IFCHR" },
551 { 0, NULL },
552};
553
Roland McGrathf9c49b22004-10-06 22:11:54 +0000554static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000555sprintmode(mode)
556int mode;
557{
558 static char buf[64];
Roland McGrathf9c49b22004-10-06 22:11:54 +0000559 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000560
561 if ((mode & S_IFMT) == 0)
562 s = "";
563 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
564 sprintf(buf, "%#o", mode);
565 return buf;
566 }
567 sprintf(buf, "%s%s%s%s", s,
568 (mode & S_ISUID) ? "|S_ISUID" : "",
569 (mode & S_ISGID) ? "|S_ISGID" : "",
570 (mode & S_ISVTX) ? "|S_ISVTX" : "");
571 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
572 if (mode)
573 sprintf(buf + strlen(buf), "|%#o", mode);
574 s = (*buf == '|') ? buf + 1 : buf;
575 return *s ? s : "0";
576}
577
578static char *
579sprinttime(t)
580time_t t;
581{
582 struct tm *tmp;
583 static char buf[32];
584
585 if (t == 0) {
586 sprintf(buf, "0");
587 return buf;
588 }
589 tmp = localtime(&t);
590 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
Wichert Akkerman3ed6dc22000-01-11 14:41:09 +0000591 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000592 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
593 return buf;
594}
595
596#ifdef LINUXSPARC
597typedef struct {
598 int tv_sec;
599 int tv_nsec;
600} timestruct_t;
601
602struct solstat {
603 unsigned st_dev;
604 int st_pad1[3]; /* network id */
605 unsigned st_ino;
606 unsigned st_mode;
607 unsigned st_nlink;
608 unsigned st_uid;
609 unsigned st_gid;
610 unsigned st_rdev;
611 int st_pad2[2];
612 int st_size;
613 int st_pad3; /* st_size, off_t expansion */
614 timestruct_t st_atime;
615 timestruct_t st_mtime;
616 timestruct_t st_ctime;
617 int st_blksize;
618 int st_blocks;
619 char st_fstype[16];
620 int st_pad4[8]; /* expansion area */
621};
622
623static void
624printstatsol(tcp, addr)
625struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000626long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000627{
628 struct solstat statbuf;
629
630 if (!addr) {
631 tprintf("NULL");
632 return;
633 }
634 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000635 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000636 return;
637 }
638 if (umove(tcp, addr, &statbuf) < 0) {
639 tprintf("{...}");
640 return;
641 }
642 if (!abbrev(tcp)) {
643 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
644 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
645 (unsigned long) (statbuf.st_dev & 0x3ffff),
646 (unsigned long) statbuf.st_ino,
647 sprintmode(statbuf.st_mode));
648 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
649 (unsigned long) statbuf.st_nlink,
650 (unsigned long) statbuf.st_uid,
651 (unsigned long) statbuf.st_gid);
652 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
653 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
654 }
655 else
656 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
657 switch (statbuf.st_mode & S_IFMT) {
658 case S_IFCHR: case S_IFBLK:
659 tprintf("st_rdev=makedev(%lu, %lu), ",
660 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
661 (unsigned long) (statbuf.st_rdev & 0x3ffff));
662 break;
663 default:
664 tprintf("st_size=%u, ", statbuf.st_size);
665 break;
666 }
667 if (!abbrev(tcp)) {
668 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
669 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
670 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
671 }
672 else
673 tprintf("...}");
674}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000675
676#if defined (SPARC64)
677static void
678printstat_sparc64(tcp, addr)
679struct tcb *tcp;
680long addr;
681{
682 struct stat_sparc64 statbuf;
683
684 if (!addr) {
685 tprintf("NULL");
686 return;
687 }
688 if (syserror(tcp) || !verbose(tcp)) {
689 tprintf("%#lx", addr);
690 return;
691 }
692 if (umove(tcp, addr, &statbuf) < 0) {
693 tprintf("{...}");
694 return;
695 }
696
697 if (!abbrev(tcp)) {
698 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
699 (unsigned long) major(statbuf.st_dev),
700 (unsigned long) minor(statbuf.st_dev),
701 (unsigned long) statbuf.st_ino,
702 sprintmode(statbuf.st_mode));
703 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
704 (unsigned long) statbuf.st_nlink,
705 (unsigned long) statbuf.st_uid,
706 (unsigned long) statbuf.st_gid);
707 tprintf("st_blksize=%lu, ",
708 (unsigned long) statbuf.st_blksize);
709 tprintf("st_blocks=%lu, ",
710 (unsigned long) statbuf.st_blocks);
711 }
712 else
713 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
714 switch (statbuf.st_mode & S_IFMT) {
715 case S_IFCHR: case S_IFBLK:
716 tprintf("st_rdev=makedev(%lu, %lu), ",
717 (unsigned long) major(statbuf.st_rdev),
718 (unsigned long) minor(statbuf.st_rdev));
719 break;
720 default:
721 tprintf("st_size=%lu, ", statbuf.st_size);
722 break;
723 }
724 if (!abbrev(tcp)) {
725 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
726 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
727 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
728 tprintf("}");
729 }
730 else
731 tprintf("...}");
732}
733#endif /* SPARC64 */
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000734#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000735
Roland McGrathd9f816f2004-09-04 03:39:20 +0000736const struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000737#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000738 { UF_NODUMP, "UF_NODUMP" },
739 { UF_IMMUTABLE, "UF_IMMUTABLE" },
740 { UF_APPEND, "UF_APPEND" },
741 { UF_OPAQUE, "UF_OPAQUE" },
742 { UF_NOUNLINK, "UF_NOUNLINK" },
743 { SF_ARCHIVED, "SF_ARCHIVED" },
744 { SF_IMMUTABLE, "SF_IMMUTABLE" },
745 { SF_APPEND, "SF_APPEND" },
746 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000747#elif UNIXWARE >= 2
748#ifdef _S_ISMLD
749 { _S_ISMLD, "_S_ISMLD" },
750#endif
751#ifdef _S_ISMOUNTED
752 { _S_ISMOUNTED, "_S_ISMOUNTED" },
753#endif
754#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000755 { 0, NULL },
756};
757
John Hughesc0fc3fd2001-03-08 16:10:40 +0000758#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000759int
760sys_chflags(tcp)
761struct tcb *tcp;
762{
763 if (entering(tcp)) {
764 printpath(tcp, tcp->u_arg[0]);
765 tprintf(", ");
766 if (tcp->u_arg[1])
767 printflags(fileflags, tcp->u_arg[1]);
768 else
769 tprintf("0");
770 }
771 return 0;
772}
773
774int
775sys_fchflags(tcp)
776struct tcb *tcp;
777{
778 if (entering(tcp)) {
779 tprintf("%ld, ", tcp->u_arg[0]);
780 if (tcp->u_arg[1])
781 printflags(fileflags, tcp->u_arg[1]);
782 else
783 tprintf("0");
784 }
785 return 0;
786}
787#endif
788
John Hughes70623be2001-03-08 13:59:00 +0000789#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000790static void
791realprintstat(tcp, statbuf)
792struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000793struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000794{
795 if (!abbrev(tcp)) {
796 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
797 (unsigned long) major(statbuf->st_dev),
798 (unsigned long) minor(statbuf->st_dev),
799 (unsigned long) statbuf->st_ino,
800 sprintmode(statbuf->st_mode));
801 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
802 (unsigned long) statbuf->st_nlink,
803 (unsigned long) statbuf->st_uid,
804 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000805#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000806 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000807#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
808#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000809 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000810#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000811 }
812 else
813 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
814 switch (statbuf->st_mode & S_IFMT) {
815 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000816#ifdef HAVE_STRUCT_STAT_ST_RDEV
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000817 tprintf("st_rdev=makedev(%lu, %lu), ",
818 (unsigned long) major(statbuf->st_rdev),
819 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000820#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000821 tprintf("st_size=makedev(%lu, %lu), ",
822 (unsigned long) major(statbuf->st_size),
823 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000824#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000825 break;
826 default:
827 tprintf("st_size=%lu, ", statbuf->st_size);
828 break;
829 }
830 if (!abbrev(tcp)) {
831 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
832 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000833 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000834#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000835 tprintf(", st_flags=");
836 if (statbuf->st_flags) {
837 printflags(fileflags, statbuf->st_flags);
838 } else
839 tprintf("0");
840#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000841#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000842 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
843#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000844#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000845 tprintf(", st_level=%ld", statbuf->st_level);
846#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000847#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000848 tprintf(", st_fstype=%.*s",
849 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
850#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000851#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000852 tprintf(", st_gen=%u", statbuf->st_gen);
853#endif
854 tprintf("}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000855 }
856 else
857 tprintf("...}");
858}
859
Nate Sammons771a6ff1999-04-05 22:39:31 +0000860
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000861static void
862printstat(tcp, addr)
863struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000864long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000865{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000866 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000867
868#ifdef LINUXSPARC
869 if (current_personality == 1) {
870 printstatsol(tcp, addr);
871 return;
872 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000873#ifdef SPARC64
874 else if (current_personality == 2) {
875 printstat_sparc64(tcp, addr);
876 return;
877 }
878#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000879#endif /* LINUXSPARC */
880
881 if (!addr) {
882 tprintf("NULL");
883 return;
884 }
885 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000886 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000887 return;
888 }
889 if (umove(tcp, addr, &statbuf) < 0) {
890 tprintf("{...}");
891 return;
892 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000893
894 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000895}
John Hughes70623be2001-03-08 13:59:00 +0000896#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000897
Wichert Akkermanc7926982000-04-10 22:22:31 +0000898#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000899static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000900printstat64(tcp, addr)
901struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000902long addr;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000903{
904 struct stat64 statbuf;
905
906#ifdef LINUXSPARC
907 if (current_personality == 1) {
908 printstatsol(tcp, addr);
909 return;
910 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000911#ifdef SPARC64
912 else if (current_personality == 2) {
913 printstat_sparc64(tcp, addr);
914 return;
915 }
916#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000917#endif /* LINUXSPARC */
918
919 if (!addr) {
920 tprintf("NULL");
921 return;
922 }
923 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000924 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000925 return;
926 }
927 if (umove(tcp, addr, &statbuf) < 0) {
928 tprintf("{...}");
929 return;
930 }
931
932 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +0000933#ifdef HAVE_LONG_LONG
934 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
935#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000936 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +0000937#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000938 (unsigned long) major(statbuf.st_dev),
939 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +0000940#ifdef HAVE_LONG_LONG
941 (unsigned long long) statbuf.st_ino,
942#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000943 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +0000944#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000945 sprintmode(statbuf.st_mode));
946 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
947 (unsigned long) statbuf.st_nlink,
948 (unsigned long) statbuf.st_uid,
949 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000950#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000951 tprintf("st_blksize=%lu, ",
952 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000953#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
954#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000955 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000956#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000957 }
958 else
959 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
960 switch (statbuf.st_mode & S_IFMT) {
961 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000962#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000963 tprintf("st_rdev=makedev(%lu, %lu), ",
964 (unsigned long) major(statbuf.st_rdev),
965 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000966#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000967 tprintf("st_size=makedev(%lu, %lu), ",
968 (unsigned long) major(statbuf.st_size),
969 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000970#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000971 break;
972 default:
973 tprintf("st_size=%llu, ", statbuf.st_size);
974 break;
975 }
976 if (!abbrev(tcp)) {
977 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
978 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000979 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000980#if HAVE_STRUCT_STAT_ST_FLAGS
John Hughesc0fc3fd2001-03-08 16:10:40 +0000981 tprintf(", st_flags=");
John Hughesb8c9f772001-03-07 16:53:07 +0000982 if (statbuf.st_flags) {
983 printflags(fileflags, statbuf.st_flags);
984 } else
985 tprintf("0");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000986#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000987#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000988 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
989#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000990#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000991 tprintf(", st_level=%ld", statbuf.st_level);
992#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000993#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000994 tprintf(", st_fstype=%.*s",
995 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
996#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000997#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000998 tprintf(", st_gen=%u", statbuf.st_gen);
999#endif
1000 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001001 }
1002 else
1003 tprintf("...}");
1004}
Wichert Akkermanc7926982000-04-10 22:22:31 +00001005#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001006
Roland McGrath79db8af2003-06-27 21:20:09 +00001007#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001008static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001009convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001010const struct __old_kernel_stat *oldbuf;
1011struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001012{
1013 newbuf->st_dev=oldbuf->st_dev;
1014 newbuf->st_ino=oldbuf->st_ino;
1015 newbuf->st_mode=oldbuf->st_mode;
1016 newbuf->st_nlink=oldbuf->st_nlink;
1017 newbuf->st_uid=oldbuf->st_uid;
1018 newbuf->st_gid=oldbuf->st_gid;
1019 newbuf->st_rdev=oldbuf->st_rdev;
1020 newbuf->st_size=oldbuf->st_size;
1021 newbuf->st_atime=oldbuf->st_atime;
1022 newbuf->st_mtime=oldbuf->st_mtime;
1023 newbuf->st_ctime=oldbuf->st_ctime;
1024 newbuf->st_blksize=0; /* not supported in old_stat */
1025 newbuf->st_blocks=0; /* not supported in old_stat */
1026}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001027
1028
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001029static void
1030printoldstat(tcp, addr)
1031struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001032long addr;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001033{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +00001034 struct __old_kernel_stat statbuf;
1035 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001036
1037#ifdef LINUXSPARC
1038 if (current_personality == 1) {
1039 printstatsol(tcp, addr);
1040 return;
1041 }
1042#endif /* LINUXSPARC */
1043
1044 if (!addr) {
1045 tprintf("NULL");
1046 return;
1047 }
1048 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001049 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001050 return;
1051 }
1052 if (umove(tcp, addr, &statbuf) < 0) {
1053 tprintf("{...}");
1054 return;
1055 }
1056
1057 convertoldstat(&statbuf, &newstatbuf);
1058 realprintstat(tcp, &newstatbuf);
1059}
Michal Ludvig10a88d02002-10-07 14:31:00 +00001060#endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001061
John Hughes70623be2001-03-08 13:59:00 +00001062#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001063int
1064sys_stat(tcp)
1065struct tcb *tcp;
1066{
1067 if (entering(tcp)) {
1068 printpath(tcp, tcp->u_arg[0]);
1069 tprintf(", ");
1070 } else {
1071 printstat(tcp, tcp->u_arg[1]);
1072 }
1073 return 0;
1074}
John Hughesb8c9f772001-03-07 16:53:07 +00001075#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001076
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001077int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001078sys_stat64(tcp)
1079struct tcb *tcp;
1080{
1081#ifdef HAVE_STAT64
1082 if (entering(tcp)) {
1083 printpath(tcp, tcp->u_arg[0]);
1084 tprintf(", ");
1085 } else {
1086 printstat64(tcp, tcp->u_arg[1]);
1087 }
1088 return 0;
1089#else
1090 return printargs(tcp);
1091#endif
1092}
1093
Roland McGrath79db8af2003-06-27 21:20:09 +00001094#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001095int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001096sys_oldstat(tcp)
1097struct tcb *tcp;
1098{
1099 if (entering(tcp)) {
1100 printpath(tcp, tcp->u_arg[0]);
1101 tprintf(", ");
1102 } else {
1103 printoldstat(tcp, tcp->u_arg[1]);
1104 }
1105 return 0;
1106}
Roland McGrath79db8af2003-06-27 21:20:09 +00001107#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001108
John Hughes70623be2001-03-08 13:59:00 +00001109#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001110int
1111sys_fstat(tcp)
1112struct tcb *tcp;
1113{
1114 if (entering(tcp))
1115 tprintf("%ld, ", tcp->u_arg[0]);
1116 else {
1117 printstat(tcp, tcp->u_arg[1]);
1118 }
1119 return 0;
1120}
John Hughesb8c9f772001-03-07 16:53:07 +00001121#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001122
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001123int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001124sys_fstat64(tcp)
1125struct tcb *tcp;
1126{
1127#ifdef HAVE_STAT64
1128 if (entering(tcp))
1129 tprintf("%ld, ", tcp->u_arg[0]);
1130 else {
1131 printstat64(tcp, tcp->u_arg[1]);
1132 }
1133 return 0;
1134#else
1135 return printargs(tcp);
1136#endif
1137}
1138
Roland McGrath79db8af2003-06-27 21:20:09 +00001139#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001140int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001141sys_oldfstat(tcp)
1142struct tcb *tcp;
1143{
1144 if (entering(tcp))
1145 tprintf("%ld, ", tcp->u_arg[0]);
1146 else {
1147 printoldstat(tcp, tcp->u_arg[1]);
1148 }
1149 return 0;
1150}
Roland McGrath79db8af2003-06-27 21:20:09 +00001151#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001152
John Hughes70623be2001-03-08 13:59:00 +00001153#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001154int
1155sys_lstat(tcp)
1156struct tcb *tcp;
1157{
1158 if (entering(tcp)) {
1159 printpath(tcp, tcp->u_arg[0]);
1160 tprintf(", ");
1161 } else {
1162 printstat(tcp, tcp->u_arg[1]);
1163 }
1164 return 0;
1165}
John Hughesb8c9f772001-03-07 16:53:07 +00001166#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001167
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001168int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001169sys_lstat64(tcp)
1170struct tcb *tcp;
1171{
1172#ifdef HAVE_STAT64
1173 if (entering(tcp)) {
1174 printpath(tcp, tcp->u_arg[0]);
1175 tprintf(", ");
1176 } else {
1177 printstat64(tcp, tcp->u_arg[1]);
1178 }
1179 return 0;
1180#else
1181 return printargs(tcp);
1182#endif
1183}
1184
Roland McGrath79db8af2003-06-27 21:20:09 +00001185#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001186int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001187sys_oldlstat(tcp)
1188struct tcb *tcp;
1189{
1190 if (entering(tcp)) {
1191 printpath(tcp, tcp->u_arg[0]);
1192 tprintf(", ");
1193 } else {
1194 printoldstat(tcp, tcp->u_arg[1]);
1195 }
1196 return 0;
1197}
Roland McGrath79db8af2003-06-27 21:20:09 +00001198#endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001199
1200
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001201#if defined(SVR4) || defined(LINUXSPARC)
1202
1203int
1204sys_xstat(tcp)
1205struct tcb *tcp;
1206{
1207 if (entering(tcp)) {
1208 tprintf("%ld, ", tcp->u_arg[0]);
1209 printpath(tcp, tcp->u_arg[1]);
1210 tprintf(", ");
1211 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001212#ifdef _STAT64_VER
1213 if (tcp->u_arg[0] == _STAT64_VER)
1214 printstat64 (tcp, tcp->u_arg[2]);
1215 else
1216#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001217 printstat(tcp, tcp->u_arg[2]);
1218 }
1219 return 0;
1220}
1221
1222int
1223sys_fxstat(tcp)
1224struct tcb *tcp;
1225{
1226 if (entering(tcp))
1227 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1228 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001229#ifdef _STAT64_VER
1230 if (tcp->u_arg[0] == _STAT64_VER)
1231 printstat64 (tcp, tcp->u_arg[2]);
1232 else
1233#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001234 printstat(tcp, tcp->u_arg[2]);
1235 }
1236 return 0;
1237}
1238
1239int
1240sys_lxstat(tcp)
1241struct tcb *tcp;
1242{
1243 if (entering(tcp)) {
1244 tprintf("%ld, ", tcp->u_arg[0]);
1245 printpath(tcp, tcp->u_arg[1]);
1246 tprintf(", ");
1247 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001248#ifdef _STAT64_VER
1249 if (tcp->u_arg[0] == _STAT64_VER)
1250 printstat64 (tcp, tcp->u_arg[2]);
1251 else
1252#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001253 printstat(tcp, tcp->u_arg[2]);
1254 }
1255 return 0;
1256}
1257
1258int
1259sys_xmknod(tcp)
1260struct tcb *tcp;
1261{
1262 int mode = tcp->u_arg[2];
1263
1264 if (entering(tcp)) {
1265 tprintf("%ld, ", tcp->u_arg[0]);
1266 printpath(tcp, tcp->u_arg[1]);
1267 tprintf(", %s", sprintmode(mode));
1268 switch (mode & S_IFMT) {
1269 case S_IFCHR: case S_IFBLK:
1270#ifdef LINUXSPARC
1271 tprintf(", makedev(%lu, %lu)",
1272 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1273 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001274#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001275 tprintf(", makedev(%lu, %lu)",
1276 (unsigned long) major(tcp->u_arg[3]),
1277 (unsigned long) minor(tcp->u_arg[3]));
Roland McGrath186c5ac2002-12-15 23:58:23 +00001278#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001279 break;
1280 default:
1281 break;
1282 }
1283 }
1284 return 0;
1285}
1286
Wichert Akkerman8829a551999-06-11 13:18:40 +00001287#ifdef HAVE_SYS_ACL_H
1288
1289#include <sys/acl.h>
1290
Roland McGrathd9f816f2004-09-04 03:39:20 +00001291const struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001292#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001293 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001294#endif
1295#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001296 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001297#endif
1298#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001299 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001300#endif
1301#ifdef ACL_GET
1302 { ACL_GET, "ACL_GET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001303#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001304#ifdef ACL_SET
1305 { ACL_SET, "ACL_SET" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001306#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001307#ifdef ACL_CNT
1308 { ACL_CNT, "ACL_CNT" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001309#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001310 { 0, NULL },
1311};
1312
1313int
1314sys_acl(tcp)
1315struct tcb *tcp;
1316{
1317 if (entering(tcp)) {
1318 printpath(tcp, tcp->u_arg[0]);
1319 tprintf(", ");
1320 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1321 tprintf(", %ld", tcp->u_arg[2]);
1322 /*
1323 * FIXME - dump out the list of aclent_t's pointed to
1324 * by "tcp->u_arg[3]" if it's not NULL.
1325 */
1326 if (tcp->u_arg[3])
1327 tprintf(", %#lx", tcp->u_arg[3]);
1328 else
1329 tprintf(", NULL");
1330 }
1331 return 0;
1332}
1333
1334
1335int
1336sys_facl(tcp)
1337struct tcb *tcp;
1338{
1339 if (entering(tcp)) {
1340 tprintf("%ld, ", tcp->u_arg[0]);
1341 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1342 tprintf(", %ld", tcp->u_arg[2]);
1343 /*
1344 * FIXME - dump out the list of aclent_t's pointed to
1345 * by "tcp->u_arg[3]" if it's not NULL.
1346 */
1347 if (tcp->u_arg[3])
1348 tprintf(", %#lx", tcp->u_arg[3]);
1349 else
1350 tprintf(", NULL");
1351 }
1352 return 0;
1353}
1354
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001355
Roland McGrathd9f816f2004-09-04 03:39:20 +00001356const struct xlat aclipc[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001357#ifdef IPC_SHM
1358 { IPC_SHM, "IPC_SHM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001359#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001360#ifdef IPC_SEM
1361 { IPC_SEM, "IPC_SEM" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001362#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001363#ifdef IPC_MSG
1364 { IPC_MSG, "IPC_MSG" },
Roland McGrath186c5ac2002-12-15 23:58:23 +00001365#endif
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001366 { 0, NULL },
1367};
1368
1369
1370int
1371sys_aclipc(tcp)
1372struct tcb *tcp;
1373{
1374 if (entering(tcp)) {
1375 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1376 tprintf(", %#lx, ", tcp->u_arg[1]);
1377 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1378 tprintf(", %ld", tcp->u_arg[3]);
1379 /*
1380 * FIXME - dump out the list of aclent_t's pointed to
1381 * by "tcp->u_arg[4]" if it's not NULL.
1382 */
1383 if (tcp->u_arg[4])
1384 tprintf(", %#lx", tcp->u_arg[4]);
1385 else
1386 tprintf(", NULL");
1387 }
1388 return 0;
1389}
1390
1391
1392
Wichert Akkerman8829a551999-06-11 13:18:40 +00001393#endif /* HAVE_SYS_ACL_H */
1394
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001395#endif /* SVR4 || LINUXSPARC */
1396
Michal Ludvig53b320f2002-09-23 13:30:09 +00001397#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001398
Roland McGrathd9f816f2004-09-04 03:39:20 +00001399static const struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001400 { 0x73757245, "CODA_SUPER_MAGIC" },
1401 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1402 { 0x1373, "DEVFS_SUPER_MAGIC" },
1403 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1404 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001405 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1406 { 0xef53, "EXT2_SUPER_MAGIC" },
1407 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001408 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001409 { 0x9660, "ISOFS_SUPER_MAGIC" },
1410 { 0x137f, "MINIX_SUPER_MAGIC" },
1411 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001412 { 0x2468, "MINIX2_SUPER_MAGIC" },
1413 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001414 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001415 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001416 { 0x6969, "NFS_SUPER_MAGIC" },
1417 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001418 { 0x002f, "QNX4_SUPER_MAGIC" },
1419 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1420 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1421 { 0x517b, "SMB_SUPER_MAGIC" },
1422 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1423 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1424 { 0x00011954, "UFS_MAGIC" },
1425 { 0x54190100, "UFS_CIGAM" },
1426 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001427 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
Roland McGrathc767ad82004-01-13 10:13:45 +00001428 { 0x62656572, "SYSFS_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001429 { 0, NULL },
1430};
1431
Michal Ludvig53b320f2002-09-23 13:30:09 +00001432#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001433
1434#ifndef SVR4
1435
Roland McGrathf9c49b22004-10-06 22:11:54 +00001436static const char *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001437sprintfstype(magic)
1438int magic;
1439{
1440 static char buf[32];
Michal Ludvig53b320f2002-09-23 13:30:09 +00001441#ifdef LINUX
Roland McGrathf9c49b22004-10-06 22:11:54 +00001442 const char *s;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001443
1444 s = xlookup(fsmagic, magic);
1445 if (s) {
1446 sprintf(buf, "\"%s\"", s);
1447 return buf;
1448 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00001449#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001450 sprintf(buf, "%#x", magic);
1451 return buf;
1452}
1453
1454static void
1455printstatfs(tcp, addr)
1456struct tcb *tcp;
1457long addr;
1458{
1459 struct statfs statbuf;
1460
1461 if (syserror(tcp) || !verbose(tcp)) {
1462 tprintf("%#lx", addr);
1463 return;
1464 }
1465 if (umove(tcp, addr, &statbuf) < 0) {
1466 tprintf("{...}");
1467 return;
1468 }
1469#ifdef ALPHA
1470
1471 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1472 sprintfstype(statbuf.f_type),
1473 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001474 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1475 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1476 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1477 statbuf.f_namelen);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001478#else /* !ALPHA */
1479 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1480 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001481 (unsigned long)statbuf.f_bsize,
1482 (unsigned long)statbuf.f_blocks,
1483 (unsigned long)statbuf.f_bfree);
Roland McGrathab147c52003-07-17 09:03:02 +00001484 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1485 (unsigned long)statbuf.f_bavail,
Nate Sammons5c74d201999-04-06 01:37:51 +00001486 (unsigned long)statbuf.f_files,
Roland McGrathab147c52003-07-17 09:03:02 +00001487 (unsigned long)statbuf.f_ffree,
1488 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001489#ifdef LINUX
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001490 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Michal Ludvig53b320f2002-09-23 13:30:09 +00001491#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001492#endif /* !ALPHA */
Roland McGrathab147c52003-07-17 09:03:02 +00001493#ifdef _STATFS_F_FRSIZE
1494 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1495#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001496 tprintf("}");
1497}
1498
1499int
1500sys_statfs(tcp)
1501struct tcb *tcp;
1502{
1503 if (entering(tcp)) {
1504 printpath(tcp, tcp->u_arg[0]);
1505 tprintf(", ");
1506 } else {
1507 printstatfs(tcp, tcp->u_arg[1]);
1508 }
1509 return 0;
1510}
1511
1512int
1513sys_fstatfs(tcp)
1514struct tcb *tcp;
1515{
1516 if (entering(tcp)) {
1517 tprintf("%lu, ", tcp->u_arg[0]);
1518 } else {
1519 printstatfs(tcp, tcp->u_arg[1]);
1520 }
1521 return 0;
1522}
1523
Roland McGrathab147c52003-07-17 09:03:02 +00001524#ifdef LINUX
1525static void
1526printstatfs64(tcp, addr)
1527struct tcb *tcp;
1528long addr;
1529{
1530 struct statfs64 statbuf;
1531
1532 if (syserror(tcp) || !verbose(tcp)) {
1533 tprintf("%#lx", addr);
1534 return;
1535 }
1536 if (umove(tcp, addr, &statbuf) < 0) {
1537 tprintf("{...}");
1538 return;
1539 }
1540#ifdef ALPHA
1541
1542 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1543 sprintfstype(statbuf.f_type),
1544 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1545 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1546 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1547 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1548 statbuf.f_namelen);
1549#else /* !ALPHA */
1550 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1551 sprintfstype(statbuf.f_type),
1552 (unsigned long)statbuf.f_bsize,
1553 (unsigned long)statbuf.f_blocks,
1554 (unsigned long)statbuf.f_bfree);
1555 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1556 (unsigned long)statbuf.f_bavail,
1557 (unsigned long)statbuf.f_files,
1558 (unsigned long)statbuf.f_ffree,
1559 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1560 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1561#endif /* !ALPHA */
1562#ifdef _STATFS_F_FRSIZE
1563 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1564#endif
1565 tprintf("}");
1566}
1567
1568int
1569sys_statfs64(tcp)
1570struct tcb *tcp;
1571{
1572 if (entering(tcp)) {
1573 printpath(tcp, tcp->u_arg[0]);
1574 tprintf(", %lu, ", tcp->u_arg[1]);
1575 } else {
1576 if (tcp->u_arg[1] == sizeof (struct statfs64))
1577 printstatfs64(tcp, tcp->u_arg[2]);
1578 else
1579 tprintf("{???}");
1580 }
1581 return 0;
1582}
1583
1584int
1585sys_fstatfs64(tcp)
1586struct tcb *tcp;
1587{
1588 if (entering(tcp)) {
1589 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1590 } else {
1591 if (tcp->u_arg[1] == sizeof (struct statfs64))
1592 printstatfs64(tcp, tcp->u_arg[2]);
1593 else
1594 tprintf("{???}");
1595 }
1596 return 0;
1597}
1598#endif
1599
Michal Ludvig53b320f2002-09-23 13:30:09 +00001600#if defined(LINUX) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001601
1602int
1603osf_statfs(tcp)
1604struct tcb *tcp;
1605{
1606 if (entering(tcp)) {
1607 printpath(tcp, tcp->u_arg[0]);
1608 tprintf(", ");
1609 } else {
1610 printstatfs(tcp, tcp->u_arg[1]);
1611 tprintf(", %lu", tcp->u_arg[2]);
1612 }
1613 return 0;
1614}
1615
1616int
1617osf_fstatfs(tcp)
1618struct tcb *tcp;
1619{
1620 if (entering(tcp)) {
1621 tprintf("%lu, ", tcp->u_arg[0]);
1622 } else {
1623 printstatfs(tcp, tcp->u_arg[1]);
1624 tprintf(", %lu", tcp->u_arg[2]);
1625 }
1626 return 0;
1627}
Michal Ludvig53b320f2002-09-23 13:30:09 +00001628#endif /* LINUX && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001629
1630#endif /* !SVR4 */
1631
1632#ifdef SUNOS4
1633
1634int
1635sys_ustat(tcp)
1636struct tcb *tcp;
1637{
1638 struct ustat statbuf;
1639
1640 if (entering(tcp)) {
1641 tprintf("makedev(%lu, %lu), ",
1642 (long) major(tcp->u_arg[0]),
1643 (long) minor(tcp->u_arg[0]));
1644 }
1645 else {
1646 if (syserror(tcp) || !verbose(tcp))
1647 tprintf("%#lx", tcp->u_arg[1]);
1648 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1649 tprintf("{...}");
1650 else {
1651 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1652 statbuf.f_tfree, statbuf.f_tinode);
1653 tprintf("f_fname=\"%.*s\", ",
1654 (int) sizeof(statbuf.f_fname),
1655 statbuf.f_fname);
1656 tprintf("f_fpack=\"%.*s\"}",
1657 (int) sizeof(statbuf.f_fpack),
1658 statbuf.f_fpack);
1659 }
1660 }
1661 return 0;
1662}
1663
1664#endif /* SUNOS4 */
1665
Wichert Akkermanc7926982000-04-10 22:22:31 +00001666int
1667sys_pivotroot(tcp)
1668struct tcb *tcp;
1669{
1670 if (entering(tcp)) {
1671 printpath(tcp, tcp->u_arg[0]);
1672 tprintf(", ");
1673 printpath(tcp, tcp->u_arg[1]);
1674 }
1675 return 0;
1676}
1677
1678
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001679/* directory */
1680int
1681sys_chdir(tcp)
1682struct tcb *tcp;
1683{
1684 if (entering(tcp)) {
1685 printpath(tcp, tcp->u_arg[0]);
1686 }
1687 return 0;
1688}
1689
1690int
1691sys_mkdir(tcp)
1692struct tcb *tcp;
1693{
1694 if (entering(tcp)) {
1695 printpath(tcp, tcp->u_arg[0]);
1696 tprintf(", %#lo", tcp->u_arg[1]);
1697 }
1698 return 0;
1699}
1700
1701int
1702sys_rmdir(tcp)
1703struct tcb *tcp;
1704{
1705 if (entering(tcp)) {
1706 printpath(tcp, tcp->u_arg[0]);
1707 }
1708 return 0;
1709}
1710
1711int
1712sys_fchdir(tcp)
1713struct tcb *tcp;
1714{
1715 if (entering(tcp)) {
1716 tprintf("%ld", tcp->u_arg[0]);
1717 }
1718 return 0;
1719}
1720
1721int
1722sys_chroot(tcp)
1723struct tcb *tcp;
1724{
1725 if (entering(tcp)) {
1726 printpath(tcp, tcp->u_arg[0]);
1727 }
1728 return 0;
1729}
1730
1731int
1732sys_fchroot(tcp)
1733struct tcb *tcp;
1734{
1735 if (entering(tcp)) {
1736 tprintf("%ld", tcp->u_arg[0]);
1737 }
1738 return 0;
1739}
1740
1741int
1742sys_link(tcp)
1743struct tcb *tcp;
1744{
1745 if (entering(tcp)) {
1746 printpath(tcp, tcp->u_arg[0]);
1747 tprintf(", ");
1748 printpath(tcp, tcp->u_arg[1]);
1749 }
1750 return 0;
1751}
1752
1753int
1754sys_unlink(tcp)
1755struct tcb *tcp;
1756{
1757 if (entering(tcp)) {
1758 printpath(tcp, tcp->u_arg[0]);
1759 }
1760 return 0;
1761}
1762
1763int
1764sys_symlink(tcp)
1765struct tcb *tcp;
1766{
1767 if (entering(tcp)) {
1768 printpath(tcp, tcp->u_arg[0]);
1769 tprintf(", ");
1770 printpath(tcp, tcp->u_arg[1]);
1771 }
1772 return 0;
1773}
1774
1775int
1776sys_readlink(tcp)
1777struct tcb *tcp;
1778{
1779 if (entering(tcp)) {
1780 printpath(tcp, tcp->u_arg[0]);
1781 tprintf(", ");
1782 } else {
1783 if (syserror(tcp))
1784 tprintf("%#lx", tcp->u_arg[1]);
1785 else
1786 printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
1787 tprintf(", %lu", tcp->u_arg[2]);
1788 }
1789 return 0;
1790}
1791
1792int
1793sys_rename(tcp)
1794struct tcb *tcp;
1795{
1796 if (entering(tcp)) {
1797 printpath(tcp, tcp->u_arg[0]);
1798 tprintf(", ");
1799 printpath(tcp, tcp->u_arg[1]);
1800 }
1801 return 0;
1802}
1803
1804int
1805sys_chown(tcp)
1806struct tcb *tcp;
1807{
1808 if (entering(tcp)) {
1809 printpath(tcp, tcp->u_arg[0]);
Roland McGrath6bc12202003-11-13 22:32:27 +00001810 printuid(", ", tcp->u_arg[1]);
1811 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001812 }
1813 return 0;
1814}
1815
1816int
1817sys_fchown(tcp)
1818struct tcb *tcp;
1819{
1820 if (entering(tcp)) {
Roland McGrath6bc12202003-11-13 22:32:27 +00001821 tprintf("%ld", tcp->u_arg[0]);
1822 printuid(", ", tcp->u_arg[1]);
1823 printuid(", ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001824 }
1825 return 0;
1826}
1827
1828int
1829sys_chmod(tcp)
1830struct tcb *tcp;
1831{
1832 if (entering(tcp)) {
1833 printpath(tcp, tcp->u_arg[0]);
1834 tprintf(", %#lo", tcp->u_arg[1]);
1835 }
1836 return 0;
1837}
1838
1839int
1840sys_fchmod(tcp)
1841struct tcb *tcp;
1842{
1843 if (entering(tcp)) {
1844 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
1845 }
1846 return 0;
1847}
1848
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001849#ifdef ALPHA
1850int
1851sys_osf_utimes(tcp)
1852struct tcb *tcp;
1853{
1854 if (entering(tcp)) {
1855 printpath(tcp, tcp->u_arg[0]);
1856 tprintf(", ");
1857 printtv32(tcp, tcp->u_arg[1]);
1858 }
1859 return 0;
1860}
1861#endif
1862
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001863int
1864sys_utimes(tcp)
1865struct tcb *tcp;
1866{
1867 if (entering(tcp)) {
1868 printpath(tcp, tcp->u_arg[0]);
1869 tprintf(", ");
1870 printtv(tcp, tcp->u_arg[1]);
1871 }
1872 return 0;
1873}
1874
1875int
1876sys_utime(tcp)
1877struct tcb *tcp;
1878{
1879 long ut[2];
1880
1881 if (entering(tcp)) {
1882 printpath(tcp, tcp->u_arg[0]);
1883 tprintf(", ");
1884 if (!tcp->u_arg[1])
1885 tprintf("NULL");
1886 else if (!verbose(tcp))
1887 tprintf("%#lx", tcp->u_arg[1]);
1888 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
1889 (char *) ut) < 0)
1890 tprintf("[?, ?]");
1891 else {
1892 tprintf("[%s,", sprinttime(ut[0]));
1893 tprintf(" %s]", sprinttime(ut[1]));
1894 }
1895 }
1896 return 0;
1897}
1898
1899int
1900sys_mknod(tcp)
1901struct tcb *tcp;
1902{
1903 int mode = tcp->u_arg[1];
1904
1905 if (entering(tcp)) {
1906 printpath(tcp, tcp->u_arg[0]);
1907 tprintf(", %s", sprintmode(mode));
1908 switch (mode & S_IFMT) {
1909 case S_IFCHR: case S_IFBLK:
1910#ifdef LINUXSPARC
1911 if (current_personality == 1)
1912 tprintf(", makedev(%lu, %lu)",
1913 (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
1914 (unsigned long) (tcp->u_arg[2] & 0x3ffff));
1915 else
Roland McGrath186c5ac2002-12-15 23:58:23 +00001916#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001917 tprintf(", makedev(%lu, %lu)",
1918 (unsigned long) major(tcp->u_arg[2]),
1919 (unsigned long) minor(tcp->u_arg[2]));
1920 break;
1921 default:
1922 break;
1923 }
1924 }
1925 return 0;
1926}
1927
1928int
1929sys_mkfifo(tcp)
1930struct tcb *tcp;
1931{
1932 if (entering(tcp)) {
1933 printpath(tcp, tcp->u_arg[0]);
1934 tprintf(", %#lo", tcp->u_arg[1]);
1935 }
1936 return 0;
1937}
1938
1939int
1940sys_fsync(tcp)
1941struct tcb *tcp;
1942{
1943 if (entering(tcp)) {
1944 tprintf("%ld", tcp->u_arg[0]);
1945 }
1946 return 0;
1947}
1948
Michal Ludvig53b320f2002-09-23 13:30:09 +00001949#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001950
1951static void
1952printdir(tcp, addr)
1953struct tcb *tcp;
1954long addr;
1955{
1956 struct dirent d;
1957
1958 if (!verbose(tcp)) {
1959 tprintf("%#lx", addr);
1960 return;
1961 }
1962 if (umove(tcp, addr, &d) < 0) {
1963 tprintf("{...}");
1964 return;
1965 }
1966 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001967 tprintf("d_name=");
1968 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
1969 tprintf("}");
1970}
1971
1972int
1973sys_readdir(tcp)
1974struct tcb *tcp;
1975{
1976 if (entering(tcp)) {
1977 tprintf("%lu, ", tcp->u_arg[0]);
1978 } else {
1979 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
1980 tprintf("%#lx", tcp->u_arg[1]);
1981 else
1982 printdir(tcp, tcp->u_arg[1]);
1983 /* Not much point in printing this out, it is always 1. */
1984 if (tcp->u_arg[2] != 1)
1985 tprintf(", %lu", tcp->u_arg[2]);
1986 }
1987 return 0;
1988}
1989
Michal Ludvig53b320f2002-09-23 13:30:09 +00001990#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001991
Roland McGrath40542842004-01-13 09:47:49 +00001992#if defined FREEBSD || defined LINUX
Roland McGrathd9f816f2004-09-04 03:39:20 +00001993const struct xlat direnttypes[] = {
Roland McGrath40542842004-01-13 09:47:49 +00001994 { DT_UNKNOWN, "DT_UNKNOWN" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001995 { DT_FIFO, "DT_FIFO" },
1996 { DT_CHR, "DT_CHR" },
1997 { DT_DIR, "DT_DIR" },
1998 { DT_BLK, "DT_BLK" },
1999 { DT_REG, "DT_REG" },
2000 { DT_LNK, "DT_LNK" },
2001 { DT_SOCK, "DT_SOCK" },
2002 { DT_WHT, "DT_WHT" },
2003 { 0, NULL },
2004};
2005
2006#endif
2007
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002008int
2009sys_getdents(tcp)
2010struct tcb *tcp;
2011{
2012 int i, len, dents = 0;
2013 char *buf;
2014
2015 if (entering(tcp)) {
2016 tprintf("%lu, ", tcp->u_arg[0]);
2017 return 0;
2018 }
2019 if (syserror(tcp) || !verbose(tcp)) {
2020 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2021 return 0;
2022 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002023 len = tcp->u_rval;
2024 if ((buf = malloc(len)) == NULL) {
2025 tprintf("out of memory\n");
2026 return 0;
2027 }
2028 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2029 tprintf("{...}, %lu", tcp->u_arg[2]);
2030 free(buf);
2031 return 0;
2032 }
2033 if (!abbrev(tcp))
2034 tprintf("{");
2035 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00002036 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002037#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002038 if (!abbrev(tcp)) {
2039 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2040 i ? " " : "", d->d_ino, d->d_off);
2041 tprintf("d_reclen=%u, d_name=\"%s\"}",
2042 d->d_reclen, d->d_name);
2043 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002044#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002045#ifdef SVR4
2046 if (!abbrev(tcp)) {
2047 tprintf("%s{d_ino=%lu, d_off=%lu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002048 i ? " " : "",
2049 (unsigned long) d->d_ino,
2050 (unsigned long) d->d_off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002051 tprintf("d_reclen=%u, d_name=\"%s\"}",
2052 d->d_reclen, d->d_name);
2053 }
2054#endif /* SVR4 */
2055#ifdef SUNOS4
2056 if (!abbrev(tcp)) {
2057 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2058 i ? " " : "", d->d_off, d->d_fileno,
2059 d->d_reclen);
2060 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2061 d->d_namlen, d->d_namlen, d->d_name);
2062 }
2063#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002064#ifdef FREEBSD
2065 if (!abbrev(tcp)) {
2066 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2067 i ? " " : "", d->d_fileno, d->d_reclen);
2068 printxval(direnttypes, d->d_type, "DT_???");
2069 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2070 d->d_namlen, d->d_namlen, d->d_name);
2071 }
Roland McGrath186c5ac2002-12-15 23:58:23 +00002072#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00002073 if (!d->d_reclen) {
2074 tprintf("/* d_reclen == 0, problem here */");
2075 break;
2076 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002077 i += d->d_reclen;
2078 dents++;
2079 }
2080 if (!abbrev(tcp))
2081 tprintf("}");
2082 else
2083 tprintf("/* %u entries */", dents);
2084 tprintf(", %lu", tcp->u_arg[2]);
2085 free(buf);
2086 return 0;
2087}
2088
John Hughesbdf48f52001-03-06 15:08:09 +00002089
2090#if _LFS64_LARGEFILE
2091int
2092sys_getdents64(tcp)
2093struct tcb *tcp;
2094{
2095 int i, len, dents = 0;
2096 char *buf;
2097
2098 if (entering(tcp)) {
2099 tprintf("%lu, ", tcp->u_arg[0]);
2100 return 0;
2101 }
2102 if (syserror(tcp) || !verbose(tcp)) {
2103 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2104 return 0;
2105 }
2106 len = tcp->u_rval;
2107 if ((buf = malloc(len)) == NULL) {
2108 tprintf("out of memory\n");
2109 return 0;
2110 }
2111 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2112 tprintf("{...}, %lu", tcp->u_arg[2]);
2113 free(buf);
2114 return 0;
2115 }
2116 if (!abbrev(tcp))
2117 tprintf("{");
2118 for (i = 0; i < len;) {
2119 struct dirent64 *d = (struct dirent64 *) &buf[i];
Michal Ludvig53b320f2002-09-23 13:30:09 +00002120#if defined(LINUX) || defined(SVR4)
John Hughesbdf48f52001-03-06 15:08:09 +00002121 if (!abbrev(tcp)) {
Roland McGrath92053242004-01-13 10:16:47 +00002122 tprintf("%s{d_ino=%llu, d_off=%llu, ",
Roland McGrath186c5ac2002-12-15 23:58:23 +00002123 i ? " " : "",
Roland McGrath92053242004-01-13 10:16:47 +00002124 d->d_ino,
2125 d->d_off);
Roland McGrath40542842004-01-13 09:47:49 +00002126#ifdef LINUX
2127 tprintf("d_type=");
2128 printxval(direnttypes, d->d_type, "DT_???");
2129 tprintf(", ");
2130#endif
John Hughesbdf48f52001-03-06 15:08:09 +00002131 tprintf("d_reclen=%u, d_name=\"%s\"}",
2132 d->d_reclen, d->d_name);
2133 }
Michal Ludvig53b320f2002-09-23 13:30:09 +00002134#endif /* LINUX || SVR4 */
John Hughesbdf48f52001-03-06 15:08:09 +00002135#ifdef SUNOS4
2136 if (!abbrev(tcp)) {
2137 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2138 i ? " " : "", d->d_off, d->d_fileno,
2139 d->d_reclen);
2140 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2141 d->d_namlen, d->d_namlen, d->d_name);
2142 }
2143#endif /* SUNOS4 */
2144 i += d->d_reclen;
2145 dents++;
2146 }
2147 if (!abbrev(tcp))
2148 tprintf("}");
2149 else
2150 tprintf("/* %u entries */", dents);
2151 tprintf(", %lu", tcp->u_arg[2]);
2152 free(buf);
2153 return 0;
2154}
2155#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002156
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002157#ifdef FREEBSD
2158int
2159sys_getdirentries(tcp)
2160struct tcb * tcp;
2161{
2162 int i, len, dents = 0;
2163 long basep;
2164 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002165
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002166 if (entering(tcp)) {
2167 tprintf("%lu, ", tcp->u_arg[0]);
2168 return 0;
2169 }
2170 if (syserror(tcp) || !verbose(tcp)) {
2171 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2172 return 0;
2173 }
2174 len = tcp->u_rval;
2175 if ((buf = malloc(len)) == NULL) {
2176 tprintf("out of memory\n");
2177 return 0;
2178 }
2179 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2180 tprintf("{...}, %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3]);
2181 free(buf);
2182 return 0;
2183 }
2184 if (!abbrev(tcp))
2185 tprintf("{");
2186 for (i = 0; i < len;) {
2187 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2188 if (!abbrev(tcp)) {
2189 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2190 i ? " " : "", d->d_fileno, d->d_reclen);
2191 printxval(direnttypes, d->d_type, "DT_???");
2192 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2193 d->d_namlen, d->d_namlen, d->d_name);
2194 }
2195 i += d->d_reclen;
2196 dents++;
2197 }
2198 if (!abbrev(tcp))
2199 tprintf("}");
2200 else
2201 tprintf("/* %u entries */", dents);
2202 free(buf);
2203 tprintf(", %lu", tcp->u_arg[2]);
2204 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2205 tprintf(", %#lx", tcp->u_arg[3]);
2206 else
2207 tprintf(", [%lu]", basep);
2208 return 0;
2209}
2210#endif
2211
Michal Ludvig53b320f2002-09-23 13:30:09 +00002212#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002213int
2214sys_getcwd(tcp)
2215struct tcb *tcp;
2216{
2217 if (exiting(tcp)) {
2218 if (syserror(tcp))
2219 tprintf("%#lx", tcp->u_arg[0]);
2220 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002221 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002222 tprintf(", %lu", tcp->u_arg[1]);
2223 }
2224 return 0;
2225}
Michal Ludvig53b320f2002-09-23 13:30:09 +00002226#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002227
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002228#ifdef FREEBSD
2229int
2230sys___getcwd(tcp)
2231struct tcb *tcp;
2232{
2233 if (exiting(tcp)) {
2234 if (syserror(tcp))
2235 tprintf("%#lx", tcp->u_arg[0]);
2236 else
2237 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2238 tprintf(", %lu", tcp->u_arg[1]);
2239 }
2240 return 0;
2241}
2242#endif
2243
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002244#ifdef HAVE_SYS_ASYNCH_H
2245
2246int
2247sys_aioread(tcp)
2248struct tcb *tcp;
2249{
2250 struct aio_result_t res;
2251
2252 if (entering(tcp)) {
2253 tprintf("%lu, ", tcp->u_arg[0]);
2254 } else {
2255 if (syserror(tcp))
2256 tprintf("%#lx", tcp->u_arg[1]);
2257 else
2258 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2259 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2260 printxval(whence, tcp->u_arg[4], "L_???");
2261 if (syserror(tcp) || tcp->u_arg[5] == 0
2262 || umove(tcp, tcp->u_arg[5], &res) < 0)
2263 tprintf(", %#lx", tcp->u_arg[5]);
2264 else
2265 tprintf(", {aio_return %d aio_errno %d}",
2266 res.aio_return, res.aio_errno);
2267 }
2268 return 0;
2269}
2270
2271int
2272sys_aiowrite(tcp)
2273struct tcb *tcp;
2274{
2275 struct aio_result_t res;
2276
2277 if (entering(tcp)) {
2278 tprintf("%lu, ", tcp->u_arg[0]);
2279 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2280 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2281 printxval(whence, tcp->u_arg[4], "L_???");
2282 }
2283 else {
2284 if (tcp->u_arg[5] == 0)
2285 tprintf(", NULL");
2286 else if (syserror(tcp)
2287 || umove(tcp, tcp->u_arg[5], &res) < 0)
2288 tprintf(", %#lx", tcp->u_arg[5]);
2289 else
2290 tprintf(", {aio_return %d aio_errno %d}",
2291 res.aio_return, res.aio_errno);
2292 }
2293 return 0;
2294}
2295
2296int
2297sys_aiowait(tcp)
2298struct tcb *tcp;
2299{
2300 if (entering(tcp))
2301 printtv(tcp, tcp->u_arg[0]);
2302 return 0;
2303}
2304
2305int
2306sys_aiocancel(tcp)
2307struct tcb *tcp;
2308{
2309 struct aio_result_t res;
2310
2311 if (exiting(tcp)) {
2312 if (tcp->u_arg[0] == 0)
2313 tprintf("NULL");
2314 else if (syserror(tcp)
2315 || umove(tcp, tcp->u_arg[0], &res) < 0)
2316 tprintf("%#lx", tcp->u_arg[0]);
2317 else
2318 tprintf("{aio_return %d aio_errno %d}",
2319 res.aio_return, res.aio_errno);
2320 }
2321 return 0;
2322}
2323
2324#endif /* HAVE_SYS_ASYNCH_H */
Roland McGrath186c5ac2002-12-15 23:58:23 +00002325
Roland McGrathd9f816f2004-09-04 03:39:20 +00002326const struct xlat xattrflags[] = {
Roland McGrath561c7992003-04-02 01:10:44 +00002327#ifdef XATTR_CREATE
Roland McGrath186c5ac2002-12-15 23:58:23 +00002328 { XATTR_CREATE, "XATTR_CREATE" },
2329 { XATTR_REPLACE, "XATTR_REPLACE" },
Roland McGrath561c7992003-04-02 01:10:44 +00002330#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +00002331 { 0, NULL }
2332};
2333
Roland McGrath3292e222004-08-31 06:30:48 +00002334static void
2335print_xattr_val(tcp, failed, arg, insize, size)
2336struct tcb *tcp;
2337int failed;
2338unsigned long arg;
2339size_t size;
2340{
2341 unsigned char buf[4 * size + 1];
2342 if (!failed && umoven(tcp, arg, size, &buf[3 * size]) >= 0) {
2343 unsigned char *out = buf;
2344 unsigned char *in = &buf[3 * size];
2345 size_t i;
2346 for (i = 0; i < size; ++i)
2347 if (isprint(in[i]))
2348 *out++ = in[i];
2349 else {
2350#define tohex(n) "0123456789abcdef"[n]
2351 *out++ = '\\';
2352 *out++ = 'x';
2353 *out++ = tohex(in[i] / 16);
2354 *out++ = tohex(in[i] % 16);
2355 }
2356 /* Don't print terminating NUL if there is one. */
2357 if (in[i - 1] == '\0')
2358 out -= 4;
2359 *out = '\0';
2360 tprintf(", \"%s\", %zd", buf, insize);
2361 } else
2362 tprintf(", 0x%lx, %zd", arg, insize);
2363}
2364
Roland McGrath186c5ac2002-12-15 23:58:23 +00002365int
2366sys_setxattr(tcp)
2367struct tcb *tcp;
2368{
2369 if (entering(tcp)) {
2370 printpath(tcp, tcp->u_arg[0]);
2371 tprintf(", ");
2372 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002373 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2374 tprintf(", ");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002375 printflags(xattrflags, tcp->u_arg[4]);
2376 }
2377 return 0;
2378}
2379
2380int
2381sys_fsetxattr(tcp)
2382struct tcb *tcp;
2383{
2384 if (entering(tcp)) {
2385 tprintf("%ld, ", tcp->u_arg[0]);
2386 printstr(tcp, tcp->u_arg[1], -1);
Roland McGrath3292e222004-08-31 06:30:48 +00002387 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2388 tprintf(", ");
Roland McGrath186c5ac2002-12-15 23:58:23 +00002389 printflags(xattrflags, tcp->u_arg[4]);
2390 }
2391 return 0;
2392}
2393
2394int
2395sys_getxattr(tcp)
2396struct tcb *tcp;
2397{
2398 if (entering(tcp)) {
2399 printpath(tcp, tcp->u_arg[0]);
2400 tprintf(", ");
2401 printstr(tcp, tcp->u_arg[1], -1);
2402 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002403 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2404 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002405 }
2406 return 0;
2407}
2408
2409int
2410sys_fgetxattr(tcp)
2411struct tcb *tcp;
2412{
2413 if (entering(tcp)) {
2414 tprintf("%ld, ", tcp->u_arg[0]);
2415 printstr(tcp, tcp->u_arg[1], -1);
2416 } else {
Roland McGrath3292e222004-08-31 06:30:48 +00002417 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2418 tcp->u_rval);
Roland McGrath186c5ac2002-12-15 23:58:23 +00002419 }
2420 return 0;
2421}
2422
2423int
2424sys_listxattr(tcp)
2425struct tcb *tcp;
2426{
2427 if (entering(tcp)) {
2428 printpath(tcp, tcp->u_arg[0]);
2429 } else {
2430 /* XXX Print value in format */
2431 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2432 }
2433 return 0;
2434}
2435
2436int
2437sys_flistxattr(tcp)
2438struct tcb *tcp;
2439{
2440 if (entering(tcp)) {
2441 tprintf("%ld", tcp->u_arg[0]);
2442 } else {
2443 /* XXX Print value in format */
2444 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2445 }
2446 return 0;
2447}
2448
2449int
2450sys_removexattr(tcp)
2451struct tcb *tcp;
2452{
2453 if (entering(tcp)) {
2454 printpath(tcp, tcp->u_arg[0]);
2455 tprintf(", ");
2456 printstr(tcp, tcp->u_arg[1], -1);
2457 }
2458 return 0;
2459}
2460
2461int
2462sys_fremovexattr(tcp)
2463struct tcb *tcp;
2464{
2465 if (entering(tcp)) {
2466 tprintf("%ld, ", tcp->u_arg[0]);
2467 printstr(tcp, tcp->u_arg[1], -1);
2468 }
2469 return 0;
2470}
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002471
2472
2473static const struct xlat advise[] = {
2474 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2475 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2476 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2477 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2478 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2479 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2480 { 0, NULL }
2481};
2482
2483
2484#if defined LINUX && (defined I386 || defined X86_64)
2485int
2486sys_fadvise64(tcp)
2487struct tcb *tcp;
2488{
2489 if (entering(tcp)) {
2490 tprintf("%ld, %lld, %ld, ",
2491 tcp->u_arg[0],
2492# if defined IA64 || defined X86_64 || defined ALPHA
2493 (long long int) tcp->u_arg[1], tcp->u_arg[2]);
2494 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2495#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002496 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
2497 printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002498#endif
2499 }
2500 return 0;
2501}
2502#endif
2503
2504
2505int
2506sys_fadvise64_64(tcp)
2507struct tcb *tcp;
2508{
2509 if (entering(tcp)) {
2510 tprintf("%ld, %lld, %lld, ",
2511 tcp->u_arg[0],
2512# if defined IA64 || defined X86_64 || defined ALPHA
2513 (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
2514 printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2515#else
Roland McGrath2fe2a3e2004-10-07 19:09:16 +00002516 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
2517 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
Roland McGrathdf13e8f2004-10-07 18:51:19 +00002518 printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
2519#endif
2520 }
2521 return 0;
2522}