Home | History | Annotate | Download | only in strace
      1 /*
      2 #ifdef LINUX
      3  * Copyright (c) 1991, 1992 Paul Kranenburg <pk (at) cs.few.eur.nl>
      4  * Copyright (c) 1993 Branko Lankester <branko (at) hacktic.nl>
      5  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs (at) world.std.com>
      6  * Copyright (c) 1996-1999 Wichert Akkerman <wichert (at) cistron.nl>
      7  * 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: file.c,v 1.75 2005/06/08 20:45:28 roland Exp $
     32  */
     33 
     34 #include "defs.h"
     35 
     36 #include <dirent.h>
     37 #if defined(LINUX)
     38 #define dirent kernel_dirent
     39 #ifndef HAVE_ANDROID_OS
     40 #define dirent64 kernel_dirent64
     41 #endif
     42 #ifdef HAVE_ANDROID_OS
     43 #include <linux/fadvise.h>
     44 
     45 // ANDROID: From kernel_headers/asm/statfs.h
     46 
     47 /*
     48  * With EABI there is 4 bytes of padding added to this structure.
     49  * Let's pack it so the padding goes away to simplify dual ABI support.
     50  * Note that user space does NOT have to pack this structure.
     51  */
     52 struct statfs64 {
     53         __u32 f_type;
     54         __u32 f_bsize;
     55         __u64 f_blocks;
     56         __u64 f_bfree;
     57         __u64 f_bavail;
     58         __u64 f_files;
     59         __u64 f_ffree;
     60         __kernel_fsid_t f_fsid;
     61         __u32 f_namelen;
     62         __u32 f_frsize;
     63         __u32 f_spare[5];
     64 } __attribute__ ((packed,aligned(4)));
     65 
     66 
     67 
     68 
     69 #endif /* HAVE_ANDROID_OS */
     70 #include <linux/types.h>
     71 #include <linux/dirent.h>
     72 #undef dirent
     73 #undef dirent64
     74 #else
     75 #define kernel_dirent dirent
     76 #endif
     77 
     78 #ifdef LINUX
     79 #  ifdef LINUXSPARC
     80 struct stat {
     81 	unsigned short	st_dev;
     82 	unsigned int	st_ino;
     83 	unsigned short	st_mode;
     84 	short		st_nlink;
     85 	unsigned short	st_uid;
     86 	unsigned short	st_gid;
     87 	unsigned short	st_rdev;
     88 	unsigned int	st_size;
     89 	int		st_atime;
     90 	unsigned int	__unused1;
     91 	int		st_mtime;
     92 	unsigned int	__unused2;
     93 	int		st_ctime;
     94 	unsigned int	__unused3;
     95 	int		st_blksize;
     96 	int		st_blocks;
     97 	unsigned int	__unused4[2];
     98 };
     99 #if defined(SPARC64)
    100 struct stat_sparc64 {
    101 	unsigned int	st_dev;
    102 	unsigned long	st_ino;
    103 	unsigned int	st_mode;
    104 	unsigned int	st_nlink;
    105 	unsigned int	st_uid;
    106 	unsigned int	st_gid;
    107 	unsigned int	st_rdev;
    108 	long		st_size;
    109 	long		st_atime;
    110 	long		st_mtime;
    111 	long		st_ctime;
    112 	long		st_blksize;
    113 	long		st_blocks;
    114 	unsigned long	__unused4[2];
    115 };
    116 #endif /* SPARC64 */
    117 #    define stat kernel_stat
    118 #    include <asm/stat.h>
    119 #    undef stat
    120 #  else
    121 #    undef dev_t
    122 #    undef ino_t
    123 #    undef mode_t
    124 #    undef nlink_t
    125 #    undef uid_t
    126 #    undef gid_t
    127 #    undef off_t
    128 #    undef loff_t
    129 
    130 #    define dev_t __kernel_dev_t
    131 #    define ino_t __kernel_ino_t
    132 #    define mode_t __kernel_mode_t
    133 #    define nlink_t __kernel_nlink_t
    134 #    define uid_t __kernel_uid_t
    135 #    define gid_t __kernel_gid_t
    136 #    define off_t __kernel_off_t
    137 #    define loff_t __kernel_loff_t
    138 
    139 #    include <asm/stat.h>
    140 
    141 #    undef dev_t
    142 #    undef ino_t
    143 #    undef mode_t
    144 #    undef nlink_t
    145 #    undef uid_t
    146 #    undef gid_t
    147 #    undef off_t
    148 #    undef loff_t
    149 
    150 #    define dev_t dev_t
    151 #    define ino_t ino_t
    152 #    define mode_t mode_t
    153 #    define nlink_t nlink_t
    154 #    define uid_t uid_t
    155 #    define gid_t gid_t
    156 #    define off_t off_t
    157 #    define loff_t loff_t
    158 #  endif
    159 #  ifdef HPPA	/* asm-parisc/stat.h defines stat64 */
    160 #    undef stat64
    161 #  endif
    162 #  define stat libc_stat
    163 #  define stat64 libc_stat64
    164 #  include <sys/stat.h>
    165 #  undef stat
    166 #  undef stat64
    167    /* These might be macros. */
    168 #  undef st_atime
    169 #  undef st_mtime
    170 #  undef st_ctime
    171 #  ifdef HPPA
    172 #    define stat64 hpux_stat64
    173 #  endif
    174 #else
    175 #  include <sys/stat.h>
    176 #endif
    177 
    178 #include <fcntl.h>
    179 
    180 #ifdef SVR4
    181 #  include <sys/cred.h>
    182 #endif /* SVR4 */
    183 
    184 #ifdef HAVE_SYS_VFS_H
    185 #include <sys/vfs.h>
    186 #endif
    187 
    188 #ifdef HAVE_LINUX_XATTR_H
    189 #include <linux/xattr.h>
    190 #elif defined linux
    191 #define XATTR_CREATE 1
    192 #define XATTR_REPLACE 2
    193 #endif
    194 
    195 #ifdef FREEBSD
    196 #include <sys/param.h>
    197 #include <sys/mount.h>
    198 #include <sys/stat.h>
    199 #endif
    200 
    201 #if HAVE_LONG_LONG_OFF_T
    202 /*
    203  * Ugly hacks for systems that have typedef long long off_t
    204  */
    205 
    206 #define stat64 stat
    207 #define HAVE_STAT64 1	/* Ugly hack */
    208 
    209 #define	sys_stat64	sys_stat
    210 #define sys_fstat64	sys_fstat
    211 #define sys_lstat64	sys_lstat
    212 #define sys_lseek64	sys_lseek
    213 #define sys_truncate64	sys_truncate
    214 #define sys_ftruncate64	sys_ftruncate
    215 #endif
    216 
    217 #ifdef MAJOR_IN_SYSMACROS
    218 #include <sys/sysmacros.h>
    219 #endif
    220 
    221 #ifdef MAJOR_IN_MKDEV
    222 #include <sys/mkdev.h>
    223 #endif
    224 
    225 #ifdef HAVE_SYS_ASYNCH_H
    226 #include <sys/asynch.h>
    227 #endif
    228 
    229 #ifdef SUNOS4
    230 #include <ustat.h>
    231 #endif
    232 
    233 /*
    234  * This is a really dirty trick but it should always work.  Traditional
    235  * Unix says r/w/rw are 0/1/2, so we make them true flags 1/2/3 by
    236  * adding 1.  Just remember to add 1 to any arg decoded with openmodes.
    237  */
    238 const struct xlat openmodes[] = {
    239 	{ O_RDWR+1,	"O_RDWR"	},
    240 	{ O_RDONLY+1,	"O_RDONLY"	},
    241 	{ O_WRONLY+1,	"O_WRONLY"	},
    242 	{ O_NONBLOCK,	"O_NONBLOCK"	},
    243 	{ O_APPEND,	"O_APPEND"	},
    244 	{ O_CREAT,	"O_CREAT"	},
    245 	{ O_TRUNC,	"O_TRUNC"	},
    246 	{ O_EXCL,	"O_EXCL"	},
    247 	{ O_NOCTTY,	"O_NOCTTY"	},
    248 #ifdef O_SYNC
    249 	{ O_SYNC,	"O_SYNC"	},
    250 #endif
    251 #ifdef O_ASYNC
    252 	{ O_ASYNC,	"O_ASYNC"	},
    253 #endif
    254 #ifdef O_DSYNC
    255 	{ O_DSYNC,	"O_DSYNC"	},
    256 #endif
    257 #ifdef O_RSYNC
    258 	{ O_RSYNC,	"O_RSYNC"	},
    259 #endif
    260 #ifdef O_NDELAY
    261 	{ O_NDELAY,	"O_NDELAY"	},
    262 #endif
    263 #ifdef O_PRIV
    264 	{ O_PRIV,	"O_PRIV"	},
    265 #endif
    266 #ifdef O_DIRECT
    267 	{ O_DIRECT,	"O_DIRECT"	},
    268 #endif
    269 #ifdef O_LARGEFILE
    270 # if O_LARGEFILE == 0		/* biarch platforms in 64-bit mode */
    271 #  undef O_LARGEFILE
    272 #  ifdef SPARC64
    273 #   define O_LARGEFILE	0x40000
    274 #  elif defined X86_64 || defined S390X
    275 #   define O_LARGEFILE	0100000
    276 #  endif
    277 # endif
    278 # ifdef O_LARGEFILE
    279 	{ O_LARGEFILE,	"O_LARGEFILE"   },
    280 # endif
    281 #endif
    282 #ifdef O_DIRECTORY
    283 	{ O_DIRECTORY,	"O_DIRECTORY"   },
    284 #endif
    285 #ifdef O_NOFOLLOW
    286 	{ O_NOFOLLOW, 	"O_NOFOLLOW"	},
    287 #endif
    288 #ifdef O_NOATIME
    289 	{ O_NOATIME, 	"O_NOATIME"	},
    290 #endif
    291 
    292 #ifdef FNDELAY
    293 	{ FNDELAY,	"FNDELAY"	},
    294 #endif
    295 #ifdef FAPPEND
    296 	{ FAPPEND,	"FAPPEND"	},
    297 #endif
    298 #ifdef FMARK
    299 	{ FMARK,	"FMARK"		},
    300 #endif
    301 #ifdef FDEFER
    302 	{ FDEFER,	"FDEFER"	},
    303 #endif
    304 #ifdef FASYNC
    305 	{ FASYNC,	"FASYNC"	},
    306 #endif
    307 #ifdef FSHLOCK
    308 	{ FSHLOCK,	"FSHLOCK"	},
    309 #endif
    310 #ifdef FEXLOCK
    311 	{ FEXLOCK,	"FEXLOCK"	},
    312 #endif
    313 #ifdef FCREAT
    314 	{ FCREAT,	"FCREAT"	},
    315 #endif
    316 #ifdef FTRUNC
    317 	{ FTRUNC,	"FTRUNC"	},
    318 #endif
    319 #ifdef FEXCL
    320 	{ FEXCL,	"FEXCL"		},
    321 #endif
    322 #ifdef FNBIO
    323 	{ FNBIO,	"FNBIO"		},
    324 #endif
    325 #ifdef FSYNC
    326 	{ FSYNC,	"FSYNC"		},
    327 #endif
    328 #ifdef FNOCTTY
    329 	{ FNOCTTY,	"FNOCTTY"	},
    330 #endif
    331 #ifdef O_SHLOCK
    332 	{ O_SHLOCK,	"O_SHLOCK"	},
    333 #endif
    334 #ifdef O_EXLOCK
    335 	{ O_EXLOCK,	"O_EXLOCK"	},
    336 #endif
    337 	{ 0,		NULL		},
    338 };
    339 
    340 int
    341 sys_open(tcp)
    342 struct tcb *tcp;
    343 {
    344 	if (entering(tcp)) {
    345 		printpath(tcp, tcp->u_arg[0]);
    346 		tprintf(", ");
    347 		/* flags */
    348 		printflags(openmodes, tcp->u_arg[1] + 1, "O_???");
    349 		if (tcp->u_arg[1] & O_CREAT) {
    350 			/* mode */
    351 			tprintf(", %#lo", tcp->u_arg[2]);
    352 		}
    353 	}
    354 	return 0;
    355 }
    356 
    357 #ifdef LINUXSPARC
    358 static const struct xlat openmodessol[] = {
    359 	{ 0,		"O_RDWR"	},
    360 	{ 1,		"O_RDONLY"	},
    361 	{ 2,		"O_WRONLY"	},
    362 	{ 0x80,		"O_NONBLOCK"	},
    363 	{ 8,		"O_APPEND"	},
    364 	{ 0x100,	"O_CREAT"	},
    365 	{ 0x200,	"O_TRUNC"	},
    366 	{ 0x400,	"O_EXCL"	},
    367 	{ 0x800,	"O_NOCTTY"	},
    368 	{ 0x10,		"O_SYNC"	},
    369 	{ 0x40,		"O_DSYNC"	},
    370 	{ 0x8000,	"O_RSYNC"	},
    371 	{ 4,		"O_NDELAY"	},
    372 	{ 0x1000,	"O_PRIV"	},
    373 	{ 0,		NULL		},
    374 };
    375 
    376 int
    377 solaris_open(tcp)
    378 struct tcb *tcp;
    379 {
    380 	if (entering(tcp)) {
    381 		printpath(tcp, tcp->u_arg[0]);
    382 		tprintf(", ");
    383 		/* flags */
    384 		printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
    385 		if (tcp->u_arg[1] & 0x100) {
    386 			/* mode */
    387 			tprintf(", %#lo", tcp->u_arg[2]);
    388 		}
    389 	}
    390 	return 0;
    391 }
    392 
    393 #endif
    394 
    395 int
    396 sys_creat(tcp)
    397 struct tcb *tcp;
    398 {
    399 	if (entering(tcp)) {
    400 		printpath(tcp, tcp->u_arg[0]);
    401 		tprintf(", %#lo", tcp->u_arg[1]);
    402 	}
    403 	return 0;
    404 }
    405 
    406 static const struct xlat access_flags[] = {
    407 	{ F_OK,		"F_OK",		},
    408 	{ R_OK,		"R_OK"		},
    409 	{ W_OK,		"W_OK"		},
    410 	{ X_OK,		"X_OK"		},
    411 #ifdef EFF_ONLY_OK
    412 	{ EFF_ONLY_OK,	"EFF_ONLY_OK"	},
    413 #endif
    414 #ifdef EX_OK
    415 	{ EX_OK,	"EX_OK"		},
    416 #endif
    417 	{ 0,		NULL		},
    418 };
    419 
    420 int
    421 sys_access(tcp)
    422 struct tcb *tcp;
    423 {
    424 	if (entering(tcp)) {
    425 		printpath(tcp, tcp->u_arg[0]);
    426 		tprintf(", ");
    427 		printflags(access_flags, tcp->u_arg[1], "?_OK");
    428 	}
    429 	return 0;
    430 }
    431 
    432 int
    433 sys_umask(tcp)
    434 struct tcb *tcp;
    435 {
    436 	if (entering(tcp)) {
    437 		tprintf("%#lo", tcp->u_arg[0]);
    438 	}
    439 	return RVAL_OCTAL;
    440 }
    441 
    442 static const struct xlat whence[] = {
    443 	{ SEEK_SET,	"SEEK_SET"	},
    444 	{ SEEK_CUR,	"SEEK_CUR"	},
    445 	{ SEEK_END,	"SEEK_END"	},
    446 	{ 0,		NULL		},
    447 };
    448 
    449 #ifndef HAVE_LONG_LONG_OFF_T
    450 int
    451 sys_lseek(tcp)
    452 struct tcb *tcp;
    453 {
    454 	off_t offset;
    455 	int _whence;
    456 
    457 	if (entering(tcp)) {
    458 		tprintf("%ld, ", tcp->u_arg[0]);
    459 		offset = tcp->u_arg[1];
    460 		_whence = tcp->u_arg[2];
    461 		if (_whence == SEEK_SET)
    462 			tprintf("%lu, ", offset);
    463 		else
    464 			tprintf("%ld, ", offset);
    465 		printxval(whence, _whence, "SEEK_???");
    466 	}
    467 	return RVAL_UDECIMAL;
    468 }
    469 #endif
    470 
    471 #ifdef LINUX
    472 int
    473 sys_llseek (tcp)
    474 struct tcb *tcp;
    475 {
    476     if (entering(tcp)) {
    477 	/*
    478 	 * This one call takes explicitly two 32-bit arguments hi, lo,
    479 	 * rather than one 64-bit argument for which LONG_LONG works
    480 	 * appropriate for the native byte order.
    481 	 */
    482 	if (tcp->u_arg[4] == SEEK_SET)
    483 	    tprintf("%ld, %llu, ", tcp->u_arg[0],
    484 		    (((long long int) tcp->u_arg[1]) << 32
    485 		     | (unsigned long long) (unsigned) tcp->u_arg[2]));
    486 	else
    487 	    tprintf("%ld, %lld, ", tcp->u_arg[0],
    488 		    (((long long int) tcp->u_arg[1]) << 32
    489 		     | (unsigned long long) (unsigned) tcp->u_arg[2]));
    490     }
    491     else {
    492 	long long int off;
    493 	if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
    494 	    tprintf("%#lx, ", tcp->u_arg[3]);
    495 	else
    496 	    tprintf("[%llu], ", off);
    497 	printxval(whence, tcp->u_arg[4], "SEEK_???");
    498     }
    499     return 0;
    500 }
    501 
    502 int
    503 sys_readahead (tcp)
    504 struct tcb *tcp;
    505 {
    506     if (entering(tcp)) {
    507 	tprintf("%ld, %lld, %ld", tcp->u_arg[0],
    508 # if defined IA64 || defined X86_64 || defined ALPHA
    509 		(long long int) tcp->u_arg[1], tcp->u_arg[2]
    510 # else
    511 		LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]
    512 # endif
    513 		);
    514     }
    515     return 0;
    516 }
    517 #endif
    518 
    519 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
    520 int
    521 sys_lseek64 (tcp)
    522 struct tcb *tcp;
    523 {
    524 	if (entering(tcp)) {
    525 		long long offset;
    526 		ALIGN64 (tcp, 1);	/* FreeBSD aligns off_t args */
    527 		offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
    528 		if (tcp->u_arg[3] == SEEK_SET)
    529 			tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
    530 		else
    531 			tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
    532 		printxval(whence, tcp->u_arg[3], "SEEK_???");
    533 	}
    534 	return RVAL_LUDECIMAL;
    535 }
    536 #endif
    537 
    538 #ifndef HAVE_LONG_LONG_OFF_T
    539 int
    540 sys_truncate(tcp)
    541 struct tcb *tcp;
    542 {
    543 	if (entering(tcp)) {
    544 		printpath(tcp, tcp->u_arg[0]);
    545 		tprintf(", %lu", tcp->u_arg[1]);
    546 	}
    547 	return 0;
    548 }
    549 #endif
    550 
    551 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
    552 int
    553 sys_truncate64(tcp)
    554 struct tcb *tcp;
    555 {
    556 	if (entering(tcp)) {
    557 		ALIGN64 (tcp, 1);
    558 		printpath(tcp, tcp->u_arg[0]);
    559 		tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
    560 	}
    561 	return 0;
    562 }
    563 #endif
    564 
    565 #ifndef HAVE_LONG_LONG_OFF_T
    566 int
    567 sys_ftruncate(tcp)
    568 struct tcb *tcp;
    569 {
    570 	if (entering(tcp)) {
    571 		tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
    572 	}
    573 	return 0;
    574 }
    575 #endif
    576 
    577 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
    578 int
    579 sys_ftruncate64(tcp)
    580 struct tcb *tcp;
    581 {
    582 	if (entering(tcp)) {
    583 		ALIGN64 (tcp, 1);
    584 		tprintf("%ld, %llu", tcp->u_arg[0],
    585 			LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
    586 	}
    587 	return 0;
    588 }
    589 #endif
    590 
    591 /* several stats */
    592 
    593 static const struct xlat modetypes[] = {
    594 	{ S_IFREG,	"S_IFREG"	},
    595 	{ S_IFSOCK,	"S_IFSOCK"	},
    596 	{ S_IFIFO,	"S_IFIFO"	},
    597 	{ S_IFLNK,	"S_IFLNK"	},
    598 	{ S_IFDIR,	"S_IFDIR"	},
    599 	{ S_IFBLK,	"S_IFBLK"	},
    600 	{ S_IFCHR,	"S_IFCHR"	},
    601 	{ 0,		NULL		},
    602 };
    603 
    604 static const char *
    605 sprintmode(mode)
    606 int mode;
    607 {
    608 	static char buf[64];
    609 	const char *s;
    610 
    611 	if ((mode & S_IFMT) == 0)
    612 		s = "";
    613 	else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
    614 		sprintf(buf, "%#o", mode);
    615 		return buf;
    616 	}
    617 	sprintf(buf, "%s%s%s%s", s,
    618 		(mode & S_ISUID) ? "|S_ISUID" : "",
    619 		(mode & S_ISGID) ? "|S_ISGID" : "",
    620 		(mode & S_ISVTX) ? "|S_ISVTX" : "");
    621 	mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
    622 	if (mode)
    623 		sprintf(buf + strlen(buf), "|%#o", mode);
    624 	s = (*buf == '|') ? buf + 1 : buf;
    625 	return *s ? s : "0";
    626 }
    627 
    628 static char *
    629 sprinttime(t)
    630 time_t t;
    631 {
    632 	struct tm *tmp;
    633 	static char buf[32];
    634 
    635 	if (t == 0) {
    636 		sprintf(buf, "0");
    637 		return buf;
    638 	}
    639 	tmp = localtime(&t);
    640 	sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
    641 		tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
    642 		tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
    643 	return buf;
    644 }
    645 
    646 #ifdef LINUXSPARC
    647 typedef struct {
    648         int     tv_sec;
    649         int     tv_nsec;
    650 } timestruct_t;
    651 
    652 struct solstat {
    653         unsigned        st_dev;
    654         int             st_pad1[3];     /* network id */
    655         unsigned        st_ino;
    656         unsigned        st_mode;
    657         unsigned        st_nlink;
    658         unsigned        st_uid;
    659         unsigned        st_gid;
    660         unsigned        st_rdev;
    661         int             st_pad2[2];
    662         int             st_size;
    663         int             st_pad3;        /* st_size, off_t expansion */
    664         timestruct_t    st_atime;
    665         timestruct_t    st_mtime;
    666         timestruct_t    st_ctime;
    667         int             st_blksize;
    668         int             st_blocks;
    669         char            st_fstype[16];
    670         int             st_pad4[8];     /* expansion area */
    671 };
    672 
    673 static void
    674 printstatsol(tcp, addr)
    675 struct tcb *tcp;
    676 long addr;
    677 {
    678 	struct solstat statbuf;
    679 
    680 	if (!addr) {
    681 		tprintf("NULL");
    682 		return;
    683 	}
    684 	if (syserror(tcp) || !verbose(tcp)) {
    685 		tprintf("%#lx", addr);
    686 		return;
    687 	}
    688 	if (umove(tcp, addr, &statbuf) < 0) {
    689 		tprintf("{...}");
    690 		return;
    691 	}
    692 	if (!abbrev(tcp)) {
    693 		tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
    694 			(unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
    695 			(unsigned long) (statbuf.st_dev & 0x3ffff),
    696 			(unsigned long) statbuf.st_ino,
    697 			sprintmode(statbuf.st_mode));
    698 		tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
    699 			(unsigned long) statbuf.st_nlink,
    700 			(unsigned long) statbuf.st_uid,
    701 			(unsigned long) statbuf.st_gid);
    702 		tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
    703 		tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
    704 	}
    705 	else
    706 		tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
    707 	switch (statbuf.st_mode & S_IFMT) {
    708 	case S_IFCHR: case S_IFBLK:
    709 		tprintf("st_rdev=makedev(%lu, %lu), ",
    710 			(unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
    711 			(unsigned long) (statbuf.st_rdev & 0x3ffff));
    712 		break;
    713 	default:
    714 		tprintf("st_size=%u, ", statbuf.st_size);
    715 		break;
    716 	}
    717 	if (!abbrev(tcp)) {
    718 		tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
    719 		tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
    720 		tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
    721 	}
    722 	else
    723 		tprintf("...}");
    724 }
    725 
    726 #if defined (SPARC64)
    727 static void
    728 printstat_sparc64(tcp, addr)
    729 struct tcb *tcp;
    730 long addr;
    731 {
    732 	struct stat_sparc64 statbuf;
    733 
    734 	if (!addr) {
    735 		tprintf("NULL");
    736 		return;
    737 	}
    738 	if (syserror(tcp) || !verbose(tcp)) {
    739 		tprintf("%#lx", addr);
    740 		return;
    741 	}
    742 	if (umove(tcp, addr, &statbuf) < 0) {
    743 		tprintf("{...}");
    744 		return;
    745 	}
    746 
    747 	if (!abbrev(tcp)) {
    748 		tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
    749 			(unsigned long) major(statbuf.st_dev),
    750 			(unsigned long) minor(statbuf.st_dev),
    751 			(unsigned long) statbuf.st_ino,
    752 			sprintmode(statbuf.st_mode));
    753 		tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
    754 			(unsigned long) statbuf.st_nlink,
    755 			(unsigned long) statbuf.st_uid,
    756 			(unsigned long) statbuf.st_gid);
    757 		tprintf("st_blksize=%lu, ",
    758 			(unsigned long) statbuf.st_blksize);
    759 		tprintf("st_blocks=%lu, ",
    760 			(unsigned long) statbuf.st_blocks);
    761 	}
    762 	else
    763 		tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
    764 	switch (statbuf.st_mode & S_IFMT) {
    765 	case S_IFCHR: case S_IFBLK:
    766 		tprintf("st_rdev=makedev(%lu, %lu), ",
    767 			(unsigned long) major(statbuf.st_rdev),
    768 			(unsigned long) minor(statbuf.st_rdev));
    769 		break;
    770 	default:
    771 		tprintf("st_size=%lu, ", statbuf.st_size);
    772 		break;
    773 	}
    774 	if (!abbrev(tcp)) {
    775 		tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
    776 		tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
    777 		tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
    778 		tprintf("}");
    779 	}
    780 	else
    781 		tprintf("...}");
    782 }
    783 #endif /* SPARC64 */
    784 #endif /* LINUXSPARC */
    785 
    786 static const struct xlat fileflags[] = {
    787 #ifdef FREEBSD
    788 	{ UF_NODUMP,	"UF_NODUMP"	},
    789 	{ UF_IMMUTABLE,	"UF_IMMUTABLE"	},
    790 	{ UF_APPEND,	"UF_APPEND"	},
    791 	{ UF_OPAQUE,	"UF_OPAQUE"	},
    792 	{ UF_NOUNLINK,	"UF_NOUNLINK"	},
    793 	{ SF_ARCHIVED,	"SF_ARCHIVED"	},
    794 	{ SF_IMMUTABLE,	"SF_IMMUTABLE"	},
    795 	{ SF_APPEND,	"SF_APPEND"	},
    796 	{ SF_NOUNLINK,	"SF_NOUNLINK"	},
    797 #elif UNIXWARE >= 2
    798 #ifdef 	_S_ISMLD
    799 	{ _S_ISMLD, 	"_S_ISMLD"	},
    800 #endif
    801 #ifdef 	_S_ISMOUNTED
    802 	{ _S_ISMOUNTED, "_S_ISMOUNTED"	},
    803 #endif
    804 #endif
    805 	{ 0,		NULL		},
    806 };
    807 
    808 #ifdef FREEBSD
    809 int
    810 sys_chflags(tcp)
    811 struct tcb *tcp;
    812 {
    813 	if (entering(tcp)) {
    814 		printpath(tcp, tcp->u_arg[0]);
    815 		tprintf(", ");
    816 		printflags(fileflags, tcp->u_arg[1], "UF_???");
    817 	}
    818 	return 0;
    819 }
    820 
    821 int
    822 sys_fchflags(tcp)
    823 struct tcb *tcp;
    824 {
    825 	if (entering(tcp)) {
    826 		tprintf("%ld, ", tcp->u_arg[0]);
    827 		printflags(fileflags, tcp->u_arg[1], "UF_???");
    828 	}
    829 	return 0;
    830 }
    831 #endif
    832 
    833 #ifndef HAVE_LONG_LONG_OFF_T
    834 static void
    835 realprintstat(tcp, statbuf)
    836 struct tcb *tcp;
    837 struct stat *statbuf;
    838 {
    839     if (!abbrev(tcp)) {
    840 	    tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
    841 		    (unsigned long) major(statbuf->st_dev),
    842 		    (unsigned long) minor(statbuf->st_dev),
    843 		    (unsigned long) statbuf->st_ino,
    844 		    sprintmode(statbuf->st_mode));
    845 	    tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
    846 		    (unsigned long) statbuf->st_nlink,
    847 		    (unsigned long) statbuf->st_uid,
    848 		    (unsigned long) statbuf->st_gid);
    849 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
    850 	    tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
    851 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
    852 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
    853 	    tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
    854 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
    855     }
    856     else
    857 	    tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
    858     switch (statbuf->st_mode & S_IFMT) {
    859     case S_IFCHR: case S_IFBLK:
    860 #ifdef HAVE_STRUCT_STAT_ST_RDEV
    861 	    tprintf("st_rdev=makedev(%lu, %lu), ",
    862 		    (unsigned long) major(statbuf->st_rdev),
    863 		    (unsigned long) minor(statbuf->st_rdev));
    864 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
    865 	    tprintf("st_size=makedev(%lu, %lu), ",
    866 		    (unsigned long) major(statbuf->st_size),
    867 		    (unsigned long) minor(statbuf->st_size));
    868 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
    869 	    break;
    870     default:
    871 	    tprintf("st_size=%lu, ", statbuf->st_size);
    872 	    break;
    873     }
    874     if (!abbrev(tcp)) {
    875 	    tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
    876 	    tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
    877 	    tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
    878 #if HAVE_STRUCT_STAT_ST_FLAGS
    879 		tprintf(", st_flags=");
    880 		printflags(fileflags, statbuf->st_flags, "UF_???");
    881 #endif
    882 #if HAVE_STRUCT_STAT_ST_ACLCNT
    883 		tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
    884 #endif
    885 #if HAVE_STRUCT_STAT_ST_LEVEL
    886 		tprintf(", st_level=%ld", statbuf->st_level);
    887 #endif
    888 #if HAVE_STRUCT_STAT_ST_FSTYPE
    889 		tprintf(", st_fstype=%.*s",
    890 			(int) sizeof statbuf->st_fstype, statbuf->st_fstype);
    891 #endif
    892 #if HAVE_STRUCT_STAT_ST_GEN
    893 		tprintf(", st_gen=%u", statbuf->st_gen);
    894 #endif
    895 		tprintf("}");
    896     }
    897     else
    898 	    tprintf("...}");
    899 }
    900 
    901 
    902 static void
    903 printstat(tcp, addr)
    904 struct tcb *tcp;
    905 long addr;
    906 {
    907 	struct stat statbuf;
    908 
    909 #ifdef LINUXSPARC
    910  	if (current_personality == 1) {
    911  		printstatsol(tcp, addr);
    912  		return;
    913  	}
    914 #ifdef SPARC64
    915 	else if (current_personality == 2) {
    916 		printstat_sparc64(tcp, addr);
    917 		return;
    918 	}
    919 #endif
    920 #endif /* LINUXSPARC */
    921 
    922 	if (!addr) {
    923 		tprintf("NULL");
    924 		return;
    925 	}
    926 	if (syserror(tcp) || !verbose(tcp)) {
    927 		tprintf("%#lx", addr);
    928 		return;
    929 	}
    930 	if (umove(tcp, addr, &statbuf) < 0) {
    931 		tprintf("{...}");
    932 		return;
    933 	}
    934 
    935 	realprintstat(tcp, &statbuf);
    936 }
    937 #endif	/* !HAVE_LONG_LONG_OFF_T */
    938 
    939 #ifdef HAVE_STAT64
    940 static void
    941 printstat64(tcp, addr)
    942 struct tcb *tcp;
    943 long addr;
    944 {
    945 	struct stat64 statbuf;
    946 
    947 #ifdef LINUXSPARC
    948  	if (current_personality == 1) {
    949  		printstatsol(tcp, addr);
    950  		return;
    951  	}
    952 #ifdef SPARC64
    953 	else if (current_personality == 2) {
    954 		printstat_sparc64(tcp, addr);
    955 		return;
    956 	}
    957 #endif
    958 #endif /* LINUXSPARC */
    959 
    960 	if (!addr) {
    961 		tprintf("NULL");
    962 		return;
    963 	}
    964 	if (syserror(tcp) || !verbose(tcp)) {
    965 		tprintf("%#lx", addr);
    966 		return;
    967 	}
    968 	if (umove(tcp, addr, &statbuf) < 0) {
    969 		tprintf("{...}");
    970 		return;
    971 	}
    972 
    973 	if (!abbrev(tcp)) {
    974 #ifdef HAVE_LONG_LONG
    975 		tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
    976 #else
    977 		tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
    978 #endif
    979 			(unsigned long) major(statbuf.st_dev),
    980 			(unsigned long) minor(statbuf.st_dev),
    981 #ifdef HAVE_LONG_LONG
    982 			(unsigned long long) statbuf.st_ino,
    983 #else
    984 			(unsigned long) statbuf.st_ino,
    985 #endif
    986 			sprintmode(statbuf.st_mode));
    987 		tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
    988 			(unsigned long) statbuf.st_nlink,
    989 			(unsigned long) statbuf.st_uid,
    990 			(unsigned long) statbuf.st_gid);
    991 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
    992 		tprintf("st_blksize=%lu, ",
    993 			(unsigned long) statbuf.st_blksize);
    994 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
    995 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
    996 		tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
    997 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
    998 	}
    999 	else
   1000 		tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
   1001 	switch (statbuf.st_mode & S_IFMT) {
   1002 	case S_IFCHR: case S_IFBLK:
   1003 #ifdef HAVE_STRUCT_STAT_ST_RDEV
   1004 		tprintf("st_rdev=makedev(%lu, %lu), ",
   1005 			(unsigned long) major(statbuf.st_rdev),
   1006 			(unsigned long) minor(statbuf.st_rdev));
   1007 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
   1008 		tprintf("st_size=makedev(%lu, %lu), ",
   1009 			(unsigned long) major(statbuf.st_size),
   1010 			(unsigned long) minor(statbuf.st_size));
   1011 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
   1012 		break;
   1013 	default:
   1014 		tprintf("st_size=%llu, ", statbuf.st_size);
   1015 		break;
   1016 	}
   1017 	if (!abbrev(tcp)) {
   1018 		tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
   1019 		tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
   1020 		tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
   1021 #if HAVE_STRUCT_STAT_ST_FLAGS
   1022 		tprintf(", st_flags=");
   1023 		printflags(fileflags, statbuf.st_flags, "UF_???");
   1024 #endif
   1025 #if HAVE_STRUCT_STAT_ST_ACLCNT
   1026 		tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
   1027 #endif
   1028 #if HAVE_STRUCT_STAT_ST_LEVEL
   1029 		tprintf(", st_level=%ld", statbuf.st_level);
   1030 #endif
   1031 #if HAVE_STRUCT_STAT_ST_FSTYPE
   1032 		tprintf(", st_fstype=%.*s",
   1033 			(int) sizeof statbuf.st_fstype, statbuf.st_fstype);
   1034 #endif
   1035 #if HAVE_STRUCT_STAT_ST_GEN
   1036 		tprintf(", st_gen=%u", statbuf.st_gen);
   1037 #endif
   1038 		tprintf("}");
   1039 	}
   1040 	else
   1041 		tprintf("...}");
   1042 }
   1043 #endif /* HAVE_STAT64 */
   1044 
   1045 #if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
   1046 static void
   1047 convertoldstat(oldbuf, newbuf)
   1048 const struct __old_kernel_stat *oldbuf;
   1049 struct stat *newbuf;
   1050 {
   1051     newbuf->st_dev=oldbuf->st_dev;
   1052     newbuf->st_ino=oldbuf->st_ino;
   1053     newbuf->st_mode=oldbuf->st_mode;
   1054     newbuf->st_nlink=oldbuf->st_nlink;
   1055     newbuf->st_uid=oldbuf->st_uid;
   1056     newbuf->st_gid=oldbuf->st_gid;
   1057     newbuf->st_rdev=oldbuf->st_rdev;
   1058     newbuf->st_size=oldbuf->st_size;
   1059     newbuf->st_atime=oldbuf->st_atime;
   1060     newbuf->st_mtime=oldbuf->st_mtime;
   1061     newbuf->st_ctime=oldbuf->st_ctime;
   1062     newbuf->st_blksize=0;	/* not supported in old_stat */
   1063     newbuf->st_blocks=0;		/* not supported in old_stat */
   1064 }
   1065 
   1066 
   1067 static void
   1068 printoldstat(tcp, addr)
   1069 struct tcb *tcp;
   1070 long addr;
   1071 {
   1072 	struct __old_kernel_stat statbuf;
   1073 	struct stat newstatbuf;
   1074 
   1075 #ifdef LINUXSPARC
   1076  	if (current_personality == 1) {
   1077  		printstatsol(tcp, addr);
   1078  		return;
   1079  	}
   1080 #endif /* LINUXSPARC */
   1081 
   1082 	if (!addr) {
   1083 		tprintf("NULL");
   1084 		return;
   1085 	}
   1086 	if (syserror(tcp) || !verbose(tcp)) {
   1087 		tprintf("%#lx", addr);
   1088 		return;
   1089 	}
   1090 	if (umove(tcp, addr, &statbuf) < 0) {
   1091 		tprintf("{...}");
   1092 		return;
   1093 	}
   1094 
   1095 	convertoldstat(&statbuf, &newstatbuf);
   1096 	realprintstat(tcp, &newstatbuf);
   1097 }
   1098 #endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
   1099 
   1100 #ifndef HAVE_LONG_LONG_OFF_T
   1101 int
   1102 sys_stat(tcp)
   1103 struct tcb *tcp;
   1104 {
   1105 	if (entering(tcp)) {
   1106 		printpath(tcp, tcp->u_arg[0]);
   1107 		tprintf(", ");
   1108 	} else {
   1109 		printstat(tcp, tcp->u_arg[1]);
   1110 	}
   1111 	return 0;
   1112 }
   1113 #endif
   1114 
   1115 int
   1116 sys_stat64(tcp)
   1117 struct tcb *tcp;
   1118 {
   1119 #ifdef HAVE_STAT64
   1120 	if (entering(tcp)) {
   1121 		printpath(tcp, tcp->u_arg[0]);
   1122 		tprintf(", ");
   1123 	} else {
   1124 		printstat64(tcp, tcp->u_arg[1]);
   1125 	}
   1126 	return 0;
   1127 #else
   1128 	return printargs(tcp);
   1129 #endif
   1130 }
   1131 
   1132 #if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
   1133 int
   1134 sys_oldstat(tcp)
   1135 struct tcb *tcp;
   1136 {
   1137 	if (entering(tcp)) {
   1138 		printpath(tcp, tcp->u_arg[0]);
   1139 		tprintf(", ");
   1140 	} else {
   1141 		printoldstat(tcp, tcp->u_arg[1]);
   1142 	}
   1143 	return 0;
   1144 }
   1145 #endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
   1146 
   1147 #ifndef HAVE_LONG_LONG_OFF_T
   1148 int
   1149 sys_fstat(tcp)
   1150 struct tcb *tcp;
   1151 {
   1152 	if (entering(tcp))
   1153 		tprintf("%ld, ", tcp->u_arg[0]);
   1154 	else {
   1155 		printstat(tcp, tcp->u_arg[1]);
   1156 	}
   1157 	return 0;
   1158 }
   1159 #endif
   1160 
   1161 int
   1162 sys_fstat64(tcp)
   1163 struct tcb *tcp;
   1164 {
   1165 #ifdef HAVE_STAT64
   1166 	if (entering(tcp))
   1167 		tprintf("%ld, ", tcp->u_arg[0]);
   1168 	else {
   1169 		printstat64(tcp, tcp->u_arg[1]);
   1170 	}
   1171 	return 0;
   1172 #else
   1173 	return printargs(tcp);
   1174 #endif
   1175 }
   1176 
   1177 #if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
   1178 int
   1179 sys_oldfstat(tcp)
   1180 struct tcb *tcp;
   1181 {
   1182 	if (entering(tcp))
   1183 		tprintf("%ld, ", tcp->u_arg[0]);
   1184 	else {
   1185 		printoldstat(tcp, tcp->u_arg[1]);
   1186 	}
   1187 	return 0;
   1188 }
   1189 #endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
   1190 
   1191 #ifndef HAVE_LONG_LONG_OFF_T
   1192 int
   1193 sys_lstat(tcp)
   1194 struct tcb *tcp;
   1195 {
   1196 	if (entering(tcp)) {
   1197 		printpath(tcp, tcp->u_arg[0]);
   1198 		tprintf(", ");
   1199 	} else {
   1200 		printstat(tcp, tcp->u_arg[1]);
   1201 	}
   1202 	return 0;
   1203 }
   1204 #endif
   1205 
   1206 int
   1207 sys_lstat64(tcp)
   1208 struct tcb *tcp;
   1209 {
   1210 #ifdef HAVE_STAT64
   1211 	if (entering(tcp)) {
   1212 		printpath(tcp, tcp->u_arg[0]);
   1213 		tprintf(", ");
   1214 	} else {
   1215 		printstat64(tcp, tcp->u_arg[1]);
   1216 	}
   1217 	return 0;
   1218 #else
   1219 	return printargs(tcp);
   1220 #endif
   1221 }
   1222 
   1223 #if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
   1224 int
   1225 sys_oldlstat(tcp)
   1226 struct tcb *tcp;
   1227 {
   1228 	if (entering(tcp)) {
   1229 		printpath(tcp, tcp->u_arg[0]);
   1230 		tprintf(", ");
   1231 	} else {
   1232 		printoldstat(tcp, tcp->u_arg[1]);
   1233 	}
   1234 	return 0;
   1235 }
   1236 #endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
   1237 
   1238 
   1239 #if defined(SVR4) || defined(LINUXSPARC)
   1240 
   1241 int
   1242 sys_xstat(tcp)
   1243 struct tcb *tcp;
   1244 {
   1245 	if (entering(tcp)) {
   1246 		tprintf("%ld, ", tcp->u_arg[0]);
   1247 		printpath(tcp, tcp->u_arg[1]);
   1248 		tprintf(", ");
   1249 	} else {
   1250 #ifdef _STAT64_VER
   1251 		if (tcp->u_arg[0] == _STAT64_VER)
   1252 			printstat64 (tcp, tcp->u_arg[2]);
   1253 		else
   1254 #endif
   1255 		printstat(tcp, tcp->u_arg[2]);
   1256 	}
   1257 	return 0;
   1258 }
   1259 
   1260 int
   1261 sys_fxstat(tcp)
   1262 struct tcb *tcp;
   1263 {
   1264 	if (entering(tcp))
   1265 		tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
   1266 	else {
   1267 #ifdef _STAT64_VER
   1268 		if (tcp->u_arg[0] == _STAT64_VER)
   1269 			printstat64 (tcp, tcp->u_arg[2]);
   1270 		else
   1271 #endif
   1272 		printstat(tcp, tcp->u_arg[2]);
   1273 	}
   1274 	return 0;
   1275 }
   1276 
   1277 int
   1278 sys_lxstat(tcp)
   1279 struct tcb *tcp;
   1280 {
   1281 	if (entering(tcp)) {
   1282 		tprintf("%ld, ", tcp->u_arg[0]);
   1283 		printpath(tcp, tcp->u_arg[1]);
   1284 		tprintf(", ");
   1285 	} else {
   1286 #ifdef _STAT64_VER
   1287 		if (tcp->u_arg[0] == _STAT64_VER)
   1288 			printstat64 (tcp, tcp->u_arg[2]);
   1289 		else
   1290 #endif
   1291 		printstat(tcp, tcp->u_arg[2]);
   1292 	}
   1293 	return 0;
   1294 }
   1295 
   1296 int
   1297 sys_xmknod(tcp)
   1298 struct tcb *tcp;
   1299 {
   1300 	int mode = tcp->u_arg[2];
   1301 
   1302 	if (entering(tcp)) {
   1303 		tprintf("%ld, ", tcp->u_arg[0]);
   1304 		printpath(tcp, tcp->u_arg[1]);
   1305 		tprintf(", %s", sprintmode(mode));
   1306 		switch (mode & S_IFMT) {
   1307 		case S_IFCHR: case S_IFBLK:
   1308 #ifdef LINUXSPARC
   1309 			tprintf(", makedev(%lu, %lu)",
   1310 				(unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
   1311 				(unsigned long) (tcp->u_arg[3] & 0x3ffff));
   1312 #else
   1313 			tprintf(", makedev(%lu, %lu)",
   1314 				(unsigned long) major(tcp->u_arg[3]),
   1315 				(unsigned long) minor(tcp->u_arg[3]));
   1316 #endif
   1317 			break;
   1318 		default:
   1319 			break;
   1320 		}
   1321 	}
   1322 	return 0;
   1323 }
   1324 
   1325 #ifdef HAVE_SYS_ACL_H
   1326 
   1327 #include <sys/acl.h>
   1328 
   1329 static const struct xlat aclcmds[] = {
   1330 #ifdef SETACL
   1331 	{ SETACL,	"SETACL"	},
   1332 #endif
   1333 #ifdef GETACL
   1334 	{ GETACL,	"GETACL"	},
   1335 #endif
   1336 #ifdef GETACLCNT
   1337 	{ GETACLCNT,	"GETACLCNT"	},
   1338 #endif
   1339 #ifdef ACL_GET
   1340 	{ ACL_GET,	"ACL_GET"	},
   1341 #endif
   1342 #ifdef ACL_SET
   1343 	{ ACL_SET,	"ACL_SET"	},
   1344 #endif
   1345 #ifdef ACL_CNT
   1346 	{ ACL_CNT,	"ACL_CNT"	},
   1347 #endif
   1348 	{ 0,		NULL		},
   1349 };
   1350 
   1351 int
   1352 sys_acl(tcp)
   1353 struct tcb *tcp;
   1354 {
   1355 	if (entering(tcp)) {
   1356 		printpath(tcp, tcp->u_arg[0]);
   1357 		tprintf(", ");
   1358 		printxval(aclcmds, tcp->u_arg[1], "???ACL???");
   1359 		tprintf(", %ld", tcp->u_arg[2]);
   1360 		/*
   1361 		 * FIXME - dump out the list of aclent_t's pointed to
   1362 		 * by "tcp->u_arg[3]" if it's not NULL.
   1363 		 */
   1364 		if (tcp->u_arg[3])
   1365 			tprintf(", %#lx", tcp->u_arg[3]);
   1366 		else
   1367 			tprintf(", NULL");
   1368 	}
   1369 	return 0;
   1370 }
   1371 
   1372 
   1373 int
   1374 sys_facl(tcp)
   1375 struct tcb *tcp;
   1376 {
   1377 	if (entering(tcp)) {
   1378 		tprintf("%ld, ", tcp->u_arg[0]);
   1379 		printxval(aclcmds, tcp->u_arg[1], "???ACL???");
   1380 		tprintf(", %ld", tcp->u_arg[2]);
   1381 		/*
   1382 		 * FIXME - dump out the list of aclent_t's pointed to
   1383 		 * by "tcp->u_arg[3]" if it's not NULL.
   1384 		 */
   1385 		if (tcp->u_arg[3])
   1386 			tprintf(", %#lx", tcp->u_arg[3]);
   1387 		else
   1388 			tprintf(", NULL");
   1389 	}
   1390 	return 0;
   1391 }
   1392 
   1393 
   1394 static const struct xlat aclipc[] = {
   1395 #ifdef IPC_SHM
   1396 	{ IPC_SHM,	"IPC_SHM"	},
   1397 #endif
   1398 #ifdef IPC_SEM
   1399 	{ IPC_SEM,	"IPC_SEM"	},
   1400 #endif
   1401 #ifdef IPC_MSG
   1402 	{ IPC_MSG,	"IPC_MSG"	},
   1403 #endif
   1404 	{ 0,		NULL		},
   1405 };
   1406 
   1407 
   1408 int
   1409 sys_aclipc(tcp)
   1410 struct tcb *tcp;
   1411 {
   1412 	if (entering(tcp)) {
   1413 		printxval(aclipc, tcp->u_arg[0], "???IPC???");
   1414 		tprintf(", %#lx, ", tcp->u_arg[1]);
   1415 		printxval(aclcmds, tcp->u_arg[2], "???ACL???");
   1416 		tprintf(", %ld", tcp->u_arg[3]);
   1417 		/*
   1418 		 * FIXME - dump out the list of aclent_t's pointed to
   1419 		 * by "tcp->u_arg[4]" if it's not NULL.
   1420 		 */
   1421 		if (tcp->u_arg[4])
   1422 			tprintf(", %#lx", tcp->u_arg[4]);
   1423 		else
   1424 			tprintf(", NULL");
   1425 	}
   1426 	return 0;
   1427 }
   1428 
   1429 
   1430 
   1431 #endif /* HAVE_SYS_ACL_H */
   1432 
   1433 #endif /* SVR4 || LINUXSPARC */
   1434 
   1435 #ifdef LINUX
   1436 
   1437 static const struct xlat fsmagic[] = {
   1438 	{ 0x73757245,	"CODA_SUPER_MAGIC"	},
   1439 	{ 0x012ff7b7,	"COH_SUPER_MAGIC"	},
   1440 	{ 0x1373,	"DEVFS_SUPER_MAGIC"	},
   1441 	{ 0x1cd1,	"DEVPTS_SUPER_MAGIC"	},
   1442 	{ 0x414A53,	"EFS_SUPER_MAGIC"	},
   1443 	{ 0xef51,	"EXT2_OLD_SUPER_MAGIC"	},
   1444 	{ 0xef53,	"EXT2_SUPER_MAGIC"	},
   1445 	{ 0x137d,	"EXT_SUPER_MAGIC"	},
   1446 	{ 0xf995e849,	"HPFS_SUPER_MAGIC"	},
   1447 	{ 0x9660,	"ISOFS_SUPER_MAGIC"	},
   1448 	{ 0x137f,	"MINIX_SUPER_MAGIC"	},
   1449 	{ 0x138f,	"MINIX_SUPER_MAGIC2"	},
   1450 	{ 0x2468,	"MINIX2_SUPER_MAGIC"	},
   1451 	{ 0x2478,	"MINIX2_SUPER_MAGIC2"	},
   1452 	{ 0x4d44,	"MSDOS_SUPER_MAGIC"	},
   1453 	{ 0x564c,	"NCP_SUPER_MAGIC"	},
   1454 	{ 0x6969,	"NFS_SUPER_MAGIC"	},
   1455 	{ 0x9fa0,	"PROC_SUPER_MAGIC"	},
   1456 	{ 0x002f,	"QNX4_SUPER_MAGIC"	},
   1457 	{ 0x52654973,	"REISERFS_SUPER_MAGIC"	},
   1458 	{ 0x02011994,	"SHMFS_SUPER_MAGIC"	},
   1459 	{ 0x517b,	"SMB_SUPER_MAGIC"	},
   1460 	{ 0x012ff7b6,	"SYSV2_SUPER_MAGIC"	},
   1461 	{ 0x012ff7b5,	"SYSV4_SUPER_MAGIC"	},
   1462 	{ 0x00011954,	"UFS_MAGIC"		},
   1463 	{ 0x54190100,	"UFS_CIGAM"		},
   1464 	{ 0x012ff7b4,	"XENIX_SUPER_MAGIC"	},
   1465 	{ 0x012fd16d,	"XIAFS_SUPER_MAGIC"	},
   1466 	{ 0x62656572,	"SYSFS_MAGIC"		},
   1467 	{ 0,		NULL			},
   1468 };
   1469 
   1470 #endif /* LINUX */
   1471 
   1472 #ifndef SVR4
   1473 
   1474 static const char *
   1475 sprintfstype(magic)
   1476 int magic;
   1477 {
   1478 	static char buf[32];
   1479 #ifdef LINUX
   1480 	const char *s;
   1481 
   1482 	s = xlookup(fsmagic, magic);
   1483 	if (s) {
   1484 		sprintf(buf, "\"%s\"", s);
   1485 		return buf;
   1486 	}
   1487 #endif /* LINUX */
   1488 	sprintf(buf, "%#x", magic);
   1489 	return buf;
   1490 }
   1491 
   1492 static void
   1493 printstatfs(tcp, addr)
   1494 struct tcb *tcp;
   1495 long addr;
   1496 {
   1497 	struct statfs statbuf;
   1498 
   1499 	if (syserror(tcp) || !verbose(tcp)) {
   1500 		tprintf("%#lx", addr);
   1501 		return;
   1502 	}
   1503 	if (umove(tcp, addr, &statbuf) < 0) {
   1504 		tprintf("{...}");
   1505 		return;
   1506 	}
   1507 #ifdef ALPHA
   1508 
   1509 	tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
   1510 		sprintfstype(statbuf.f_type),
   1511 		statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
   1512 	tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
   1513 		statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
   1514 		statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
   1515 		statbuf.f_namelen);
   1516 #else /* !ALPHA */
   1517 	tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
   1518 		sprintfstype(statbuf.f_type),
   1519 		(unsigned long)statbuf.f_bsize,
   1520 		(unsigned long)statbuf.f_blocks,
   1521 		(unsigned long)statbuf.f_bfree);
   1522 	tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
   1523 		(unsigned long)statbuf.f_bavail,
   1524 		(unsigned long)statbuf.f_files,
   1525 		(unsigned long)statbuf.f_ffree,
   1526 		statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
   1527 #ifdef LINUX
   1528 	tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
   1529 #endif /* LINUX */
   1530 #endif /* !ALPHA */
   1531 #ifdef _STATFS_F_FRSIZE
   1532 	tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
   1533 #endif
   1534 	tprintf("}");
   1535 }
   1536 
   1537 int
   1538 sys_statfs(tcp)
   1539 struct tcb *tcp;
   1540 {
   1541 	if (entering(tcp)) {
   1542 		printpath(tcp, tcp->u_arg[0]);
   1543 		tprintf(", ");
   1544 	} else {
   1545 		printstatfs(tcp, tcp->u_arg[1]);
   1546 	}
   1547 	return 0;
   1548 }
   1549 
   1550 int
   1551 sys_fstatfs(tcp)
   1552 struct tcb *tcp;
   1553 {
   1554 	if (entering(tcp)) {
   1555 		tprintf("%lu, ", tcp->u_arg[0]);
   1556 	} else {
   1557 		printstatfs(tcp, tcp->u_arg[1]);
   1558 	}
   1559 	return 0;
   1560 }
   1561 
   1562 #ifdef LINUX
   1563 static void
   1564 printstatfs64(tcp, addr)
   1565 struct tcb *tcp;
   1566 long addr;
   1567 {
   1568 	struct statfs64 statbuf;
   1569 
   1570 	if (syserror(tcp) || !verbose(tcp)) {
   1571 		tprintf("%#lx", addr);
   1572 		return;
   1573 	}
   1574 	if (umove(tcp, addr, &statbuf) < 0) {
   1575 		tprintf("{...}");
   1576 		return;
   1577 	}
   1578 	tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
   1579 		sprintfstype(statbuf.f_type),
   1580 		(unsigned long long)statbuf.f_bsize,
   1581 		(unsigned long long)statbuf.f_blocks,
   1582 		(unsigned long long)statbuf.f_bfree);
   1583 	tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
   1584 		(unsigned long long)statbuf.f_bavail,
   1585 		(unsigned long long)statbuf.f_files,
   1586 		(unsigned long long)statbuf.f_ffree,
   1587 		statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
   1588 	tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
   1589 #ifdef _STATFS_F_FRSIZE
   1590 	tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
   1591 #endif
   1592 	tprintf("}");
   1593 }
   1594 
   1595 int
   1596 sys_statfs64(tcp)
   1597 struct tcb *tcp;
   1598 {
   1599 	if (entering(tcp)) {
   1600 		printpath(tcp, tcp->u_arg[0]);
   1601 		tprintf(", %lu, ", tcp->u_arg[1]);
   1602 	} else {
   1603 		if (tcp->u_arg[1] == sizeof (struct statfs64))
   1604 			printstatfs64(tcp, tcp->u_arg[2]);
   1605 		else
   1606 			tprintf("{???}");
   1607 	}
   1608 	return 0;
   1609 }
   1610 
   1611 int
   1612 sys_fstatfs64(tcp)
   1613 struct tcb *tcp;
   1614 {
   1615 	if (entering(tcp)) {
   1616 		tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
   1617 	} else {
   1618 		if (tcp->u_arg[1] == sizeof (struct statfs64))
   1619 			printstatfs64(tcp, tcp->u_arg[2]);
   1620 		else
   1621 			tprintf("{???}");
   1622 	}
   1623 	return 0;
   1624 }
   1625 #endif
   1626 
   1627 #if defined(LINUX) && defined(__alpha)
   1628 
   1629 int
   1630 osf_statfs(tcp)
   1631 struct tcb *tcp;
   1632 {
   1633 	if (entering(tcp)) {
   1634 		printpath(tcp, tcp->u_arg[0]);
   1635 		tprintf(", ");
   1636 	} else {
   1637 		printstatfs(tcp, tcp->u_arg[1]);
   1638 		tprintf(", %lu", tcp->u_arg[2]);
   1639 	}
   1640 	return 0;
   1641 }
   1642 
   1643 int
   1644 osf_fstatfs(tcp)
   1645 struct tcb *tcp;
   1646 {
   1647 	if (entering(tcp)) {
   1648 		tprintf("%lu, ", tcp->u_arg[0]);
   1649 	} else {
   1650 		printstatfs(tcp, tcp->u_arg[1]);
   1651 		tprintf(", %lu", tcp->u_arg[2]);
   1652 	}
   1653 	return 0;
   1654 }
   1655 #endif /* LINUX && __alpha */
   1656 
   1657 #endif /* !SVR4 */
   1658 
   1659 #ifdef SUNOS4
   1660 
   1661 int
   1662 sys_ustat(tcp)
   1663 struct tcb *tcp;
   1664 {
   1665 	struct ustat statbuf;
   1666 
   1667 	if (entering(tcp)) {
   1668 		tprintf("makedev(%lu, %lu), ",
   1669 				(long) major(tcp->u_arg[0]),
   1670 				(long) minor(tcp->u_arg[0]));
   1671 	}
   1672 	else {
   1673 		if (syserror(tcp) || !verbose(tcp))
   1674 			tprintf("%#lx", tcp->u_arg[1]);
   1675 		else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
   1676 			tprintf("{...}");
   1677 		else {
   1678 			tprintf("{f_tfree=%lu, f_tinode=%lu, ",
   1679 				statbuf.f_tfree, statbuf.f_tinode);
   1680 			tprintf("f_fname=\"%.*s\", ",
   1681 				(int) sizeof(statbuf.f_fname),
   1682 				statbuf.f_fname);
   1683 			tprintf("f_fpack=\"%.*s\"}",
   1684 				(int) sizeof(statbuf.f_fpack),
   1685 				statbuf.f_fpack);
   1686 		}
   1687 	}
   1688 	return 0;
   1689 }
   1690 
   1691 #endif /* SUNOS4 */
   1692 
   1693 int
   1694 sys_pivotroot(tcp)
   1695 struct tcb *tcp;
   1696 {
   1697 	if (entering(tcp)) {
   1698 		printpath(tcp, tcp->u_arg[0]);
   1699 		tprintf(", ");
   1700 		printpath(tcp, tcp->u_arg[1]);
   1701 	}
   1702 	return 0;
   1703 }
   1704 
   1705 
   1706 /* directory */
   1707 int
   1708 sys_chdir(tcp)
   1709 struct tcb *tcp;
   1710 {
   1711 	if (entering(tcp)) {
   1712 		printpath(tcp, tcp->u_arg[0]);
   1713 	}
   1714 	return 0;
   1715 }
   1716 
   1717 int
   1718 sys_mkdir(tcp)
   1719 struct tcb *tcp;
   1720 {
   1721 	if (entering(tcp)) {
   1722 		printpath(tcp, tcp->u_arg[0]);
   1723 		tprintf(", %#lo", tcp->u_arg[1]);
   1724 	}
   1725 	return 0;
   1726 }
   1727 
   1728 int
   1729 sys_rmdir(tcp)
   1730 struct tcb *tcp;
   1731 {
   1732 	if (entering(tcp)) {
   1733 		printpath(tcp, tcp->u_arg[0]);
   1734 	}
   1735 	return 0;
   1736 }
   1737 
   1738 int
   1739 sys_fchdir(tcp)
   1740 struct tcb *tcp;
   1741 {
   1742 	if (entering(tcp)) {
   1743 		tprintf("%ld", tcp->u_arg[0]);
   1744 	}
   1745 	return 0;
   1746 }
   1747 
   1748 int
   1749 sys_chroot(tcp)
   1750 struct tcb *tcp;
   1751 {
   1752 	if (entering(tcp)) {
   1753 		printpath(tcp, tcp->u_arg[0]);
   1754 	}
   1755 	return 0;
   1756 }
   1757 
   1758 int
   1759 sys_fchroot(tcp)
   1760 struct tcb *tcp;
   1761 {
   1762 	if (entering(tcp)) {
   1763 		tprintf("%ld", tcp->u_arg[0]);
   1764 	}
   1765 	return 0;
   1766 }
   1767 
   1768 int
   1769 sys_link(tcp)
   1770 struct tcb *tcp;
   1771 {
   1772 	if (entering(tcp)) {
   1773 		printpath(tcp, tcp->u_arg[0]);
   1774 		tprintf(", ");
   1775 		printpath(tcp, tcp->u_arg[1]);
   1776 	}
   1777 	return 0;
   1778 }
   1779 
   1780 int
   1781 sys_unlink(tcp)
   1782 struct tcb *tcp;
   1783 {
   1784 	if (entering(tcp)) {
   1785 		printpath(tcp, tcp->u_arg[0]);
   1786 	}
   1787 	return 0;
   1788 }
   1789 
   1790 int
   1791 sys_symlink(tcp)
   1792 struct tcb *tcp;
   1793 {
   1794 	if (entering(tcp)) {
   1795 		printpath(tcp, tcp->u_arg[0]);
   1796 		tprintf(", ");
   1797 		printpath(tcp, tcp->u_arg[1]);
   1798 	}
   1799 	return 0;
   1800 }
   1801 
   1802 int
   1803 sys_readlink(tcp)
   1804 struct tcb *tcp;
   1805 {
   1806 	if (entering(tcp)) {
   1807 		printpath(tcp, tcp->u_arg[0]);
   1808 		tprintf(", ");
   1809 	} else {
   1810 		if (syserror(tcp))
   1811 			tprintf("%#lx", tcp->u_arg[1]);
   1812 		else
   1813 			printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
   1814 		tprintf(", %lu", tcp->u_arg[2]);
   1815 	}
   1816 	return 0;
   1817 }
   1818 
   1819 int
   1820 sys_rename(tcp)
   1821 struct tcb *tcp;
   1822 {
   1823 	if (entering(tcp)) {
   1824 		printpath(tcp, tcp->u_arg[0]);
   1825 		tprintf(", ");
   1826 		printpath(tcp, tcp->u_arg[1]);
   1827 	}
   1828 	return 0;
   1829 }
   1830 
   1831 int
   1832 sys_chown(tcp)
   1833 struct tcb *tcp;
   1834 {
   1835 	if (entering(tcp)) {
   1836 		printpath(tcp, tcp->u_arg[0]);
   1837 		printuid(", ", tcp->u_arg[1]);
   1838 		printuid(", ", tcp->u_arg[2]);
   1839 	}
   1840 	return 0;
   1841 }
   1842 
   1843 int
   1844 sys_fchown(tcp)
   1845 struct tcb *tcp;
   1846 {
   1847 	if (entering(tcp)) {
   1848 		tprintf("%ld", tcp->u_arg[0]);
   1849 		printuid(", ", tcp->u_arg[1]);
   1850 		printuid(", ", tcp->u_arg[2]);
   1851 	}
   1852 	return 0;
   1853 }
   1854 
   1855 int
   1856 sys_chmod(tcp)
   1857 struct tcb *tcp;
   1858 {
   1859 	if (entering(tcp)) {
   1860 		printpath(tcp, tcp->u_arg[0]);
   1861 		tprintf(", %#lo", tcp->u_arg[1]);
   1862 	}
   1863 	return 0;
   1864 }
   1865 
   1866 int
   1867 sys_fchmod(tcp)
   1868 struct tcb *tcp;
   1869 {
   1870 	if (entering(tcp)) {
   1871 		tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
   1872 	}
   1873 	return 0;
   1874 }
   1875 
   1876 #ifdef ALPHA
   1877 int
   1878 sys_osf_utimes(tcp)
   1879 struct tcb *tcp;
   1880 {
   1881     if (entering(tcp)) {
   1882 	printpath(tcp, tcp->u_arg[0]);
   1883 	tprintf(", ");
   1884 	printtv32(tcp, tcp->u_arg[1]);
   1885     }
   1886     return 0;
   1887 }
   1888 #endif
   1889 
   1890 int
   1891 sys_utimes(tcp)
   1892 struct tcb *tcp;
   1893 {
   1894 	if (entering(tcp)) {
   1895 		printpath(tcp, tcp->u_arg[0]);
   1896 		tprintf(", ");
   1897 		printtv(tcp, tcp->u_arg[1]);
   1898 	}
   1899 	return 0;
   1900 }
   1901 
   1902 int
   1903 sys_utime(tcp)
   1904 struct tcb *tcp;
   1905 {
   1906 	long ut[2];
   1907 
   1908 	if (entering(tcp)) {
   1909 		printpath(tcp, tcp->u_arg[0]);
   1910 		tprintf(", ");
   1911 		if (!tcp->u_arg[1])
   1912 			tprintf("NULL");
   1913 		else if (!verbose(tcp))
   1914 			tprintf("%#lx", tcp->u_arg[1]);
   1915 		else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
   1916 		    (char *) ut) < 0)
   1917 			tprintf("[?, ?]");
   1918 		else {
   1919 			tprintf("[%s,", sprinttime(ut[0]));
   1920 			tprintf(" %s]", sprinttime(ut[1]));
   1921 		}
   1922 	}
   1923 	return 0;
   1924 }
   1925 
   1926 int
   1927 sys_mknod(tcp)
   1928 struct tcb *tcp;
   1929 {
   1930 	int mode = tcp->u_arg[1];
   1931 
   1932 	if (entering(tcp)) {
   1933 		printpath(tcp, tcp->u_arg[0]);
   1934 		tprintf(", %s", sprintmode(mode));
   1935 		switch (mode & S_IFMT) {
   1936 		case S_IFCHR: case S_IFBLK:
   1937 #ifdef LINUXSPARC
   1938 			if (current_personality == 1)
   1939 			tprintf(", makedev(%lu, %lu)",
   1940 				(unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
   1941 				(unsigned long) (tcp->u_arg[2] & 0x3ffff));
   1942 			else
   1943 #endif
   1944 			tprintf(", makedev(%lu, %lu)",
   1945 				(unsigned long) major(tcp->u_arg[2]),
   1946 				(unsigned long) minor(tcp->u_arg[2]));
   1947 			break;
   1948 		default:
   1949 			break;
   1950 		}
   1951 	}
   1952 	return 0;
   1953 }
   1954 
   1955 int
   1956 sys_mkfifo(tcp)
   1957 struct tcb *tcp;
   1958 {
   1959 	if (entering(tcp)) {
   1960 		printpath(tcp, tcp->u_arg[0]);
   1961 		tprintf(", %#lo", tcp->u_arg[1]);
   1962 	}
   1963 	return 0;
   1964 }
   1965 
   1966 int
   1967 sys_fsync(tcp)
   1968 struct tcb *tcp;
   1969 {
   1970 	if (entering(tcp)) {
   1971 		tprintf("%ld", tcp->u_arg[0]);
   1972 	}
   1973 	return 0;
   1974 }
   1975 
   1976 #ifdef LINUX
   1977 
   1978 static void
   1979 printdir(tcp, addr)
   1980 struct tcb *tcp;
   1981 long addr;
   1982 {
   1983 	struct dirent d;
   1984 
   1985 	if (!verbose(tcp)) {
   1986 		tprintf("%#lx", addr);
   1987 		return;
   1988 	}
   1989 	if (umove(tcp, addr, &d) < 0) {
   1990 		tprintf("{...}");
   1991 		return;
   1992 	}
   1993 	tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
   1994 	tprintf("d_name=");
   1995 	printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
   1996 	tprintf("}");
   1997 }
   1998 
   1999 int
   2000 sys_readdir(tcp)
   2001 struct tcb *tcp;
   2002 {
   2003 	if (entering(tcp)) {
   2004 		tprintf("%lu, ", tcp->u_arg[0]);
   2005 	} else {
   2006 		if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
   2007 			tprintf("%#lx", tcp->u_arg[1]);
   2008 		else
   2009 			printdir(tcp, tcp->u_arg[1]);
   2010 		/* Not much point in printing this out, it is always 1. */
   2011 		if (tcp->u_arg[2] != 1)
   2012 			tprintf(", %lu", tcp->u_arg[2]);
   2013 	}
   2014 	return 0;
   2015 }
   2016 
   2017 #endif /* LINUX */
   2018 
   2019 #if defined FREEBSD || defined LINUX
   2020 static const struct xlat direnttypes[] = {
   2021 	{ DT_UNKNOWN,	"DT_UNKNOWN" 	},
   2022 	{ DT_FIFO,	"DT_FIFO" 	},
   2023 	{ DT_CHR,	"DT_CHR" 	},
   2024 	{ DT_DIR,	"DT_DIR" 	},
   2025 	{ DT_BLK,	"DT_BLK" 	},
   2026 	{ DT_REG,	"DT_REG" 	},
   2027 	{ DT_LNK,	"DT_LNK" 	},
   2028 	{ DT_SOCK,	"DT_SOCK" 	},
   2029 	{ DT_WHT,	"DT_WHT" 	},
   2030 	{ 0,		NULL		},
   2031 };
   2032 
   2033 #endif
   2034 
   2035 int
   2036 sys_getdents(tcp)
   2037 struct tcb *tcp;
   2038 {
   2039 	int i, len, dents = 0;
   2040 	char *buf;
   2041 
   2042 	if (entering(tcp)) {
   2043 		tprintf("%lu, ", tcp->u_arg[0]);
   2044 		return 0;
   2045 	}
   2046 	if (syserror(tcp) || !verbose(tcp)) {
   2047 		tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
   2048 		return 0;
   2049 	}
   2050 	len = tcp->u_rval;
   2051 	if ((buf = malloc(len)) == NULL) {
   2052 		tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
   2053 		fprintf(stderr, "out of memory\n");
   2054 		return 0;
   2055 	}
   2056 	if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
   2057 		tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
   2058 		free(buf);
   2059 		return 0;
   2060 	}
   2061 	if (!abbrev(tcp))
   2062 		tprintf("{");
   2063 	for (i = 0; i < len;) {
   2064 		struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
   2065 #ifdef LINUX
   2066 		if (!abbrev(tcp)) {
   2067 			tprintf("%s{d_ino=%lu, d_off=%lu, ",
   2068 				i ? " " : "", d->d_ino, d->d_off);
   2069 			tprintf("d_reclen=%u, d_name=\"%s\"}",
   2070 				d->d_reclen, d->d_name);
   2071 		}
   2072 #endif /* LINUX */
   2073 #ifdef SVR4
   2074 		if (!abbrev(tcp)) {
   2075 			tprintf("%s{d_ino=%lu, d_off=%lu, ",
   2076 				i ? " " : "",
   2077 				(unsigned long) d->d_ino,
   2078 				(unsigned long) d->d_off);
   2079 			tprintf("d_reclen=%u, d_name=\"%s\"}",
   2080 				d->d_reclen, d->d_name);
   2081 		}
   2082 #endif /* SVR4 */
   2083 #ifdef SUNOS4
   2084 		if (!abbrev(tcp)) {
   2085 			tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
   2086 				i ? " " : "", d->d_off, d->d_fileno,
   2087 				d->d_reclen);
   2088 			tprintf("d_namlen=%u, d_name=\"%.*s\"}",
   2089 				d->d_namlen, d->d_namlen, d->d_name);
   2090 		}
   2091 #endif /* SUNOS4 */
   2092 #ifdef FREEBSD
   2093 		if (!abbrev(tcp)) {
   2094 			tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
   2095 				i ? " " : "", d->d_fileno, d->d_reclen);
   2096 			printxval(direnttypes, d->d_type, "DT_???");
   2097 			tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
   2098 				d->d_namlen, d->d_namlen, d->d_name);
   2099 		}
   2100 #endif /* FREEBSD */
   2101 		if (!d->d_reclen) {
   2102 			tprintf("/* d_reclen == 0, problem here */");
   2103 			break;
   2104 		}
   2105 		i += d->d_reclen;
   2106 		dents++;
   2107 	}
   2108 	if (!abbrev(tcp))
   2109 		tprintf("}");
   2110 	else
   2111 		tprintf("/* %u entries */", dents);
   2112 	tprintf(", %lu", tcp->u_arg[2]);
   2113 	free(buf);
   2114 	return 0;
   2115 }
   2116 
   2117 
   2118 #if _LFS64_LARGEFILE
   2119 int
   2120 sys_getdents64(tcp)
   2121 struct tcb *tcp;
   2122 {
   2123 	int i, len, dents = 0;
   2124 	char *buf;
   2125 
   2126 	if (entering(tcp)) {
   2127 		tprintf("%lu, ", tcp->u_arg[0]);
   2128 		return 0;
   2129 	}
   2130 	if (syserror(tcp) || !verbose(tcp)) {
   2131 		tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
   2132 		return 0;
   2133 	}
   2134 	len = tcp->u_rval;
   2135 	if ((buf = malloc(len)) == NULL) {
   2136 		tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
   2137 		fprintf(stderr, "out of memory\n");
   2138 		return 0;
   2139 	}
   2140 	if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
   2141 		tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
   2142 		free(buf);
   2143 		return 0;
   2144 	}
   2145 	if (!abbrev(tcp))
   2146 		tprintf("{");
   2147 	for (i = 0; i < len;) {
   2148 		struct dirent64 *d = (struct dirent64 *) &buf[i];
   2149 #if defined(LINUX) || defined(SVR4)
   2150 		if (!abbrev(tcp)) {
   2151 			tprintf("%s{d_ino=%llu, d_off=%llu, ",
   2152 				i ? " " : "",
   2153 				d->d_ino,
   2154 				d->d_off);
   2155 #ifdef LINUX
   2156 			tprintf("d_type=");
   2157 			printxval(direnttypes, d->d_type, "DT_???");
   2158 			tprintf(", ");
   2159 #endif
   2160 			tprintf("d_reclen=%u, d_name=\"%s\"}",
   2161 				d->d_reclen, d->d_name);
   2162 		}
   2163 #endif /* LINUX || SVR4 */
   2164 #ifdef SUNOS4
   2165 		if (!abbrev(tcp)) {
   2166 			tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
   2167 				i ? " " : "", d->d_off, d->d_fileno,
   2168 				d->d_reclen);
   2169 			tprintf("d_namlen=%u, d_name=\"%.*s\"}",
   2170 				d->d_namlen, d->d_namlen, d->d_name);
   2171 		}
   2172 #endif /* SUNOS4 */
   2173 		i += d->d_reclen;
   2174 		dents++;
   2175 	}
   2176 	if (!abbrev(tcp))
   2177 		tprintf("}");
   2178 	else
   2179 		tprintf("/* %u entries */", dents);
   2180 	tprintf(", %lu", tcp->u_arg[2]);
   2181 	free(buf);
   2182 	return 0;
   2183 }
   2184 #endif
   2185 
   2186 #ifdef FREEBSD
   2187 int
   2188 sys_getdirentries(tcp)
   2189 struct tcb * tcp;
   2190 {
   2191 	int i, len, dents = 0;
   2192 	long basep;
   2193 	char *buf;
   2194 
   2195 	if (entering(tcp)) {
   2196 		tprintf("%lu, ", tcp->u_arg[0]);
   2197 		return 0;
   2198 	}
   2199 	if (syserror(tcp) || !verbose(tcp)) {
   2200 		tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
   2201 		return 0;
   2202 	}
   2203 	len = tcp->u_rval;
   2204 	if ((buf = malloc(len)) == NULL) {
   2205 		tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
   2206 		fprintf(stderr, "out of memory\n");
   2207 		return 0;
   2208 	}
   2209 	if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
   2210 		tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
   2211 		free(buf);
   2212 		return 0;
   2213 	}
   2214 	if (!abbrev(tcp))
   2215 		tprintf("{");
   2216 	for (i = 0; i < len;) {
   2217 		struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
   2218 		if (!abbrev(tcp)) {
   2219 			tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
   2220 				i ? " " : "", d->d_fileno, d->d_reclen);
   2221 			printxval(direnttypes, d->d_type, "DT_???");
   2222 			tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
   2223 				d->d_namlen, d->d_namlen, d->d_name);
   2224 		}
   2225 		i += d->d_reclen;
   2226 		dents++;
   2227 	}
   2228 	if (!abbrev(tcp))
   2229 		tprintf("}");
   2230 	else
   2231 		tprintf("/* %u entries */", dents);
   2232 	free(buf);
   2233 	tprintf(", %lu", tcp->u_arg[2]);
   2234 	if (umove(tcp, tcp->u_arg[3], &basep) < 0)
   2235 		tprintf(", %#lx", tcp->u_arg[3]);
   2236 	else
   2237 		tprintf(", [%lu]", basep);
   2238 	return 0;
   2239 }
   2240 #endif
   2241 
   2242 #ifdef LINUX
   2243 int
   2244 sys_getcwd(tcp)
   2245 struct tcb *tcp;
   2246 {
   2247     if (exiting(tcp)) {
   2248 	if (syserror(tcp))
   2249 	    tprintf("%#lx", tcp->u_arg[0]);
   2250 	else
   2251 	    printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
   2252 	tprintf(", %lu", tcp->u_arg[1]);
   2253     }
   2254     return 0;
   2255 }
   2256 #endif /* LINUX */
   2257 
   2258 #ifdef FREEBSD
   2259 int
   2260 sys___getcwd(tcp)
   2261 struct tcb *tcp;
   2262 {
   2263     if (exiting(tcp)) {
   2264 	if (syserror(tcp))
   2265 	    tprintf("%#lx", tcp->u_arg[0]);
   2266 	else
   2267 	    printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
   2268 	tprintf(", %lu", tcp->u_arg[1]);
   2269     }
   2270     return 0;
   2271 }
   2272 #endif
   2273 
   2274 #ifdef HAVE_SYS_ASYNCH_H
   2275 
   2276 int
   2277 sys_aioread(tcp)
   2278 struct tcb *tcp;
   2279 {
   2280 	struct aio_result_t res;
   2281 
   2282 	if (entering(tcp)) {
   2283 		tprintf("%lu, ", tcp->u_arg[0]);
   2284 	} else {
   2285 		if (syserror(tcp))
   2286 			tprintf("%#lx", tcp->u_arg[1]);
   2287 		else
   2288 			printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
   2289 		tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
   2290 		printxval(whence, tcp->u_arg[4], "L_???");
   2291 		if (syserror(tcp) || tcp->u_arg[5] == 0
   2292 		    || umove(tcp, tcp->u_arg[5], &res) < 0)
   2293 			tprintf(", %#lx", tcp->u_arg[5]);
   2294 		else
   2295 			tprintf(", {aio_return %d aio_errno %d}",
   2296 				res.aio_return, res.aio_errno);
   2297 	}
   2298 	return 0;
   2299 }
   2300 
   2301 int
   2302 sys_aiowrite(tcp)
   2303 struct tcb *tcp;
   2304 {
   2305 	struct aio_result_t res;
   2306 
   2307 	if (entering(tcp)) {
   2308 		tprintf("%lu, ", tcp->u_arg[0]);
   2309 		printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
   2310 		tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
   2311 		printxval(whence, tcp->u_arg[4], "L_???");
   2312 	}
   2313 	else {
   2314 		if (tcp->u_arg[5] == 0)
   2315 			tprintf(", NULL");
   2316 		else if (syserror(tcp)
   2317 		    || umove(tcp, tcp->u_arg[5], &res) < 0)
   2318 			tprintf(", %#lx", tcp->u_arg[5]);
   2319 		else
   2320 			tprintf(", {aio_return %d aio_errno %d}",
   2321 				res.aio_return, res.aio_errno);
   2322 	}
   2323 	return 0;
   2324 }
   2325 
   2326 int
   2327 sys_aiowait(tcp)
   2328 struct tcb *tcp;
   2329 {
   2330 	if (entering(tcp))
   2331 		printtv(tcp, tcp->u_arg[0]);
   2332 	return 0;
   2333 }
   2334 
   2335 int
   2336 sys_aiocancel(tcp)
   2337 struct tcb *tcp;
   2338 {
   2339 	struct aio_result_t res;
   2340 
   2341 	if (exiting(tcp)) {
   2342 		if (tcp->u_arg[0] == 0)
   2343 			tprintf("NULL");
   2344 		else if (syserror(tcp)
   2345 		    || umove(tcp, tcp->u_arg[0], &res) < 0)
   2346 			tprintf("%#lx", tcp->u_arg[0]);
   2347 		else
   2348 			tprintf("{aio_return %d aio_errno %d}",
   2349 				res.aio_return, res.aio_errno);
   2350 	}
   2351 	return 0;
   2352 }
   2353 
   2354 #endif /* HAVE_SYS_ASYNCH_H */
   2355 
   2356 static const struct xlat xattrflags[] = {
   2357 #ifdef XATTR_CREATE
   2358 	{ XATTR_CREATE,	 "XATTR_CREATE" },
   2359 	{ XATTR_REPLACE, "XATTR_REPLACE" },
   2360 #endif
   2361 	{ 0,		 NULL }
   2362 };
   2363 
   2364 static void
   2365 print_xattr_val(tcp, failed, arg, insize, size)
   2366 struct tcb *tcp;
   2367 int failed;
   2368 unsigned long arg;
   2369 unsigned long insize, size;
   2370 {
   2371     if (!failed) {
   2372 	unsigned long capacity = 4 * size + 1;
   2373 	unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
   2374 	if (buf == NULL || /* probably a bogus size argument */
   2375 	    umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
   2376 	    failed = 1;
   2377 	}
   2378 	else {
   2379 	    unsigned char *out = buf;
   2380 	    unsigned char *in = &buf[3 * size];
   2381 	    size_t i;
   2382 	    for (i = 0; i < size; ++i)
   2383 		if (isprint(in[i]))
   2384 		    *out++ = in[i];
   2385 		else {
   2386 #define tohex(n) "0123456789abcdef"[n]
   2387 		    *out++ = '\\';
   2388 		    *out++ = 'x';
   2389 		    *out++ = tohex(in[i] / 16);
   2390 		    *out++ = tohex(in[i] % 16);
   2391 		}
   2392 	    /* Don't print terminating NUL if there is one.  */
   2393 	    if (in[i - 1] == '\0')
   2394 		out -= 4;
   2395 	    *out = '\0';
   2396 	    tprintf(", \"%s\", %ld", buf, insize);
   2397 	}
   2398 	free(buf);
   2399     }
   2400     if (failed)
   2401 	tprintf(", 0x%lx, %ld", arg, insize);
   2402 }
   2403 
   2404 int
   2405 sys_setxattr(tcp)
   2406 struct tcb *tcp;
   2407 {
   2408     if (entering(tcp)) {
   2409 	printpath(tcp, tcp->u_arg[0]);
   2410 	tprintf(", ");
   2411 	printstr(tcp, tcp->u_arg[1], -1);
   2412 	print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
   2413 	tprintf(", ");
   2414 	printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
   2415     }
   2416     return 0;
   2417 }
   2418 
   2419 int
   2420 sys_fsetxattr(tcp)
   2421 struct tcb *tcp;
   2422 {
   2423     if (entering(tcp)) {
   2424 	tprintf("%ld, ", tcp->u_arg[0]);
   2425 	printstr(tcp, tcp->u_arg[1], -1);
   2426 	print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
   2427 	tprintf(", ");
   2428 	printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
   2429     }
   2430     return 0;
   2431 }
   2432 
   2433 int
   2434 sys_getxattr(tcp)
   2435 struct tcb *tcp;
   2436 {
   2437     if (entering(tcp)) {
   2438 	printpath(tcp, tcp->u_arg[0]);
   2439 	tprintf(", ");
   2440 	printstr(tcp, tcp->u_arg[1], -1);
   2441     } else {
   2442 	print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
   2443 			tcp->u_rval);
   2444     }
   2445     return 0;
   2446 }
   2447 
   2448 int
   2449 sys_fgetxattr(tcp)
   2450 struct tcb *tcp;
   2451 {
   2452     if (entering(tcp)) {
   2453 	tprintf("%ld, ", tcp->u_arg[0]);
   2454 	printstr(tcp, tcp->u_arg[1], -1);
   2455     } else {
   2456 	print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
   2457 			tcp->u_rval);
   2458     }
   2459     return 0;
   2460 }
   2461 
   2462 int
   2463 sys_listxattr(tcp)
   2464 struct tcb *tcp;
   2465 {
   2466     if (entering(tcp)) {
   2467 	printpath(tcp, tcp->u_arg[0]);
   2468     } else {
   2469 	/* XXX Print value in format */
   2470 	tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
   2471     }
   2472     return 0;
   2473 }
   2474 
   2475 int
   2476 sys_flistxattr(tcp)
   2477 struct tcb *tcp;
   2478 {
   2479     if (entering(tcp)) {
   2480 	tprintf("%ld", tcp->u_arg[0]);
   2481     } else {
   2482 	/* XXX Print value in format */
   2483 	tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
   2484     }
   2485     return 0;
   2486 }
   2487 
   2488 int
   2489 sys_removexattr(tcp)
   2490 struct tcb *tcp;
   2491 {
   2492     if (entering(tcp)) {
   2493 	printpath(tcp, tcp->u_arg[0]);
   2494 	tprintf(", ");
   2495 	printstr(tcp, tcp->u_arg[1], -1);
   2496     }
   2497     return 0;
   2498 }
   2499 
   2500 int
   2501 sys_fremovexattr(tcp)
   2502 struct tcb *tcp;
   2503 {
   2504     if (entering(tcp)) {
   2505 	tprintf("%ld, ", tcp->u_arg[0]);
   2506 	printstr(tcp, tcp->u_arg[1], -1);
   2507     }
   2508     return 0;
   2509 }
   2510 
   2511 static const struct xlat advise[] = {
   2512   { POSIX_FADV_NORMAL,		"POSIX_FADV_NORMAL"	},
   2513   { POSIX_FADV_RANDOM,		"POSIX_FADV_RANDOM"	},
   2514   { POSIX_FADV_SEQUENTIAL,	"POSIX_FADV_SEQUENTIAL"	},
   2515   { POSIX_FADV_WILLNEED,	"POSIX_FADV_WILLNEED"	},
   2516   { POSIX_FADV_DONTNEED,	"POSIX_FADV_DONTNEED"	},
   2517   { POSIX_FADV_NOREUSE,		"POSIX_FADV_NOREUSE"	},
   2518   { 0,				NULL			}
   2519 };
   2520 
   2521 
   2522 #ifdef LINUX
   2523 int
   2524 sys_fadvise64(tcp)
   2525 struct tcb *tcp;
   2526 {
   2527     if (entering(tcp)) {
   2528 	tprintf("%ld, %lld, %ld, ",
   2529 		tcp->u_arg[0],
   2530 # if defined IA64 || defined X86_64 || defined ALPHA
   2531 		(long long int) tcp->u_arg[1], tcp->u_arg[2]);
   2532 	printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
   2533 #else
   2534 		LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
   2535 	printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
   2536 #endif
   2537     }
   2538     return 0;
   2539 }
   2540 #endif
   2541 
   2542 
   2543 int
   2544 sys_fadvise64_64(tcp)
   2545 struct tcb *tcp;
   2546 {
   2547     if (entering(tcp)) {
   2548 	tprintf("%ld, %lld, %lld, ",
   2549 		tcp->u_arg[0],
   2550 # if defined IA64 || defined X86_64 || defined ALPHA
   2551 		(long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
   2552 	printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
   2553 #else
   2554 		LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
   2555 		LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
   2556 	printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
   2557 #endif
   2558     }
   2559     return 0;
   2560 }
   2561 
   2562 //#endif /*HAVE_ANDROID_OS */
   2563