blob: bfb12ca30a3cfdb528690e8909f6d70e408ba275 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
John Hughese2f6d872001-03-07 16:03:20 +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>
Wichert Akkerman9524bb91999-05-25 23:11:18 +000037#ifdef linux
38#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
43#else
44#define kernel_dirent dirent
45#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000046
Wichert Akkerman8bc6cfd1999-04-21 15:57:38 +000047#ifdef linux
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000048# ifdef LINUXSPARC
49struct stat {
50 unsigned short st_dev;
51 unsigned int st_ino;
52 unsigned short st_mode;
53 short st_nlink;
54 unsigned short st_uid;
55 unsigned short st_gid;
56 unsigned short st_rdev;
57 unsigned int st_size;
58 int st_atime;
59 unsigned int __unused1;
60 int st_mtime;
61 unsigned int __unused2;
62 int st_ctime;
63 unsigned int __unused3;
64 int st_blksize;
65 int st_blocks;
66 unsigned int __unused4[2];
67};
68# define stat kernel_stat
69# include <asm/stat.h>
70# undef stat
71# else
Wichert Akkerman5b4d1281999-07-09 00:32:54 +000072# undef dev_t
73# undef ino_t
74# undef mode_t
75# undef nlink_t
76# undef uid_t
77# undef gid_t
78# undef off_t
79# undef loff_t
80
Wichert Akkermana6013701999-07-08 14:00:58 +000081# define dev_t __kernel_dev_t
82# define ino_t __kernel_ino_t
83# define mode_t __kernel_mode_t
84# define nlink_t __kernel_nlink_t
85# define uid_t __kernel_uid_t
86# define gid_t __kernel_gid_t
87# define off_t __kernel_off_t
88# define loff_t __kernel_loff_t
89
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000090# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +000091
92# undef dev_t
93# undef ino_t
94# undef mode_t
95# undef nlink_t
96# undef uid_t
97# undef gid_t
98# undef off_t
99# undef loff_t
Wichert Akkerman5b4d1281999-07-09 00:32:54 +0000100
101# define dev_t dev_t
102# define ino_t ino_t
103# define mode_t mode_t
104# define nlink_t nlink_t
105# define uid_t uid_t
106# define gid_t gid_t
107# define off_t off_t
108# define loff_t loff_t
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000109# endif
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000110# ifdef HPPA /* asm-parisc/stat.h defines stat64 */
111# undef stat64
112# endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000113# define stat libc_stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000114# define stat64 libc_stat64
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000115# include <sys/stat.h>
116# undef stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000117# undef stat64
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000118# ifdef HPPA
119# define stat64 hpux_stat64
120# endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000121#else
122# include <sys/stat.h>
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000123#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000124
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000125#include <fcntl.h>
126
127#ifdef SVR4
128# include <sys/cred.h>
129#endif /* SVR4 */
130
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000131#ifdef HAVE_SYS_VFS_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000132#include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000133#endif
134
135#ifdef FREEBSD
136#include <sys/param.h>
137#include <sys/mount.h>
138#include <sys/stat.h>
John Hughes70623be2001-03-08 13:59:00 +0000139#endif
140
141#if HAVE_LONG_LONG_OFF_T
142/*
143 * Ugly hacks for systems that have typedef long long off_t
144 */
John Hughesb8c9f772001-03-07 16:53:07 +0000145
146#define stat64 stat
147#define HAVE_STAT64 1 /* Ugly hack */
John Hughes70623be2001-03-08 13:59:00 +0000148
149#define sys_stat64 sys_stat
150#define sys_fstat64 sys_fstat
151#define sys_lstat64 sys_lstat
152#define sys_lseek64 sys_lseek
153#define sys_truncate64 sys_truncate
154#define sys_ftruncate64 sys_ftruncate
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000155#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000156
157#ifdef MAJOR_IN_SYSMACROS
158#include <sys/sysmacros.h>
159#endif
160
161#ifdef MAJOR_IN_MKDEV
162#include <sys/mkdev.h>
163#endif
164
165#ifdef HAVE_SYS_ASYNCH_H
166#include <sys/asynch.h>
167#endif
168
169#ifdef SUNOS4
170#include <ustat.h>
171#endif
172
173/*
174 * This is a really dirty trick but it should always work. Traditional
175 * Unix says r/w/rw are 0/1/2, so we make them true flags 1/2/3 by
176 * adding 1. Just remember to add 1 to any arg decoded with openmodes.
177 */
178struct xlat openmodes[] = {
179 { O_RDWR+1, "O_RDWR" },
180 { O_RDONLY+1, "O_RDONLY" },
181 { O_WRONLY+1, "O_WRONLY" },
182 { O_NONBLOCK, "O_NONBLOCK" },
183 { O_APPEND, "O_APPEND" },
184 { O_CREAT, "O_CREAT" },
185 { O_TRUNC, "O_TRUNC" },
186 { O_EXCL, "O_EXCL" },
187 { O_NOCTTY, "O_NOCTTY" },
188#ifdef O_SYNC
189 { O_SYNC, "O_SYNC" },
190#endif
191#ifdef O_ASYNC
192 { O_ASYNC, "O_ASYNC" },
193#endif
194#ifdef O_DSYNC
195 { O_DSYNC, "O_DSYNC" },
196#endif
197#ifdef O_RSYNC
198 { O_RSYNC, "O_RSYNC" },
199#endif
200#ifdef O_NDELAY
201 { O_NDELAY, "O_NDELAY" },
202#endif
203#ifdef O_PRIV
204 { O_PRIV, "O_PRIV" },
205#endif
206#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000207 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000208#endif
209#ifdef O_LARGEFILE
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000210 { O_LARGEFILE, "O_LARGEFILE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000211#endif
212#ifdef O_DIRECTORY
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000213 { O_DIRECTORY, "O_DIRECTORY" },
214#endif
215#ifdef O_NOFOLLOW
216 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000217#endif
218
219#ifdef FNDELAY
220 { FNDELAY, "FNDELAY" },
221#endif
222#ifdef FAPPEND
223 { FAPPEND, "FAPPEND" },
224#endif
225#ifdef FMARK
226 { FMARK, "FMARK" },
227#endif
228#ifdef FDEFER
229 { FDEFER, "FDEFER" },
230#endif
231#ifdef FASYNC
232 { FASYNC, "FASYNC" },
233#endif
234#ifdef FSHLOCK
235 { FSHLOCK, "FSHLOCK" },
236#endif
237#ifdef FEXLOCK
238 { FEXLOCK, "FEXLOCK" },
239#endif
240#ifdef FCREAT
241 { FCREAT, "FCREAT" },
242#endif
243#ifdef FTRUNC
244 { FTRUNC, "FTRUNC" },
245#endif
246#ifdef FEXCL
247 { FEXCL, "FEXCL" },
248#endif
249#ifdef FNBIO
250 { FNBIO, "FNBIO" },
251#endif
252#ifdef FSYNC
253 { FSYNC, "FSYNC" },
254#endif
255#ifdef FNOCTTY
256 { FNOCTTY, "FNOCTTY" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000257#endif
258#ifdef O_SHLOCK
259 { O_SHLOCK, "O_SHLOCK" },
260#endif
261#ifdef O_EXLOCK
262 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000263#endif
264 { 0, NULL },
265};
266
267int
268sys_open(tcp)
269struct tcb *tcp;
270{
271 if (entering(tcp)) {
272 printpath(tcp, tcp->u_arg[0]);
273 tprintf(", ");
274 /* flags */
275 printflags(openmodes, tcp->u_arg[1] + 1);
276 if (tcp->u_arg[1] & O_CREAT) {
277 /* mode */
278 tprintf(", %#lo", tcp->u_arg[2]);
279 }
280 }
281 return 0;
282}
283
284#ifdef LINUXSPARC
285struct xlat openmodessol[] = {
286 { 0, "O_RDWR" },
287 { 1, "O_RDONLY" },
288 { 2, "O_WRONLY" },
289 { 0x80, "O_NONBLOCK" },
290 { 8, "O_APPEND" },
291 { 0x100, "O_CREAT" },
292 { 0x200, "O_TRUNC" },
293 { 0x400, "O_EXCL" },
294 { 0x800, "O_NOCTTY" },
295 { 0x10, "O_SYNC" },
296 { 0x40, "O_DSYNC" },
297 { 0x8000, "O_RSYNC" },
298 { 4, "O_NDELAY" },
299 { 0x1000, "O_PRIV" },
300 { 0, NULL },
301};
302
303int
304solaris_open(tcp)
305struct tcb *tcp;
306{
307 if (entering(tcp)) {
308 printpath(tcp, tcp->u_arg[0]);
309 tprintf(", ");
310 /* flags */
311 printflags(openmodessol, tcp->u_arg[1] + 1);
312 if (tcp->u_arg[1] & 0x100) {
313 /* mode */
314 tprintf(", %#lo", tcp->u_arg[2]);
315 }
316 }
317 return 0;
318}
319
320#endif
321
322int
323sys_creat(tcp)
324struct tcb *tcp;
325{
326 if (entering(tcp)) {
327 printpath(tcp, tcp->u_arg[0]);
328 tprintf(", %#lo", tcp->u_arg[1]);
329 }
330 return 0;
331}
332
333static struct xlat access_flags[] = {
334 { F_OK, "F_OK", },
335 { R_OK, "R_OK" },
336 { W_OK, "W_OK" },
337 { X_OK, "X_OK" },
338#ifdef EFF_ONLY_OK
339 { EFF_ONLY_OK, "EFF_ONLY_OK" },
340#endif
341#ifdef EX_OK
342 { EX_OK, "EX_OK" },
343#endif
344 { 0, NULL },
345};
346
347int
348sys_access(tcp)
349struct tcb *tcp;
350{
351 if (entering(tcp)) {
352 printpath(tcp, tcp->u_arg[0]);
353 tprintf(", ");
354 printflags(access_flags, tcp->u_arg[1]);
355 }
356 return 0;
357}
358
359int
360sys_umask(tcp)
361struct tcb *tcp;
362{
363 if (entering(tcp)) {
364 tprintf("%#lo", tcp->u_arg[0]);
365 }
366 return RVAL_OCTAL;
367}
368
369static struct xlat whence[] = {
370 { SEEK_SET, "SEEK_SET" },
371 { SEEK_CUR, "SEEK_CUR" },
372 { SEEK_END, "SEEK_END" },
373 { 0, NULL },
374};
375
John Hughes70623be2001-03-08 13:59:00 +0000376#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000377int
378sys_lseek(tcp)
379struct tcb *tcp;
380{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000381 off_t offset;
382 int _whence;
383
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000384 if (entering(tcp)) {
385 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000386 offset = tcp->u_arg[1];
387 _whence = tcp->u_arg[2];
388 if (_whence == SEEK_SET)
389 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000390 else
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000391 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000392 printxval(whence, _whence, "SEEK_???");
393 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000394 return RVAL_UDECIMAL;
395}
John Hughes5a826b82001-03-07 13:21:24 +0000396#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000397
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000398#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000399int
400sys_llseek (tcp)
401struct tcb *tcp;
402{
403 if (entering(tcp)) {
404 if (tcp->u_arg[4] == SEEK_SET)
405 tprintf("%ld, %llu, ", tcp->u_arg[0],
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000406 (((long long int) tcp->u_arg[1]) << 32
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000407 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000408 else
409 tprintf("%ld, %lld, ", tcp->u_arg[0],
410 (((long long int) tcp->u_arg[1]) << 32
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000411 | (unsigned long long) (unsigned) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000412 }
413 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000414 long long int off;
415 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000416 tprintf("%#lx, ", tcp->u_arg[3]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000417 else
418 tprintf("[%llu], ", off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000419 printxval(whence, tcp->u_arg[4], "SEEK_???");
420 }
421 return 0;
422}
423#endif
424
John Hughes70623be2001-03-08 13:59:00 +0000425#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000426int
427sys_lseek64 (tcp)
428struct tcb *tcp;
429{
430 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000431 long long offset;
432 ALIGN64 (tcp, 1); /* FreeBSD aligns off_t args */
John Hughes0c79e012001-03-08 14:40:06 +0000433 offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +0000434 if (tcp->u_arg[3] == SEEK_SET)
435 tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
436 else
437 tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
438 printxval(whence, tcp->u_arg[3], "SEEK_???");
439 }
440 return RVAL_LUDECIMAL;
441}
442#endif
443
John Hughes70623be2001-03-08 13:59:00 +0000444#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000445int
446sys_truncate(tcp)
447struct tcb *tcp;
448{
449 if (entering(tcp)) {
450 printpath(tcp, tcp->u_arg[0]);
451 tprintf(", %lu", tcp->u_arg[1]);
452 }
453 return 0;
454}
John Hughes5a826b82001-03-07 13:21:24 +0000455#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000456
John Hughes70623be2001-03-08 13:59:00 +0000457#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000458int
459sys_truncate64(tcp)
460struct tcb *tcp;
461{
462 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000463 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000464 printpath(tcp, tcp->u_arg[0]);
John Hughes0c79e012001-03-08 14:40:06 +0000465 tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000466 }
467 return 0;
468}
469#endif
470
John Hughes70623be2001-03-08 13:59:00 +0000471#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000472int
473sys_ftruncate(tcp)
474struct tcb *tcp;
475{
476 if (entering(tcp)) {
477 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
478 }
479 return 0;
480}
John Hughes5a826b82001-03-07 13:21:24 +0000481#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000482
John Hughes70623be2001-03-08 13:59:00 +0000483#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000484int
485sys_ftruncate64(tcp)
486struct tcb *tcp;
487{
488 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000489 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000490 tprintf("%ld, %llu", tcp->u_arg[0],
John Hughes0c79e012001-03-08 14:40:06 +0000491 LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000492 }
493 return 0;
494}
495#endif
496
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000497/* several stats */
498
499static struct xlat modetypes[] = {
500 { S_IFREG, "S_IFREG" },
501 { S_IFSOCK, "S_IFSOCK" },
502 { S_IFIFO, "S_IFIFO" },
503 { S_IFLNK, "S_IFLNK" },
504 { S_IFDIR, "S_IFDIR" },
505 { S_IFBLK, "S_IFBLK" },
506 { S_IFCHR, "S_IFCHR" },
507 { 0, NULL },
508};
509
510static char *
511sprintmode(mode)
512int mode;
513{
514 static char buf[64];
515 char *s;
516
517 if ((mode & S_IFMT) == 0)
518 s = "";
519 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
520 sprintf(buf, "%#o", mode);
521 return buf;
522 }
523 sprintf(buf, "%s%s%s%s", s,
524 (mode & S_ISUID) ? "|S_ISUID" : "",
525 (mode & S_ISGID) ? "|S_ISGID" : "",
526 (mode & S_ISVTX) ? "|S_ISVTX" : "");
527 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
528 if (mode)
529 sprintf(buf + strlen(buf), "|%#o", mode);
530 s = (*buf == '|') ? buf + 1 : buf;
531 return *s ? s : "0";
532}
533
534static char *
535sprinttime(t)
536time_t t;
537{
538 struct tm *tmp;
539 static char buf[32];
540
541 if (t == 0) {
542 sprintf(buf, "0");
543 return buf;
544 }
545 tmp = localtime(&t);
546 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
Wichert Akkerman3ed6dc22000-01-11 14:41:09 +0000547 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000548 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
549 return buf;
550}
551
552#ifdef LINUXSPARC
553typedef struct {
554 int tv_sec;
555 int tv_nsec;
556} timestruct_t;
557
558struct solstat {
559 unsigned st_dev;
560 int st_pad1[3]; /* network id */
561 unsigned st_ino;
562 unsigned st_mode;
563 unsigned st_nlink;
564 unsigned st_uid;
565 unsigned st_gid;
566 unsigned st_rdev;
567 int st_pad2[2];
568 int st_size;
569 int st_pad3; /* st_size, off_t expansion */
570 timestruct_t st_atime;
571 timestruct_t st_mtime;
572 timestruct_t st_ctime;
573 int st_blksize;
574 int st_blocks;
575 char st_fstype[16];
576 int st_pad4[8]; /* expansion area */
577};
578
579static void
580printstatsol(tcp, addr)
581struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000582long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000583{
584 struct solstat statbuf;
585
586 if (!addr) {
587 tprintf("NULL");
588 return;
589 }
590 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000591 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000592 return;
593 }
594 if (umove(tcp, addr, &statbuf) < 0) {
595 tprintf("{...}");
596 return;
597 }
598 if (!abbrev(tcp)) {
599 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
600 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
601 (unsigned long) (statbuf.st_dev & 0x3ffff),
602 (unsigned long) statbuf.st_ino,
603 sprintmode(statbuf.st_mode));
604 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
605 (unsigned long) statbuf.st_nlink,
606 (unsigned long) statbuf.st_uid,
607 (unsigned long) statbuf.st_gid);
608 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
609 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
610 }
611 else
612 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
613 switch (statbuf.st_mode & S_IFMT) {
614 case S_IFCHR: case S_IFBLK:
615 tprintf("st_rdev=makedev(%lu, %lu), ",
616 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
617 (unsigned long) (statbuf.st_rdev & 0x3ffff));
618 break;
619 default:
620 tprintf("st_size=%u, ", statbuf.st_size);
621 break;
622 }
623 if (!abbrev(tcp)) {
624 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
625 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
626 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
627 }
628 else
629 tprintf("...}");
630}
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000631#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000632
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000633static struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000634#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000635 { UF_NODUMP, "UF_NODUMP" },
636 { UF_IMMUTABLE, "UF_IMMUTABLE" },
637 { UF_APPEND, "UF_APPEND" },
638 { UF_OPAQUE, "UF_OPAQUE" },
639 { UF_NOUNLINK, "UF_NOUNLINK" },
640 { SF_ARCHIVED, "SF_ARCHIVED" },
641 { SF_IMMUTABLE, "SF_IMMUTABLE" },
642 { SF_APPEND, "SF_APPEND" },
643 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000644#elif UNIXWARE >= 2
645#ifdef _S_ISMLD
646 { _S_ISMLD, "_S_ISMLD" },
647#endif
648#ifdef _S_ISMOUNTED
649 { _S_ISMOUNTED, "_S_ISMOUNTED" },
650#endif
651#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000652 { 0, NULL },
653};
654
John Hughesc0fc3fd2001-03-08 16:10:40 +0000655#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000656int
657sys_chflags(tcp)
658struct tcb *tcp;
659{
660 if (entering(tcp)) {
661 printpath(tcp, tcp->u_arg[0]);
662 tprintf(", ");
663 if (tcp->u_arg[1])
664 printflags(fileflags, tcp->u_arg[1]);
665 else
666 tprintf("0");
667 }
668 return 0;
669}
670
671int
672sys_fchflags(tcp)
673struct tcb *tcp;
674{
675 if (entering(tcp)) {
676 tprintf("%ld, ", tcp->u_arg[0]);
677 if (tcp->u_arg[1])
678 printflags(fileflags, tcp->u_arg[1]);
679 else
680 tprintf("0");
681 }
682 return 0;
683}
684#endif
685
John Hughes70623be2001-03-08 13:59:00 +0000686#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000687static void
688realprintstat(tcp, statbuf)
689struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000690struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000691{
692 if (!abbrev(tcp)) {
693 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
694 (unsigned long) major(statbuf->st_dev),
695 (unsigned long) minor(statbuf->st_dev),
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#ifdef HAVE_ST_BLKSIZE
703 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
704#endif /* HAVE_ST_BLKSIZE */
705#ifdef HAVE_ST_BLOCKS
706 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
707#endif /* HAVE_ST_BLOCKS */
708 }
709 else
710 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
711 switch (statbuf->st_mode & S_IFMT) {
712 case S_IFCHR: case S_IFBLK:
713#ifdef HAVE_ST_RDEV
714 tprintf("st_rdev=makedev(%lu, %lu), ",
715 (unsigned long) major(statbuf->st_rdev),
716 (unsigned long) minor(statbuf->st_rdev));
717#else /* !HAVE_ST_RDEV */
718 tprintf("st_size=makedev(%lu, %lu), ",
719 (unsigned long) major(statbuf->st_size),
720 (unsigned long) minor(statbuf->st_size));
721#endif /* !HAVE_ST_RDEV */
722 break;
723 default:
724 tprintf("st_size=%lu, ", statbuf->st_size);
725 break;
726 }
727 if (!abbrev(tcp)) {
728 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
729 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000730 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
731#if HAVE_ST_FLAGS
732 tprintf(", st_flags=");
733 if (statbuf->st_flags) {
734 printflags(fileflags, statbuf->st_flags);
735 } else
736 tprintf("0");
737#endif
738#if HAVE_ST_ACLCNT
739 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
740#endif
741#if HAVE_ST_LEVEL
742 tprintf(", st_level=%ld", statbuf->st_level);
743#endif
744#if HAVE_ST_FSTYPE
745 tprintf(", st_fstype=%.*s",
746 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
747#endif
748#if HAVE_ST_GEN
749 tprintf(", st_gen=%u", statbuf->st_gen);
750#endif
751 tprintf("}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000752 }
753 else
754 tprintf("...}");
755}
756
Nate Sammons771a6ff1999-04-05 22:39:31 +0000757
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000758static void
759printstat(tcp, addr)
760struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000761long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000762{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000763 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000764
765#ifdef LINUXSPARC
766 if (current_personality == 1) {
767 printstatsol(tcp, addr);
768 return;
769 }
770#endif /* LINUXSPARC */
771
772 if (!addr) {
773 tprintf("NULL");
774 return;
775 }
776 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000777 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000778 return;
779 }
780 if (umove(tcp, addr, &statbuf) < 0) {
781 tprintf("{...}");
782 return;
783 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000784
785 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000786}
John Hughes70623be2001-03-08 13:59:00 +0000787#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000788
Wichert Akkermanc7926982000-04-10 22:22:31 +0000789#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000790static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000791printstat64(tcp, addr)
792struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000793long addr;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000794{
795 struct stat64 statbuf;
796
797#ifdef LINUXSPARC
798 if (current_personality == 1) {
799 printstatsol(tcp, addr);
800 return;
801 }
802#endif /* LINUXSPARC */
803
804 if (!addr) {
805 tprintf("NULL");
806 return;
807 }
808 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000809 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000810 return;
811 }
812 if (umove(tcp, addr, &statbuf) < 0) {
813 tprintf("{...}");
814 return;
815 }
816
817 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +0000818#ifdef HAVE_LONG_LONG
819 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
820#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000821 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +0000822#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000823 (unsigned long) major(statbuf.st_dev),
824 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +0000825#ifdef HAVE_LONG_LONG
826 (unsigned long long) statbuf.st_ino,
827#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000828 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +0000829#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000830 sprintmode(statbuf.st_mode));
831 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
832 (unsigned long) statbuf.st_nlink,
833 (unsigned long) statbuf.st_uid,
834 (unsigned long) statbuf.st_gid);
835#ifdef HAVE_ST_BLKSIZE
836 tprintf("st_blksize=%lu, ",
837 (unsigned long) statbuf.st_blksize);
838#endif /* HAVE_ST_BLKSIZE */
839#ifdef HAVE_ST_BLOCKS
840 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
841#endif /* HAVE_ST_BLOCKS */
842 }
843 else
844 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
845 switch (statbuf.st_mode & S_IFMT) {
846 case S_IFCHR: case S_IFBLK:
847#ifdef HAVE_ST_RDEV
848 tprintf("st_rdev=makedev(%lu, %lu), ",
849 (unsigned long) major(statbuf.st_rdev),
850 (unsigned long) minor(statbuf.st_rdev));
851#else /* !HAVE_ST_RDEV */
852 tprintf("st_size=makedev(%lu, %lu), ",
853 (unsigned long) major(statbuf.st_size),
854 (unsigned long) minor(statbuf.st_size));
855#endif /* !HAVE_ST_RDEV */
856 break;
857 default:
858 tprintf("st_size=%llu, ", statbuf.st_size);
859 break;
860 }
861 if (!abbrev(tcp)) {
862 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
863 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000864 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
865#if HAVE_ST_FLAGS
866 tprintf(", st_flags=");
John Hughesb8c9f772001-03-07 16:53:07 +0000867 if (statbuf.st_flags) {
868 printflags(fileflags, statbuf.st_flags);
869 } else
870 tprintf("0");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000871#endif
872#if HAVE_ST_ACLCNT
873 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
874#endif
875#if HAVE_ST_LEVEL
876 tprintf(", st_level=%ld", statbuf.st_level);
877#endif
878#if HAVE_ST_FSTYPE
879 tprintf(", st_fstype=%.*s",
880 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
881#endif
882#if HAVE_ST_GEN
883 tprintf(", st_gen=%u", statbuf.st_gen);
884#endif
885 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000886 }
887 else
888 tprintf("...}");
889}
Wichert Akkermanc7926982000-04-10 22:22:31 +0000890#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000891
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000892#if defined(linux) && !defined(IA64) && !defined(HPPA)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000893static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000894convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000895const struct __old_kernel_stat *oldbuf;
896struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000897{
898 newbuf->st_dev=oldbuf->st_dev;
899 newbuf->st_ino=oldbuf->st_ino;
900 newbuf->st_mode=oldbuf->st_mode;
901 newbuf->st_nlink=oldbuf->st_nlink;
902 newbuf->st_uid=oldbuf->st_uid;
903 newbuf->st_gid=oldbuf->st_gid;
904 newbuf->st_rdev=oldbuf->st_rdev;
905 newbuf->st_size=oldbuf->st_size;
906 newbuf->st_atime=oldbuf->st_atime;
907 newbuf->st_mtime=oldbuf->st_mtime;
908 newbuf->st_ctime=oldbuf->st_ctime;
909 newbuf->st_blksize=0; /* not supported in old_stat */
910 newbuf->st_blocks=0; /* not supported in old_stat */
911}
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000912
913
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000914static void
915printoldstat(tcp, addr)
916struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000917long addr;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000918{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000919 struct __old_kernel_stat statbuf;
920 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000921
922#ifdef LINUXSPARC
923 if (current_personality == 1) {
924 printstatsol(tcp, addr);
925 return;
926 }
927#endif /* LINUXSPARC */
928
929 if (!addr) {
930 tprintf("NULL");
931 return;
932 }
933 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000934 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000935 return;
936 }
937 if (umove(tcp, addr, &statbuf) < 0) {
938 tprintf("{...}");
939 return;
940 }
941
942 convertoldstat(&statbuf, &newstatbuf);
943 realprintstat(tcp, &newstatbuf);
944}
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000945#endif /* linux && !IA64 */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000946
John Hughes70623be2001-03-08 13:59:00 +0000947#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000948int
949sys_stat(tcp)
950struct tcb *tcp;
951{
952 if (entering(tcp)) {
953 printpath(tcp, tcp->u_arg[0]);
954 tprintf(", ");
955 } else {
956 printstat(tcp, tcp->u_arg[1]);
957 }
958 return 0;
959}
John Hughesb8c9f772001-03-07 16:53:07 +0000960#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000961
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000962int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000963sys_stat64(tcp)
964struct tcb *tcp;
965{
966#ifdef HAVE_STAT64
967 if (entering(tcp)) {
968 printpath(tcp, tcp->u_arg[0]);
969 tprintf(", ");
970 } else {
971 printstat64(tcp, tcp->u_arg[1]);
972 }
973 return 0;
974#else
975 return printargs(tcp);
976#endif
977}
978
John Hughese2f6d872001-03-07 16:03:20 +0000979#ifdef linux
Wichert Akkermanc1652e22001-03-27 12:17:16 +0000980# if !defined(IA64) && !defined(HPPA)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000981int
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000982sys_oldstat(tcp)
983struct tcb *tcp;
984{
985 if (entering(tcp)) {
986 printpath(tcp, tcp->u_arg[0]);
987 tprintf(", ");
988 } else {
989 printoldstat(tcp, tcp->u_arg[1]);
990 }
991 return 0;
992}
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000993# endif /* !IA64 && !HPPA*/
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000994#endif /* linux */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000995
John Hughes70623be2001-03-08 13:59:00 +0000996#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000997int
998sys_fstat(tcp)
999struct tcb *tcp;
1000{
1001 if (entering(tcp))
1002 tprintf("%ld, ", tcp->u_arg[0]);
1003 else {
1004 printstat(tcp, tcp->u_arg[1]);
1005 }
1006 return 0;
1007}
John Hughesb8c9f772001-03-07 16:53:07 +00001008#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001009
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001010int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001011sys_fstat64(tcp)
1012struct tcb *tcp;
1013{
1014#ifdef HAVE_STAT64
1015 if (entering(tcp))
1016 tprintf("%ld, ", tcp->u_arg[0]);
1017 else {
1018 printstat64(tcp, tcp->u_arg[1]);
1019 }
1020 return 0;
1021#else
1022 return printargs(tcp);
1023#endif
1024}
1025
John Hughese2f6d872001-03-07 16:03:20 +00001026#ifdef linux
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001027# if !defined(IA64) && !defined(HPPA)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001028int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001029sys_oldfstat(tcp)
1030struct tcb *tcp;
1031{
1032 if (entering(tcp))
1033 tprintf("%ld, ", tcp->u_arg[0]);
1034 else {
1035 printoldstat(tcp, tcp->u_arg[1]);
1036 }
1037 return 0;
1038}
Wichert Akkerman7b3346b2001-10-09 23:47:38 +00001039# endif /* !IA64 && !HPPA*/
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001040#endif
1041
John Hughes70623be2001-03-08 13:59:00 +00001042#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001043int
1044sys_lstat(tcp)
1045struct tcb *tcp;
1046{
1047 if (entering(tcp)) {
1048 printpath(tcp, tcp->u_arg[0]);
1049 tprintf(", ");
1050 } else {
1051 printstat(tcp, tcp->u_arg[1]);
1052 }
1053 return 0;
1054}
John Hughesb8c9f772001-03-07 16:53:07 +00001055#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001056
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001057int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001058sys_lstat64(tcp)
1059struct tcb *tcp;
1060{
1061#ifdef HAVE_STAT64
1062 if (entering(tcp)) {
1063 printpath(tcp, tcp->u_arg[0]);
1064 tprintf(", ");
1065 } else {
1066 printstat64(tcp, tcp->u_arg[1]);
1067 }
1068 return 0;
1069#else
1070 return printargs(tcp);
1071#endif
1072}
1073
John Hughese2f6d872001-03-07 16:03:20 +00001074#ifdef linux
Wichert Akkermanc1652e22001-03-27 12:17:16 +00001075# if !defined(IA64) && !defined(HPPA)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001076int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001077sys_oldlstat(tcp)
1078struct tcb *tcp;
1079{
1080 if (entering(tcp)) {
1081 printpath(tcp, tcp->u_arg[0]);
1082 tprintf(", ");
1083 } else {
1084 printoldstat(tcp, tcp->u_arg[1]);
1085 }
1086 return 0;
1087}
Wichert Akkerman7b3346b2001-10-09 23:47:38 +00001088# endif /* !IA64 && !HPPA */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001089#endif
1090
1091
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001092#if defined(SVR4) || defined(LINUXSPARC)
1093
1094int
1095sys_xstat(tcp)
1096struct tcb *tcp;
1097{
1098 if (entering(tcp)) {
1099 tprintf("%ld, ", tcp->u_arg[0]);
1100 printpath(tcp, tcp->u_arg[1]);
1101 tprintf(", ");
1102 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001103#ifdef _STAT64_VER
1104 if (tcp->u_arg[0] == _STAT64_VER)
1105 printstat64 (tcp, tcp->u_arg[2]);
1106 else
1107#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001108 printstat(tcp, tcp->u_arg[2]);
1109 }
1110 return 0;
1111}
1112
1113int
1114sys_fxstat(tcp)
1115struct tcb *tcp;
1116{
1117 if (entering(tcp))
1118 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1119 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001120#ifdef _STAT64_VER
1121 if (tcp->u_arg[0] == _STAT64_VER)
1122 printstat64 (tcp, tcp->u_arg[2]);
1123 else
1124#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001125 printstat(tcp, tcp->u_arg[2]);
1126 }
1127 return 0;
1128}
1129
1130int
1131sys_lxstat(tcp)
1132struct tcb *tcp;
1133{
1134 if (entering(tcp)) {
1135 tprintf("%ld, ", tcp->u_arg[0]);
1136 printpath(tcp, tcp->u_arg[1]);
1137 tprintf(", ");
1138 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001139#ifdef _STAT64_VER
1140 if (tcp->u_arg[0] == _STAT64_VER)
1141 printstat64 (tcp, tcp->u_arg[2]);
1142 else
1143#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001144 printstat(tcp, tcp->u_arg[2]);
1145 }
1146 return 0;
1147}
1148
1149int
1150sys_xmknod(tcp)
1151struct tcb *tcp;
1152{
1153 int mode = tcp->u_arg[2];
1154
1155 if (entering(tcp)) {
1156 tprintf("%ld, ", tcp->u_arg[0]);
1157 printpath(tcp, tcp->u_arg[1]);
1158 tprintf(", %s", sprintmode(mode));
1159 switch (mode & S_IFMT) {
1160 case S_IFCHR: case S_IFBLK:
1161#ifdef LINUXSPARC
1162 tprintf(", makedev(%lu, %lu)",
1163 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1164 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1165#else
1166 tprintf(", makedev(%lu, %lu)",
1167 (unsigned long) major(tcp->u_arg[3]),
1168 (unsigned long) minor(tcp->u_arg[3]));
1169#endif
1170 break;
1171 default:
1172 break;
1173 }
1174 }
1175 return 0;
1176}
1177
Wichert Akkerman8829a551999-06-11 13:18:40 +00001178#ifdef HAVE_SYS_ACL_H
1179
1180#include <sys/acl.h>
1181
1182struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001183#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001184 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001185#endif
1186#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001187 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001188#endif
1189#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001190 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001191#endif
1192#ifdef ACL_GET
1193 { ACL_GET, "ACL_GET" },
1194#endif
1195#ifdef ACL_SET
1196 { ACL_SET, "ACL_SET" },
1197#endif
1198#ifdef ACL_CNT
1199 { ACL_CNT, "ACL_CNT" },
1200#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001201 { 0, NULL },
1202};
1203
1204int
1205sys_acl(tcp)
1206struct tcb *tcp;
1207{
1208 if (entering(tcp)) {
1209 printpath(tcp, tcp->u_arg[0]);
1210 tprintf(", ");
1211 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1212 tprintf(", %ld", tcp->u_arg[2]);
1213 /*
1214 * FIXME - dump out the list of aclent_t's pointed to
1215 * by "tcp->u_arg[3]" if it's not NULL.
1216 */
1217 if (tcp->u_arg[3])
1218 tprintf(", %#lx", tcp->u_arg[3]);
1219 else
1220 tprintf(", NULL");
1221 }
1222 return 0;
1223}
1224
1225
1226int
1227sys_facl(tcp)
1228struct tcb *tcp;
1229{
1230 if (entering(tcp)) {
1231 tprintf("%ld, ", tcp->u_arg[0]);
1232 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1233 tprintf(", %ld", tcp->u_arg[2]);
1234 /*
1235 * FIXME - dump out the list of aclent_t's pointed to
1236 * by "tcp->u_arg[3]" if it's not NULL.
1237 */
1238 if (tcp->u_arg[3])
1239 tprintf(", %#lx", tcp->u_arg[3]);
1240 else
1241 tprintf(", NULL");
1242 }
1243 return 0;
1244}
1245
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001246
1247struct xlat aclipc[] = {
1248#ifdef IPC_SHM
1249 { IPC_SHM, "IPC_SHM" },
1250#endif
1251#ifdef IPC_SEM
1252 { IPC_SEM, "IPC_SEM" },
1253#endif
1254#ifdef IPC_MSG
1255 { IPC_MSG, "IPC_MSG" },
1256#endif
1257 { 0, NULL },
1258};
1259
1260
1261int
1262sys_aclipc(tcp)
1263struct tcb *tcp;
1264{
1265 if (entering(tcp)) {
1266 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1267 tprintf(", %#lx, ", tcp->u_arg[1]);
1268 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1269 tprintf(", %ld", tcp->u_arg[3]);
1270 /*
1271 * FIXME - dump out the list of aclent_t's pointed to
1272 * by "tcp->u_arg[4]" if it's not NULL.
1273 */
1274 if (tcp->u_arg[4])
1275 tprintf(", %#lx", tcp->u_arg[4]);
1276 else
1277 tprintf(", NULL");
1278 }
1279 return 0;
1280}
1281
1282
1283
Wichert Akkerman8829a551999-06-11 13:18:40 +00001284#endif /* HAVE_SYS_ACL_H */
1285
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001286#endif /* SVR4 || LINUXSPARC */
1287
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001288#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001289
1290static struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001291 { 0x73757245, "CODA_SUPER_MAGIC" },
1292 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1293 { 0x1373, "DEVFS_SUPER_MAGIC" },
1294 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1295 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001296 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1297 { 0xef53, "EXT2_SUPER_MAGIC" },
1298 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001299 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001300 { 0x9660, "ISOFS_SUPER_MAGIC" },
1301 { 0x137f, "MINIX_SUPER_MAGIC" },
1302 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001303 { 0x2468, "MINIX2_SUPER_MAGIC" },
1304 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001305 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001306 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001307 { 0x6969, "NFS_SUPER_MAGIC" },
1308 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001309 { 0x002f, "QNX4_SUPER_MAGIC" },
1310 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1311 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1312 { 0x517b, "SMB_SUPER_MAGIC" },
1313 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1314 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1315 { 0x00011954, "UFS_MAGIC" },
1316 { 0x54190100, "UFS_CIGAM" },
1317 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001318 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
1319 { 0, NULL },
1320};
1321
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001322#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001323
1324#ifndef SVR4
1325
1326static char *
1327sprintfstype(magic)
1328int magic;
1329{
1330 static char buf[32];
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001331#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001332 char *s;
1333
1334 s = xlookup(fsmagic, magic);
1335 if (s) {
1336 sprintf(buf, "\"%s\"", s);
1337 return buf;
1338 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001339#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001340 sprintf(buf, "%#x", magic);
1341 return buf;
1342}
1343
1344static void
1345printstatfs(tcp, addr)
1346struct tcb *tcp;
1347long addr;
1348{
1349 struct statfs statbuf;
1350
1351 if (syserror(tcp) || !verbose(tcp)) {
1352 tprintf("%#lx", addr);
1353 return;
1354 }
1355 if (umove(tcp, addr, &statbuf) < 0) {
1356 tprintf("{...}");
1357 return;
1358 }
1359#ifdef ALPHA
1360
1361 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1362 sprintfstype(statbuf.f_type),
1363 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001364 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_namelen=%u",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001365 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree, statbuf.f_namelen);
1366#else /* !ALPHA */
1367 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1368 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001369 (unsigned long)statbuf.f_bsize,
1370 (unsigned long)statbuf.f_blocks,
1371 (unsigned long)statbuf.f_bfree);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001372 tprintf("f_files=%lu, f_ffree=%lu",
Nate Sammons5c74d201999-04-06 01:37:51 +00001373 (unsigned long)statbuf.f_files,
1374 (unsigned long)statbuf.f_ffree);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001375#ifdef linux
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001376 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001377#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001378#endif /* !ALPHA */
1379 tprintf("}");
1380}
1381
1382int
1383sys_statfs(tcp)
1384struct tcb *tcp;
1385{
1386 if (entering(tcp)) {
1387 printpath(tcp, tcp->u_arg[0]);
1388 tprintf(", ");
1389 } else {
1390 printstatfs(tcp, tcp->u_arg[1]);
1391 }
1392 return 0;
1393}
1394
1395int
1396sys_fstatfs(tcp)
1397struct tcb *tcp;
1398{
1399 if (entering(tcp)) {
1400 tprintf("%lu, ", tcp->u_arg[0]);
1401 } else {
1402 printstatfs(tcp, tcp->u_arg[1]);
1403 }
1404 return 0;
1405}
1406
Wichert Akkermana0f36c61999-04-16 14:01:34 +00001407#if defined(linux) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001408
1409int
1410osf_statfs(tcp)
1411struct tcb *tcp;
1412{
1413 if (entering(tcp)) {
1414 printpath(tcp, tcp->u_arg[0]);
1415 tprintf(", ");
1416 } else {
1417 printstatfs(tcp, tcp->u_arg[1]);
1418 tprintf(", %lu", tcp->u_arg[2]);
1419 }
1420 return 0;
1421}
1422
1423int
1424osf_fstatfs(tcp)
1425struct tcb *tcp;
1426{
1427 if (entering(tcp)) {
1428 tprintf("%lu, ", tcp->u_arg[0]);
1429 } else {
1430 printstatfs(tcp, tcp->u_arg[1]);
1431 tprintf(", %lu", tcp->u_arg[2]);
1432 }
1433 return 0;
1434}
Wichert Akkermana0f36c61999-04-16 14:01:34 +00001435#endif /* linux && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001436
1437#endif /* !SVR4 */
1438
1439#ifdef SUNOS4
1440
1441int
1442sys_ustat(tcp)
1443struct tcb *tcp;
1444{
1445 struct ustat statbuf;
1446
1447 if (entering(tcp)) {
1448 tprintf("makedev(%lu, %lu), ",
1449 (long) major(tcp->u_arg[0]),
1450 (long) minor(tcp->u_arg[0]));
1451 }
1452 else {
1453 if (syserror(tcp) || !verbose(tcp))
1454 tprintf("%#lx", tcp->u_arg[1]);
1455 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1456 tprintf("{...}");
1457 else {
1458 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1459 statbuf.f_tfree, statbuf.f_tinode);
1460 tprintf("f_fname=\"%.*s\", ",
1461 (int) sizeof(statbuf.f_fname),
1462 statbuf.f_fname);
1463 tprintf("f_fpack=\"%.*s\"}",
1464 (int) sizeof(statbuf.f_fpack),
1465 statbuf.f_fpack);
1466 }
1467 }
1468 return 0;
1469}
1470
1471#endif /* SUNOS4 */
1472
Wichert Akkermanc7926982000-04-10 22:22:31 +00001473int
1474sys_pivotroot(tcp)
1475struct tcb *tcp;
1476{
1477 if (entering(tcp)) {
1478 printpath(tcp, tcp->u_arg[0]);
1479 tprintf(", ");
1480 printpath(tcp, tcp->u_arg[1]);
1481 }
1482 return 0;
1483}
1484
1485
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001486/* directory */
1487int
1488sys_chdir(tcp)
1489struct tcb *tcp;
1490{
1491 if (entering(tcp)) {
1492 printpath(tcp, tcp->u_arg[0]);
1493 }
1494 return 0;
1495}
1496
1497int
1498sys_mkdir(tcp)
1499struct tcb *tcp;
1500{
1501 if (entering(tcp)) {
1502 printpath(tcp, tcp->u_arg[0]);
1503 tprintf(", %#lo", tcp->u_arg[1]);
1504 }
1505 return 0;
1506}
1507
1508int
1509sys_rmdir(tcp)
1510struct tcb *tcp;
1511{
1512 if (entering(tcp)) {
1513 printpath(tcp, tcp->u_arg[0]);
1514 }
1515 return 0;
1516}
1517
1518int
1519sys_fchdir(tcp)
1520struct tcb *tcp;
1521{
1522 if (entering(tcp)) {
1523 tprintf("%ld", tcp->u_arg[0]);
1524 }
1525 return 0;
1526}
1527
1528int
1529sys_chroot(tcp)
1530struct tcb *tcp;
1531{
1532 if (entering(tcp)) {
1533 printpath(tcp, tcp->u_arg[0]);
1534 }
1535 return 0;
1536}
1537
1538int
1539sys_fchroot(tcp)
1540struct tcb *tcp;
1541{
1542 if (entering(tcp)) {
1543 tprintf("%ld", tcp->u_arg[0]);
1544 }
1545 return 0;
1546}
1547
1548int
1549sys_link(tcp)
1550struct tcb *tcp;
1551{
1552 if (entering(tcp)) {
1553 printpath(tcp, tcp->u_arg[0]);
1554 tprintf(", ");
1555 printpath(tcp, tcp->u_arg[1]);
1556 }
1557 return 0;
1558}
1559
1560int
1561sys_unlink(tcp)
1562struct tcb *tcp;
1563{
1564 if (entering(tcp)) {
1565 printpath(tcp, tcp->u_arg[0]);
1566 }
1567 return 0;
1568}
1569
1570int
1571sys_symlink(tcp)
1572struct tcb *tcp;
1573{
1574 if (entering(tcp)) {
1575 printpath(tcp, tcp->u_arg[0]);
1576 tprintf(", ");
1577 printpath(tcp, tcp->u_arg[1]);
1578 }
1579 return 0;
1580}
1581
1582int
1583sys_readlink(tcp)
1584struct tcb *tcp;
1585{
1586 if (entering(tcp)) {
1587 printpath(tcp, tcp->u_arg[0]);
1588 tprintf(", ");
1589 } else {
1590 if (syserror(tcp))
1591 tprintf("%#lx", tcp->u_arg[1]);
1592 else
1593 printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
1594 tprintf(", %lu", tcp->u_arg[2]);
1595 }
1596 return 0;
1597}
1598
1599int
1600sys_rename(tcp)
1601struct tcb *tcp;
1602{
1603 if (entering(tcp)) {
1604 printpath(tcp, tcp->u_arg[0]);
1605 tprintf(", ");
1606 printpath(tcp, tcp->u_arg[1]);
1607 }
1608 return 0;
1609}
1610
1611int
1612sys_chown(tcp)
1613struct tcb *tcp;
1614{
1615 if (entering(tcp)) {
1616 printpath(tcp, tcp->u_arg[0]);
1617 tprintf(", %lu, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1618 }
1619 return 0;
1620}
1621
1622int
1623sys_fchown(tcp)
1624struct tcb *tcp;
1625{
1626 if (entering(tcp)) {
1627 tprintf("%ld, %lu, %lu",
1628 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1629 }
1630 return 0;
1631}
1632
1633int
1634sys_chmod(tcp)
1635struct tcb *tcp;
1636{
1637 if (entering(tcp)) {
1638 printpath(tcp, tcp->u_arg[0]);
1639 tprintf(", %#lo", tcp->u_arg[1]);
1640 }
1641 return 0;
1642}
1643
1644int
1645sys_fchmod(tcp)
1646struct tcb *tcp;
1647{
1648 if (entering(tcp)) {
1649 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
1650 }
1651 return 0;
1652}
1653
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001654#ifdef ALPHA
1655int
1656sys_osf_utimes(tcp)
1657struct tcb *tcp;
1658{
1659 if (entering(tcp)) {
1660 printpath(tcp, tcp->u_arg[0]);
1661 tprintf(", ");
1662 printtv32(tcp, tcp->u_arg[1]);
1663 }
1664 return 0;
1665}
1666#endif
1667
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001668int
1669sys_utimes(tcp)
1670struct tcb *tcp;
1671{
1672 if (entering(tcp)) {
1673 printpath(tcp, tcp->u_arg[0]);
1674 tprintf(", ");
1675 printtv(tcp, tcp->u_arg[1]);
1676 }
1677 return 0;
1678}
1679
1680int
1681sys_utime(tcp)
1682struct tcb *tcp;
1683{
1684 long ut[2];
1685
1686 if (entering(tcp)) {
1687 printpath(tcp, tcp->u_arg[0]);
1688 tprintf(", ");
1689 if (!tcp->u_arg[1])
1690 tprintf("NULL");
1691 else if (!verbose(tcp))
1692 tprintf("%#lx", tcp->u_arg[1]);
1693 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
1694 (char *) ut) < 0)
1695 tprintf("[?, ?]");
1696 else {
1697 tprintf("[%s,", sprinttime(ut[0]));
1698 tprintf(" %s]", sprinttime(ut[1]));
1699 }
1700 }
1701 return 0;
1702}
1703
1704int
1705sys_mknod(tcp)
1706struct tcb *tcp;
1707{
1708 int mode = tcp->u_arg[1];
1709
1710 if (entering(tcp)) {
1711 printpath(tcp, tcp->u_arg[0]);
1712 tprintf(", %s", sprintmode(mode));
1713 switch (mode & S_IFMT) {
1714 case S_IFCHR: case S_IFBLK:
1715#ifdef LINUXSPARC
1716 if (current_personality == 1)
1717 tprintf(", makedev(%lu, %lu)",
1718 (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
1719 (unsigned long) (tcp->u_arg[2] & 0x3ffff));
1720 else
1721#endif
1722 tprintf(", makedev(%lu, %lu)",
1723 (unsigned long) major(tcp->u_arg[2]),
1724 (unsigned long) minor(tcp->u_arg[2]));
1725 break;
1726 default:
1727 break;
1728 }
1729 }
1730 return 0;
1731}
1732
1733int
1734sys_mkfifo(tcp)
1735struct tcb *tcp;
1736{
1737 if (entering(tcp)) {
1738 printpath(tcp, tcp->u_arg[0]);
1739 tprintf(", %#lo", tcp->u_arg[1]);
1740 }
1741 return 0;
1742}
1743
1744int
1745sys_fsync(tcp)
1746struct tcb *tcp;
1747{
1748 if (entering(tcp)) {
1749 tprintf("%ld", tcp->u_arg[0]);
1750 }
1751 return 0;
1752}
1753
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001754#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001755
1756static void
1757printdir(tcp, addr)
1758struct tcb *tcp;
1759long addr;
1760{
1761 struct dirent d;
1762
1763 if (!verbose(tcp)) {
1764 tprintf("%#lx", addr);
1765 return;
1766 }
1767 if (umove(tcp, addr, &d) < 0) {
1768 tprintf("{...}");
1769 return;
1770 }
1771 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001772 tprintf("d_name=");
1773 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
1774 tprintf("}");
1775}
1776
1777int
1778sys_readdir(tcp)
1779struct tcb *tcp;
1780{
1781 if (entering(tcp)) {
1782 tprintf("%lu, ", tcp->u_arg[0]);
1783 } else {
1784 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
1785 tprintf("%#lx", tcp->u_arg[1]);
1786 else
1787 printdir(tcp, tcp->u_arg[1]);
1788 /* Not much point in printing this out, it is always 1. */
1789 if (tcp->u_arg[2] != 1)
1790 tprintf(", %lu", tcp->u_arg[2]);
1791 }
1792 return 0;
1793}
1794
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001795#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001796
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001797#ifdef FREEBSD
1798struct xlat direnttypes[] = {
1799 { DT_FIFO, "DT_FIFO" },
1800 { DT_CHR, "DT_CHR" },
1801 { DT_DIR, "DT_DIR" },
1802 { DT_BLK, "DT_BLK" },
1803 { DT_REG, "DT_REG" },
1804 { DT_LNK, "DT_LNK" },
1805 { DT_SOCK, "DT_SOCK" },
1806 { DT_WHT, "DT_WHT" },
1807 { 0, NULL },
1808};
1809
1810#endif
1811
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001812int
1813sys_getdents(tcp)
1814struct tcb *tcp;
1815{
1816 int i, len, dents = 0;
1817 char *buf;
1818
1819 if (entering(tcp)) {
1820 tprintf("%lu, ", tcp->u_arg[0]);
1821 return 0;
1822 }
1823 if (syserror(tcp) || !verbose(tcp)) {
1824 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1825 return 0;
1826 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001827 len = tcp->u_rval;
1828 if ((buf = malloc(len)) == NULL) {
1829 tprintf("out of memory\n");
1830 return 0;
1831 }
1832 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1833 tprintf("{...}, %lu", tcp->u_arg[2]);
1834 free(buf);
1835 return 0;
1836 }
1837 if (!abbrev(tcp))
1838 tprintf("{");
1839 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00001840 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001841#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001842 if (!abbrev(tcp)) {
1843 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1844 i ? " " : "", d->d_ino, d->d_off);
1845 tprintf("d_reclen=%u, d_name=\"%s\"}",
1846 d->d_reclen, d->d_name);
1847 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001848#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001849#ifdef SVR4
1850 if (!abbrev(tcp)) {
1851 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1852 i ? " " : "", d->d_ino, d->d_off);
1853 tprintf("d_reclen=%u, d_name=\"%s\"}",
1854 d->d_reclen, d->d_name);
1855 }
1856#endif /* SVR4 */
1857#ifdef SUNOS4
1858 if (!abbrev(tcp)) {
1859 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
1860 i ? " " : "", d->d_off, d->d_fileno,
1861 d->d_reclen);
1862 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
1863 d->d_namlen, d->d_namlen, d->d_name);
1864 }
1865#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001866#ifdef FREEBSD
1867 if (!abbrev(tcp)) {
1868 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
1869 i ? " " : "", d->d_fileno, d->d_reclen);
1870 printxval(direnttypes, d->d_type, "DT_???");
1871 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
1872 d->d_namlen, d->d_namlen, d->d_name);
1873 }
1874#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00001875 if (!d->d_reclen) {
1876 tprintf("/* d_reclen == 0, problem here */");
1877 break;
1878 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001879 i += d->d_reclen;
1880 dents++;
1881 }
1882 if (!abbrev(tcp))
1883 tprintf("}");
1884 else
1885 tprintf("/* %u entries */", dents);
1886 tprintf(", %lu", tcp->u_arg[2]);
1887 free(buf);
1888 return 0;
1889}
1890
John Hughesbdf48f52001-03-06 15:08:09 +00001891
1892#if _LFS64_LARGEFILE
1893int
1894sys_getdents64(tcp)
1895struct tcb *tcp;
1896{
1897 int i, len, dents = 0;
1898 char *buf;
1899
1900 if (entering(tcp)) {
1901 tprintf("%lu, ", tcp->u_arg[0]);
1902 return 0;
1903 }
1904 if (syserror(tcp) || !verbose(tcp)) {
1905 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1906 return 0;
1907 }
1908 len = tcp->u_rval;
1909 if ((buf = malloc(len)) == NULL) {
1910 tprintf("out of memory\n");
1911 return 0;
1912 }
1913 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1914 tprintf("{...}, %lu", tcp->u_arg[2]);
1915 free(buf);
1916 return 0;
1917 }
1918 if (!abbrev(tcp))
1919 tprintf("{");
1920 for (i = 0; i < len;) {
1921 struct dirent64 *d = (struct dirent64 *) &buf[i];
1922#ifdef linux
1923 if (!abbrev(tcp)) {
1924 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1925 i ? " " : "", d->d_ino, d->d_off);
1926 tprintf("d_reclen=%u, d_name=\"%s\"}",
1927 d->d_reclen, d->d_name);
1928 }
1929#endif /* linux */
1930#ifdef SVR4
1931 if (!abbrev(tcp)) {
1932 tprintf("%s{d_ino=%llu, d_off=%llu, ",
1933 i ? " " : "", d->d_ino, d->d_off);
1934 tprintf("d_reclen=%u, d_name=\"%s\"}",
1935 d->d_reclen, d->d_name);
1936 }
1937#endif /* SVR4 */
1938#ifdef SUNOS4
1939 if (!abbrev(tcp)) {
1940 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
1941 i ? " " : "", d->d_off, d->d_fileno,
1942 d->d_reclen);
1943 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
1944 d->d_namlen, d->d_namlen, d->d_name);
1945 }
1946#endif /* SUNOS4 */
1947 i += d->d_reclen;
1948 dents++;
1949 }
1950 if (!abbrev(tcp))
1951 tprintf("}");
1952 else
1953 tprintf("/* %u entries */", dents);
1954 tprintf(", %lu", tcp->u_arg[2]);
1955 free(buf);
1956 return 0;
1957}
1958#endif
1959
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001960#ifdef FREEBSD
1961int
1962sys_getdirentries(tcp)
1963struct tcb * tcp;
1964{
1965 int i, len, dents = 0;
1966 long basep;
1967 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001968
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001969 if (entering(tcp)) {
1970 tprintf("%lu, ", tcp->u_arg[0]);
1971 return 0;
1972 }
1973 if (syserror(tcp) || !verbose(tcp)) {
1974 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
1975 return 0;
1976 }
1977 len = tcp->u_rval;
1978 if ((buf = malloc(len)) == NULL) {
1979 tprintf("out of memory\n");
1980 return 0;
1981 }
1982 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1983 tprintf("{...}, %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3]);
1984 free(buf);
1985 return 0;
1986 }
1987 if (!abbrev(tcp))
1988 tprintf("{");
1989 for (i = 0; i < len;) {
1990 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
1991 if (!abbrev(tcp)) {
1992 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
1993 i ? " " : "", d->d_fileno, d->d_reclen);
1994 printxval(direnttypes, d->d_type, "DT_???");
1995 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
1996 d->d_namlen, d->d_namlen, d->d_name);
1997 }
1998 i += d->d_reclen;
1999 dents++;
2000 }
2001 if (!abbrev(tcp))
2002 tprintf("}");
2003 else
2004 tprintf("/* %u entries */", dents);
2005 free(buf);
2006 tprintf(", %lu", tcp->u_arg[2]);
2007 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2008 tprintf(", %#lx", tcp->u_arg[3]);
2009 else
2010 tprintf(", [%lu]", basep);
2011 return 0;
2012}
2013#endif
2014
2015#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002016int
2017sys_getcwd(tcp)
2018struct tcb *tcp;
2019{
2020 if (exiting(tcp)) {
2021 if (syserror(tcp))
2022 tprintf("%#lx", tcp->u_arg[0]);
2023 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002024 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002025 tprintf(", %lu", tcp->u_arg[1]);
2026 }
2027 return 0;
2028}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00002029#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002030
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002031#ifdef FREEBSD
2032int
2033sys___getcwd(tcp)
2034struct tcb *tcp;
2035{
2036 if (exiting(tcp)) {
2037 if (syserror(tcp))
2038 tprintf("%#lx", tcp->u_arg[0]);
2039 else
2040 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2041 tprintf(", %lu", tcp->u_arg[1]);
2042 }
2043 return 0;
2044}
2045#endif
2046
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002047#ifdef HAVE_SYS_ASYNCH_H
2048
2049int
2050sys_aioread(tcp)
2051struct tcb *tcp;
2052{
2053 struct aio_result_t res;
2054
2055 if (entering(tcp)) {
2056 tprintf("%lu, ", tcp->u_arg[0]);
2057 } else {
2058 if (syserror(tcp))
2059 tprintf("%#lx", tcp->u_arg[1]);
2060 else
2061 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2062 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2063 printxval(whence, tcp->u_arg[4], "L_???");
2064 if (syserror(tcp) || tcp->u_arg[5] == 0
2065 || umove(tcp, tcp->u_arg[5], &res) < 0)
2066 tprintf(", %#lx", tcp->u_arg[5]);
2067 else
2068 tprintf(", {aio_return %d aio_errno %d}",
2069 res.aio_return, res.aio_errno);
2070 }
2071 return 0;
2072}
2073
2074int
2075sys_aiowrite(tcp)
2076struct tcb *tcp;
2077{
2078 struct aio_result_t res;
2079
2080 if (entering(tcp)) {
2081 tprintf("%lu, ", tcp->u_arg[0]);
2082 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2083 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2084 printxval(whence, tcp->u_arg[4], "L_???");
2085 }
2086 else {
2087 if (tcp->u_arg[5] == 0)
2088 tprintf(", NULL");
2089 else if (syserror(tcp)
2090 || umove(tcp, tcp->u_arg[5], &res) < 0)
2091 tprintf(", %#lx", tcp->u_arg[5]);
2092 else
2093 tprintf(", {aio_return %d aio_errno %d}",
2094 res.aio_return, res.aio_errno);
2095 }
2096 return 0;
2097}
2098
2099int
2100sys_aiowait(tcp)
2101struct tcb *tcp;
2102{
2103 if (entering(tcp))
2104 printtv(tcp, tcp->u_arg[0]);
2105 return 0;
2106}
2107
2108int
2109sys_aiocancel(tcp)
2110struct tcb *tcp;
2111{
2112 struct aio_result_t res;
2113
2114 if (exiting(tcp)) {
2115 if (tcp->u_arg[0] == 0)
2116 tprintf("NULL");
2117 else if (syserror(tcp)
2118 || umove(tcp, tcp->u_arg[0], &res) < 0)
2119 tprintf("%#lx", tcp->u_arg[0]);
2120 else
2121 tprintf("{aio_return %d aio_errno %d}",
2122 res.aio_return, res.aio_errno);
2123 }
2124 return 0;
2125}
2126
2127#endif /* HAVE_SYS_ASYNCH_H */