blob: 3ec97e314b3d0c67b633aefd4b9a6829d5ee4b0e [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * $Id$
31 */
32
33#include "defs.h"
34
35#include <dirent.h>
Wichert Akkerman9524bb91999-05-25 23:11:18 +000036#ifdef linux
37#define dirent kernel_dirent
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +000038#define dirent64 kernel_dirent64
Wichert Akkerman9524bb91999-05-25 23:11:18 +000039#include <linux/types.h>
40#include <linux/dirent.h>
41#undef dirent
42#else
43#define kernel_dirent dirent
44#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000045
Wichert Akkerman8bc6cfd1999-04-21 15:57:38 +000046#ifdef linux
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000047# ifdef LINUXSPARC
48struct stat {
49 unsigned short st_dev;
50 unsigned int st_ino;
51 unsigned short st_mode;
52 short st_nlink;
53 unsigned short st_uid;
54 unsigned short st_gid;
55 unsigned short st_rdev;
56 unsigned int st_size;
57 int st_atime;
58 unsigned int __unused1;
59 int st_mtime;
60 unsigned int __unused2;
61 int st_ctime;
62 unsigned int __unused3;
63 int st_blksize;
64 int st_blocks;
65 unsigned int __unused4[2];
66};
67# define stat kernel_stat
68# include <asm/stat.h>
69# undef stat
70# else
Wichert Akkerman5b4d1281999-07-09 00:32:54 +000071# undef dev_t
72# undef ino_t
73# undef mode_t
74# undef nlink_t
75# undef uid_t
76# undef gid_t
77# undef off_t
78# undef loff_t
79
Wichert Akkermana6013701999-07-08 14:00:58 +000080# define dev_t __kernel_dev_t
81# define ino_t __kernel_ino_t
82# define mode_t __kernel_mode_t
83# define nlink_t __kernel_nlink_t
84# define uid_t __kernel_uid_t
85# define gid_t __kernel_gid_t
86# define off_t __kernel_off_t
87# define loff_t __kernel_loff_t
88
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000089# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +000090
91# undef dev_t
92# undef ino_t
93# undef mode_t
94# undef nlink_t
95# undef uid_t
96# undef gid_t
97# undef off_t
98# undef loff_t
Wichert Akkerman5b4d1281999-07-09 00:32:54 +000099
100# define dev_t dev_t
101# define ino_t ino_t
102# define mode_t mode_t
103# define nlink_t nlink_t
104# define uid_t uid_t
105# define gid_t gid_t
106# define off_t off_t
107# define loff_t loff_t
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000108# endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000109# define stat libc_stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000110# define stat64 libc_stat64
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000111# include <sys/stat.h>
112# undef stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000113# undef stat64
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000114#else
115# include <sys/stat.h>
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000116#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000117
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000118#include <fcntl.h>
119
120#ifdef SVR4
121# include <sys/cred.h>
122#endif /* SVR4 */
123
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000124#ifdef HAVE_SYS_VFS_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000125#include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000126#endif
127
128#ifdef FREEBSD
129#include <sys/param.h>
130#include <sys/mount.h>
131#include <sys/stat.h>
132#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000133
134#ifdef MAJOR_IN_SYSMACROS
135#include <sys/sysmacros.h>
136#endif
137
138#ifdef MAJOR_IN_MKDEV
139#include <sys/mkdev.h>
140#endif
141
142#ifdef HAVE_SYS_ASYNCH_H
143#include <sys/asynch.h>
144#endif
145
146#ifdef SUNOS4
147#include <ustat.h>
148#endif
149
150/*
151 * This is a really dirty trick but it should always work. Traditional
152 * Unix says r/w/rw are 0/1/2, so we make them true flags 1/2/3 by
153 * adding 1. Just remember to add 1 to any arg decoded with openmodes.
154 */
155struct xlat openmodes[] = {
156 { O_RDWR+1, "O_RDWR" },
157 { O_RDONLY+1, "O_RDONLY" },
158 { O_WRONLY+1, "O_WRONLY" },
159 { O_NONBLOCK, "O_NONBLOCK" },
160 { O_APPEND, "O_APPEND" },
161 { O_CREAT, "O_CREAT" },
162 { O_TRUNC, "O_TRUNC" },
163 { O_EXCL, "O_EXCL" },
164 { O_NOCTTY, "O_NOCTTY" },
165#ifdef O_SYNC
166 { O_SYNC, "O_SYNC" },
167#endif
168#ifdef O_ASYNC
169 { O_ASYNC, "O_ASYNC" },
170#endif
171#ifdef O_DSYNC
172 { O_DSYNC, "O_DSYNC" },
173#endif
174#ifdef O_RSYNC
175 { O_RSYNC, "O_RSYNC" },
176#endif
177#ifdef O_NDELAY
178 { O_NDELAY, "O_NDELAY" },
179#endif
180#ifdef O_PRIV
181 { O_PRIV, "O_PRIV" },
182#endif
183#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000184 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000185#endif
186#ifdef O_LARGEFILE
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000187 { O_LARGEFILE, "O_LARGEFILE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000188#endif
189#ifdef O_DIRECTORY
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000190 { O_DIRECTORY, "O_DIRECTORY" },
191#endif
192#ifdef O_NOFOLLOW
193 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000194#endif
195
196#ifdef FNDELAY
197 { FNDELAY, "FNDELAY" },
198#endif
199#ifdef FAPPEND
200 { FAPPEND, "FAPPEND" },
201#endif
202#ifdef FMARK
203 { FMARK, "FMARK" },
204#endif
205#ifdef FDEFER
206 { FDEFER, "FDEFER" },
207#endif
208#ifdef FASYNC
209 { FASYNC, "FASYNC" },
210#endif
211#ifdef FSHLOCK
212 { FSHLOCK, "FSHLOCK" },
213#endif
214#ifdef FEXLOCK
215 { FEXLOCK, "FEXLOCK" },
216#endif
217#ifdef FCREAT
218 { FCREAT, "FCREAT" },
219#endif
220#ifdef FTRUNC
221 { FTRUNC, "FTRUNC" },
222#endif
223#ifdef FEXCL
224 { FEXCL, "FEXCL" },
225#endif
226#ifdef FNBIO
227 { FNBIO, "FNBIO" },
228#endif
229#ifdef FSYNC
230 { FSYNC, "FSYNC" },
231#endif
232#ifdef FNOCTTY
233 { FNOCTTY, "FNOCTTY" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000234#endif
235#ifdef O_SHLOCK
236 { O_SHLOCK, "O_SHLOCK" },
237#endif
238#ifdef O_EXLOCK
239 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000240#endif
241 { 0, NULL },
242};
243
244int
245sys_open(tcp)
246struct tcb *tcp;
247{
248 if (entering(tcp)) {
249 printpath(tcp, tcp->u_arg[0]);
250 tprintf(", ");
251 /* flags */
252 printflags(openmodes, tcp->u_arg[1] + 1);
253 if (tcp->u_arg[1] & O_CREAT) {
254 /* mode */
255 tprintf(", %#lo", tcp->u_arg[2]);
256 }
257 }
258 return 0;
259}
260
261#ifdef LINUXSPARC
262struct xlat openmodessol[] = {
263 { 0, "O_RDWR" },
264 { 1, "O_RDONLY" },
265 { 2, "O_WRONLY" },
266 { 0x80, "O_NONBLOCK" },
267 { 8, "O_APPEND" },
268 { 0x100, "O_CREAT" },
269 { 0x200, "O_TRUNC" },
270 { 0x400, "O_EXCL" },
271 { 0x800, "O_NOCTTY" },
272 { 0x10, "O_SYNC" },
273 { 0x40, "O_DSYNC" },
274 { 0x8000, "O_RSYNC" },
275 { 4, "O_NDELAY" },
276 { 0x1000, "O_PRIV" },
277 { 0, NULL },
278};
279
280int
281solaris_open(tcp)
282struct tcb *tcp;
283{
284 if (entering(tcp)) {
285 printpath(tcp, tcp->u_arg[0]);
286 tprintf(", ");
287 /* flags */
288 printflags(openmodessol, tcp->u_arg[1] + 1);
289 if (tcp->u_arg[1] & 0x100) {
290 /* mode */
291 tprintf(", %#lo", tcp->u_arg[2]);
292 }
293 }
294 return 0;
295}
296
297#endif
298
299int
300sys_creat(tcp)
301struct tcb *tcp;
302{
303 if (entering(tcp)) {
304 printpath(tcp, tcp->u_arg[0]);
305 tprintf(", %#lo", tcp->u_arg[1]);
306 }
307 return 0;
308}
309
310static struct xlat access_flags[] = {
311 { F_OK, "F_OK", },
312 { R_OK, "R_OK" },
313 { W_OK, "W_OK" },
314 { X_OK, "X_OK" },
315#ifdef EFF_ONLY_OK
316 { EFF_ONLY_OK, "EFF_ONLY_OK" },
317#endif
318#ifdef EX_OK
319 { EX_OK, "EX_OK" },
320#endif
321 { 0, NULL },
322};
323
324int
325sys_access(tcp)
326struct tcb *tcp;
327{
328 if (entering(tcp)) {
329 printpath(tcp, tcp->u_arg[0]);
330 tprintf(", ");
331 printflags(access_flags, tcp->u_arg[1]);
332 }
333 return 0;
334}
335
336int
337sys_umask(tcp)
338struct tcb *tcp;
339{
340 if (entering(tcp)) {
341 tprintf("%#lo", tcp->u_arg[0]);
342 }
343 return RVAL_OCTAL;
344}
345
346static struct xlat whence[] = {
347 { SEEK_SET, "SEEK_SET" },
348 { SEEK_CUR, "SEEK_CUR" },
349 { SEEK_END, "SEEK_END" },
350 { 0, NULL },
351};
352
353int
354sys_lseek(tcp)
355struct tcb *tcp;
356{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000357 off_t offset;
358 int _whence;
359
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000360 if (entering(tcp)) {
361 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000362#ifndef FREEBSD
363 offset = tcp->u_arg[1];
364 _whence = tcp->u_arg[2];
365 if (_whence == SEEK_SET)
366 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000367 else
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000368 tprintf("%ld, ", offset);
369#else /* FREEBSD */
370 offset = ((off_t) tcp->u_arg[1] << 32) + tcp->u_arg[2];
371 _whence = tcp->u_arg[4];
372 if (_whence == SEEK_SET)
373 tprintf("%llu, ", offset);
374 else
375 tprintf("%lld, ", offset);
376#endif
377 printxval(whence, _whence, "SEEK_???");
378 }
379#ifdef FREEBSD
380 else
381 if (!syserror(tcp))
382 return RVAL_LUDECIMAL;
383#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000384 return RVAL_UDECIMAL;
385}
386
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000387#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000388int
389sys_llseek (tcp)
390struct tcb *tcp;
391{
392 if (entering(tcp)) {
393 if (tcp->u_arg[4] == SEEK_SET)
394 tprintf("%ld, %llu, ", tcp->u_arg[0],
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000395 (((long long int) tcp->u_arg[1]) << 32
396 | (unsigned long long) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000397 else
398 tprintf("%ld, %lld, ", tcp->u_arg[0],
399 (((long long int) tcp->u_arg[1]) << 32
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000400 | (unsigned long long) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000401 }
402 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000403 long long int off;
404 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000405 tprintf("%#lx, ", tcp->u_arg[3]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000406 else
407 tprintf("[%llu], ", off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000408 printxval(whence, tcp->u_arg[4], "SEEK_???");
409 }
410 return 0;
411}
412#endif
413
John Hughesbdf48f52001-03-06 15:08:09 +0000414#if _LFS_LARGEFILE
415int
416sys_lseek64 (tcp)
417struct tcb *tcp;
418{
419 if (entering(tcp)) {
420 long long offset = get64(tcp->u_arg [1], tcp->u_arg[2]);
421 if (tcp->u_arg[3] == SEEK_SET)
422 tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
423 else
424 tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
425 printxval(whence, tcp->u_arg[3], "SEEK_???");
426 }
427 return RVAL_LUDECIMAL;
428}
429#endif
430
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000431int
432sys_truncate(tcp)
433struct tcb *tcp;
434{
435 if (entering(tcp)) {
436 printpath(tcp, tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000437#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438 tprintf(", %lu", tcp->u_arg[1]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000439#else
440 tprintf(", %llu", ((off_t) tcp->u_arg[1] << 32) + tcp->u_arg[2]);
441#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000442 }
443 return 0;
444}
445
446int
447sys_ftruncate(tcp)
448struct tcb *tcp;
449{
450 if (entering(tcp)) {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000451#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000452 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000453#else
454 tprintf("%ld, %llu", tcp->u_arg[0],
455 ((off_t) tcp->u_arg[1] << 32) + tcp->u_arg[2]);
456#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000457 }
458 return 0;
459}
460
461/* several stats */
462
463static struct xlat modetypes[] = {
464 { S_IFREG, "S_IFREG" },
465 { S_IFSOCK, "S_IFSOCK" },
466 { S_IFIFO, "S_IFIFO" },
467 { S_IFLNK, "S_IFLNK" },
468 { S_IFDIR, "S_IFDIR" },
469 { S_IFBLK, "S_IFBLK" },
470 { S_IFCHR, "S_IFCHR" },
471 { 0, NULL },
472};
473
474static char *
475sprintmode(mode)
476int mode;
477{
478 static char buf[64];
479 char *s;
480
481 if ((mode & S_IFMT) == 0)
482 s = "";
483 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
484 sprintf(buf, "%#o", mode);
485 return buf;
486 }
487 sprintf(buf, "%s%s%s%s", s,
488 (mode & S_ISUID) ? "|S_ISUID" : "",
489 (mode & S_ISGID) ? "|S_ISGID" : "",
490 (mode & S_ISVTX) ? "|S_ISVTX" : "");
491 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
492 if (mode)
493 sprintf(buf + strlen(buf), "|%#o", mode);
494 s = (*buf == '|') ? buf + 1 : buf;
495 return *s ? s : "0";
496}
497
498static char *
499sprinttime(t)
500time_t t;
501{
502 struct tm *tmp;
503 static char buf[32];
504
505 if (t == 0) {
506 sprintf(buf, "0");
507 return buf;
508 }
509 tmp = localtime(&t);
510 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
Wichert Akkerman3ed6dc22000-01-11 14:41:09 +0000511 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000512 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
513 return buf;
514}
515
516#ifdef LINUXSPARC
517typedef struct {
518 int tv_sec;
519 int tv_nsec;
520} timestruct_t;
521
522struct solstat {
523 unsigned st_dev;
524 int st_pad1[3]; /* network id */
525 unsigned st_ino;
526 unsigned st_mode;
527 unsigned st_nlink;
528 unsigned st_uid;
529 unsigned st_gid;
530 unsigned st_rdev;
531 int st_pad2[2];
532 int st_size;
533 int st_pad3; /* st_size, off_t expansion */
534 timestruct_t st_atime;
535 timestruct_t st_mtime;
536 timestruct_t st_ctime;
537 int st_blksize;
538 int st_blocks;
539 char st_fstype[16];
540 int st_pad4[8]; /* expansion area */
541};
542
543static void
544printstatsol(tcp, addr)
545struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000546long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547{
548 struct solstat statbuf;
549
550 if (!addr) {
551 tprintf("NULL");
552 return;
553 }
554 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000555 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000556 return;
557 }
558 if (umove(tcp, addr, &statbuf) < 0) {
559 tprintf("{...}");
560 return;
561 }
562 if (!abbrev(tcp)) {
563 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
564 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
565 (unsigned long) (statbuf.st_dev & 0x3ffff),
566 (unsigned long) statbuf.st_ino,
567 sprintmode(statbuf.st_mode));
568 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
569 (unsigned long) statbuf.st_nlink,
570 (unsigned long) statbuf.st_uid,
571 (unsigned long) statbuf.st_gid);
572 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
573 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
574 }
575 else
576 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
577 switch (statbuf.st_mode & S_IFMT) {
578 case S_IFCHR: case S_IFBLK:
579 tprintf("st_rdev=makedev(%lu, %lu), ",
580 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
581 (unsigned long) (statbuf.st_rdev & 0x3ffff));
582 break;
583 default:
584 tprintf("st_size=%u, ", statbuf.st_size);
585 break;
586 }
587 if (!abbrev(tcp)) {
588 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
589 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
590 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
591 }
592 else
593 tprintf("...}");
594}
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000595#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000596
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000597#ifdef FREEBSD
598static struct xlat fileflags[] = {
599 { UF_NODUMP, "UF_NODUMP" },
600 { UF_IMMUTABLE, "UF_IMMUTABLE" },
601 { UF_APPEND, "UF_APPEND" },
602 { UF_OPAQUE, "UF_OPAQUE" },
603 { UF_NOUNLINK, "UF_NOUNLINK" },
604 { SF_ARCHIVED, "SF_ARCHIVED" },
605 { SF_IMMUTABLE, "SF_IMMUTABLE" },
606 { SF_APPEND, "SF_APPEND" },
607 { SF_NOUNLINK, "SF_NOUNLINK" },
608 { 0, NULL },
609};
610
611int
612sys_chflags(tcp)
613struct tcb *tcp;
614{
615 if (entering(tcp)) {
616 printpath(tcp, tcp->u_arg[0]);
617 tprintf(", ");
618 if (tcp->u_arg[1])
619 printflags(fileflags, tcp->u_arg[1]);
620 else
621 tprintf("0");
622 }
623 return 0;
624}
625
626int
627sys_fchflags(tcp)
628struct tcb *tcp;
629{
630 if (entering(tcp)) {
631 tprintf("%ld, ", tcp->u_arg[0]);
632 if (tcp->u_arg[1])
633 printflags(fileflags, tcp->u_arg[1]);
634 else
635 tprintf("0");
636 }
637 return 0;
638}
639#endif
640
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000641static void
642realprintstat(tcp, statbuf)
643struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000644struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000645{
646 if (!abbrev(tcp)) {
647 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
648 (unsigned long) major(statbuf->st_dev),
649 (unsigned long) minor(statbuf->st_dev),
650 (unsigned long) statbuf->st_ino,
651 sprintmode(statbuf->st_mode));
652 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
653 (unsigned long) statbuf->st_nlink,
654 (unsigned long) statbuf->st_uid,
655 (unsigned long) statbuf->st_gid);
656#ifdef HAVE_ST_BLKSIZE
657 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
658#endif /* HAVE_ST_BLKSIZE */
659#ifdef HAVE_ST_BLOCKS
660 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
661#endif /* HAVE_ST_BLOCKS */
662 }
663 else
664 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
665 switch (statbuf->st_mode & S_IFMT) {
666 case S_IFCHR: case S_IFBLK:
667#ifdef HAVE_ST_RDEV
668 tprintf("st_rdev=makedev(%lu, %lu), ",
669 (unsigned long) major(statbuf->st_rdev),
670 (unsigned long) minor(statbuf->st_rdev));
671#else /* !HAVE_ST_RDEV */
672 tprintf("st_size=makedev(%lu, %lu), ",
673 (unsigned long) major(statbuf->st_size),
674 (unsigned long) minor(statbuf->st_size));
675#endif /* !HAVE_ST_RDEV */
676 break;
677 default:
678 tprintf("st_size=%lu, ", statbuf->st_size);
679 break;
680 }
681 if (!abbrev(tcp)) {
682 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
683 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000684#ifndef FREEBSD
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000685 tprintf("st_ctime=%s}", sprinttime(statbuf->st_ctime));
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000686#else /* FREEBSD */
687 tprintf("st_ctime=%s, ", sprinttime(statbuf->st_ctime));
688 tprintf("st_flags=");
689 if (statbuf->st_flags) {
690 printflags(fileflags, statbuf->st_flags);
691 } else
692 tprintf("0");
693 tprintf(", st_gen=%u}", statbuf->st_gen);
694#endif /* FREEBSD */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000695 }
696 else
697 tprintf("...}");
698}
699
Nate Sammons771a6ff1999-04-05 22:39:31 +0000700
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000701static void
702printstat(tcp, addr)
703struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000704long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000705{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000706 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000707
708#ifdef LINUXSPARC
709 if (current_personality == 1) {
710 printstatsol(tcp, addr);
711 return;
712 }
713#endif /* LINUXSPARC */
714
715 if (!addr) {
716 tprintf("NULL");
717 return;
718 }
719 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000720 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000721 return;
722 }
723 if (umove(tcp, addr, &statbuf) < 0) {
724 tprintf("{...}");
725 return;
726 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000727
728 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000729}
730
Wichert Akkermanc7926982000-04-10 22:22:31 +0000731#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000732static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000733printstat64(tcp, addr)
734struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000735long addr;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000736{
737 struct stat64 statbuf;
738
739#ifdef LINUXSPARC
740 if (current_personality == 1) {
741 printstatsol(tcp, addr);
742 return;
743 }
744#endif /* LINUXSPARC */
745
746 if (!addr) {
747 tprintf("NULL");
748 return;
749 }
750 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000751 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000752 return;
753 }
754 if (umove(tcp, addr, &statbuf) < 0) {
755 tprintf("{...}");
756 return;
757 }
758
759 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +0000760#ifdef HAVE_LONG_LONG
761 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
762#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000763 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +0000764#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000765 (unsigned long) major(statbuf.st_dev),
766 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +0000767#ifdef HAVE_LONG_LONG
768 (unsigned long long) statbuf.st_ino,
769#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000770 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +0000771#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000772 sprintmode(statbuf.st_mode));
773 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
774 (unsigned long) statbuf.st_nlink,
775 (unsigned long) statbuf.st_uid,
776 (unsigned long) statbuf.st_gid);
777#ifdef HAVE_ST_BLKSIZE
778 tprintf("st_blksize=%lu, ",
779 (unsigned long) statbuf.st_blksize);
780#endif /* HAVE_ST_BLKSIZE */
781#ifdef HAVE_ST_BLOCKS
782 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
783#endif /* HAVE_ST_BLOCKS */
784 }
785 else
786 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
787 switch (statbuf.st_mode & S_IFMT) {
788 case S_IFCHR: case S_IFBLK:
789#ifdef HAVE_ST_RDEV
790 tprintf("st_rdev=makedev(%lu, %lu), ",
791 (unsigned long) major(statbuf.st_rdev),
792 (unsigned long) minor(statbuf.st_rdev));
793#else /* !HAVE_ST_RDEV */
794 tprintf("st_size=makedev(%lu, %lu), ",
795 (unsigned long) major(statbuf.st_size),
796 (unsigned long) minor(statbuf.st_size));
797#endif /* !HAVE_ST_RDEV */
798 break;
799 default:
800 tprintf("st_size=%llu, ", statbuf.st_size);
801 break;
802 }
803 if (!abbrev(tcp)) {
804 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
805 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
806 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
807 }
808 else
809 tprintf("...}");
810}
Wichert Akkermanc7926982000-04-10 22:22:31 +0000811#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000812
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000813#if defined(linux) && !defined(IA64)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000814static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000815convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000816const struct __old_kernel_stat *oldbuf;
817struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000818{
819 newbuf->st_dev=oldbuf->st_dev;
820 newbuf->st_ino=oldbuf->st_ino;
821 newbuf->st_mode=oldbuf->st_mode;
822 newbuf->st_nlink=oldbuf->st_nlink;
823 newbuf->st_uid=oldbuf->st_uid;
824 newbuf->st_gid=oldbuf->st_gid;
825 newbuf->st_rdev=oldbuf->st_rdev;
826 newbuf->st_size=oldbuf->st_size;
827 newbuf->st_atime=oldbuf->st_atime;
828 newbuf->st_mtime=oldbuf->st_mtime;
829 newbuf->st_ctime=oldbuf->st_ctime;
830 newbuf->st_blksize=0; /* not supported in old_stat */
831 newbuf->st_blocks=0; /* not supported in old_stat */
832}
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000833
834
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000835static void
836printoldstat(tcp, addr)
837struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000838long addr;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000839{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000840 struct __old_kernel_stat statbuf;
841 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000842
843#ifdef LINUXSPARC
844 if (current_personality == 1) {
845 printstatsol(tcp, addr);
846 return;
847 }
848#endif /* LINUXSPARC */
849
850 if (!addr) {
851 tprintf("NULL");
852 return;
853 }
854 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000855 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000856 return;
857 }
858 if (umove(tcp, addr, &statbuf) < 0) {
859 tprintf("{...}");
860 return;
861 }
862
863 convertoldstat(&statbuf, &newstatbuf);
864 realprintstat(tcp, &newstatbuf);
865}
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000866#endif /* linux && !IA64 */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000867
868
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000869int
870sys_stat(tcp)
871struct tcb *tcp;
872{
873 if (entering(tcp)) {
874 printpath(tcp, tcp->u_arg[0]);
875 tprintf(", ");
876 } else {
877 printstat(tcp, tcp->u_arg[1]);
878 }
879 return 0;
880}
881
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000882#ifdef linux
883int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000884sys_stat64(tcp)
885struct tcb *tcp;
886{
887#ifdef HAVE_STAT64
888 if (entering(tcp)) {
889 printpath(tcp, tcp->u_arg[0]);
890 tprintf(", ");
891 } else {
892 printstat64(tcp, tcp->u_arg[1]);
893 }
894 return 0;
895#else
896 return printargs(tcp);
897#endif
898}
899
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000900# if !defined(IA64)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000901int
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000902sys_oldstat(tcp)
903struct tcb *tcp;
904{
905 if (entering(tcp)) {
906 printpath(tcp, tcp->u_arg[0]);
907 tprintf(", ");
908 } else {
909 printoldstat(tcp, tcp->u_arg[1]);
910 }
911 return 0;
912}
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000913# endif /* !IA64 */
914#endif /* linux */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000915
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000916int
917sys_fstat(tcp)
918struct tcb *tcp;
919{
920 if (entering(tcp))
921 tprintf("%ld, ", tcp->u_arg[0]);
922 else {
923 printstat(tcp, tcp->u_arg[1]);
924 }
925 return 0;
926}
927
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000928#ifdef linux
929int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000930sys_fstat64(tcp)
931struct tcb *tcp;
932{
933#ifdef HAVE_STAT64
934 if (entering(tcp))
935 tprintf("%ld, ", tcp->u_arg[0]);
936 else {
937 printstat64(tcp, tcp->u_arg[1]);
938 }
939 return 0;
940#else
941 return printargs(tcp);
942#endif
943}
944
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000945# if !defined(IA64)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000946int
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000947sys_oldfstat(tcp)
948struct tcb *tcp;
949{
950 if (entering(tcp))
951 tprintf("%ld, ", tcp->u_arg[0]);
952 else {
953 printoldstat(tcp, tcp->u_arg[1]);
954 }
955 return 0;
956}
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000957# endif /* !IA64 */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000958#endif
959
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000960int
961sys_lstat(tcp)
962struct tcb *tcp;
963{
964 if (entering(tcp)) {
965 printpath(tcp, tcp->u_arg[0]);
966 tprintf(", ");
967 } else {
968 printstat(tcp, tcp->u_arg[1]);
969 }
970 return 0;
971}
972
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000973#ifdef linux
974int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000975sys_lstat64(tcp)
976struct tcb *tcp;
977{
978#ifdef HAVE_STAT64
979 if (entering(tcp)) {
980 printpath(tcp, tcp->u_arg[0]);
981 tprintf(", ");
982 } else {
983 printstat64(tcp, tcp->u_arg[1]);
984 }
985 return 0;
986#else
987 return printargs(tcp);
988#endif
989}
990
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000991# if !defined(IA64)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000992int
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000993sys_oldlstat(tcp)
994struct tcb *tcp;
995{
996 if (entering(tcp)) {
997 printpath(tcp, tcp->u_arg[0]);
998 tprintf(", ");
999 } else {
1000 printoldstat(tcp, tcp->u_arg[1]);
1001 }
1002 return 0;
1003}
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001004# endif /* !IA64 */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001005#endif
1006
1007
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001008#if defined(SVR4) || defined(LINUXSPARC)
1009
1010int
1011sys_xstat(tcp)
1012struct tcb *tcp;
1013{
1014 if (entering(tcp)) {
1015 tprintf("%ld, ", tcp->u_arg[0]);
1016 printpath(tcp, tcp->u_arg[1]);
1017 tprintf(", ");
1018 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001019#ifdef _STAT64_VER
1020 if (tcp->u_arg[0] == _STAT64_VER)
1021 printstat64 (tcp, tcp->u_arg[2]);
1022 else
1023#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001024 printstat(tcp, tcp->u_arg[2]);
1025 }
1026 return 0;
1027}
1028
1029int
1030sys_fxstat(tcp)
1031struct tcb *tcp;
1032{
1033 if (entering(tcp))
1034 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1035 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001036#ifdef _STAT64_VER
1037 if (tcp->u_arg[0] == _STAT64_VER)
1038 printstat64 (tcp, tcp->u_arg[2]);
1039 else
1040#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001041 printstat(tcp, tcp->u_arg[2]);
1042 }
1043 return 0;
1044}
1045
1046int
1047sys_lxstat(tcp)
1048struct tcb *tcp;
1049{
1050 if (entering(tcp)) {
1051 tprintf("%ld, ", tcp->u_arg[0]);
1052 printpath(tcp, tcp->u_arg[1]);
1053 tprintf(", ");
1054 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001055#ifdef _STAT64_VER
1056 if (tcp->u_arg[0] == _STAT64_VER)
1057 printstat64 (tcp, tcp->u_arg[2]);
1058 else
1059#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001060 printstat(tcp, tcp->u_arg[2]);
1061 }
1062 return 0;
1063}
1064
1065int
1066sys_xmknod(tcp)
1067struct tcb *tcp;
1068{
1069 int mode = tcp->u_arg[2];
1070
1071 if (entering(tcp)) {
1072 tprintf("%ld, ", tcp->u_arg[0]);
1073 printpath(tcp, tcp->u_arg[1]);
1074 tprintf(", %s", sprintmode(mode));
1075 switch (mode & S_IFMT) {
1076 case S_IFCHR: case S_IFBLK:
1077#ifdef LINUXSPARC
1078 tprintf(", makedev(%lu, %lu)",
1079 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1080 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1081#else
1082 tprintf(", makedev(%lu, %lu)",
1083 (unsigned long) major(tcp->u_arg[3]),
1084 (unsigned long) minor(tcp->u_arg[3]));
1085#endif
1086 break;
1087 default:
1088 break;
1089 }
1090 }
1091 return 0;
1092}
1093
Wichert Akkerman8829a551999-06-11 13:18:40 +00001094#ifdef HAVE_SYS_ACL_H
1095
1096#include <sys/acl.h>
1097
1098struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001099#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001100 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001101#endif
1102#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001103 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001104#endif
1105#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001106 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001107#endif
1108#ifdef ACL_GET
1109 { ACL_GET, "ACL_GET" },
1110#endif
1111#ifdef ACL_SET
1112 { ACL_SET, "ACL_SET" },
1113#endif
1114#ifdef ACL_CNT
1115 { ACL_CNT, "ACL_CNT" },
1116#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001117 { 0, NULL },
1118};
1119
1120int
1121sys_acl(tcp)
1122struct tcb *tcp;
1123{
1124 if (entering(tcp)) {
1125 printpath(tcp, tcp->u_arg[0]);
1126 tprintf(", ");
1127 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1128 tprintf(", %ld", tcp->u_arg[2]);
1129 /*
1130 * FIXME - dump out the list of aclent_t's pointed to
1131 * by "tcp->u_arg[3]" if it's not NULL.
1132 */
1133 if (tcp->u_arg[3])
1134 tprintf(", %#lx", tcp->u_arg[3]);
1135 else
1136 tprintf(", NULL");
1137 }
1138 return 0;
1139}
1140
1141
1142int
1143sys_facl(tcp)
1144struct tcb *tcp;
1145{
1146 if (entering(tcp)) {
1147 tprintf("%ld, ", tcp->u_arg[0]);
1148 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1149 tprintf(", %ld", tcp->u_arg[2]);
1150 /*
1151 * FIXME - dump out the list of aclent_t's pointed to
1152 * by "tcp->u_arg[3]" if it's not NULL.
1153 */
1154 if (tcp->u_arg[3])
1155 tprintf(", %#lx", tcp->u_arg[3]);
1156 else
1157 tprintf(", NULL");
1158 }
1159 return 0;
1160}
1161
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001162
1163struct xlat aclipc[] = {
1164#ifdef IPC_SHM
1165 { IPC_SHM, "IPC_SHM" },
1166#endif
1167#ifdef IPC_SEM
1168 { IPC_SEM, "IPC_SEM" },
1169#endif
1170#ifdef IPC_MSG
1171 { IPC_MSG, "IPC_MSG" },
1172#endif
1173 { 0, NULL },
1174};
1175
1176
1177int
1178sys_aclipc(tcp)
1179struct tcb *tcp;
1180{
1181 if (entering(tcp)) {
1182 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1183 tprintf(", %#lx, ", tcp->u_arg[1]);
1184 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1185 tprintf(", %ld", tcp->u_arg[3]);
1186 /*
1187 * FIXME - dump out the list of aclent_t's pointed to
1188 * by "tcp->u_arg[4]" if it's not NULL.
1189 */
1190 if (tcp->u_arg[4])
1191 tprintf(", %#lx", tcp->u_arg[4]);
1192 else
1193 tprintf(", NULL");
1194 }
1195 return 0;
1196}
1197
1198
1199
Wichert Akkerman8829a551999-06-11 13:18:40 +00001200#endif /* HAVE_SYS_ACL_H */
1201
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001202#endif /* SVR4 || LINUXSPARC */
1203
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001204#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001205
1206static struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001207 { 0x73757245, "CODA_SUPER_MAGIC" },
1208 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1209 { 0x1373, "DEVFS_SUPER_MAGIC" },
1210 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1211 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001212 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1213 { 0xef53, "EXT2_SUPER_MAGIC" },
1214 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001215 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001216 { 0x9660, "ISOFS_SUPER_MAGIC" },
1217 { 0x137f, "MINIX_SUPER_MAGIC" },
1218 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001219 { 0x2468, "MINIX2_SUPER_MAGIC" },
1220 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001221 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001222 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001223 { 0x6969, "NFS_SUPER_MAGIC" },
1224 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001225 { 0x002f, "QNX4_SUPER_MAGIC" },
1226 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1227 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1228 { 0x517b, "SMB_SUPER_MAGIC" },
1229 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1230 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1231 { 0x00011954, "UFS_MAGIC" },
1232 { 0x54190100, "UFS_CIGAM" },
1233 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001234 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
1235 { 0, NULL },
1236};
1237
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001238#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001239
1240#ifndef SVR4
1241
1242static char *
1243sprintfstype(magic)
1244int magic;
1245{
1246 static char buf[32];
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001247#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001248 char *s;
1249
1250 s = xlookup(fsmagic, magic);
1251 if (s) {
1252 sprintf(buf, "\"%s\"", s);
1253 return buf;
1254 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001255#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001256 sprintf(buf, "%#x", magic);
1257 return buf;
1258}
1259
1260static void
1261printstatfs(tcp, addr)
1262struct tcb *tcp;
1263long addr;
1264{
1265 struct statfs statbuf;
1266
1267 if (syserror(tcp) || !verbose(tcp)) {
1268 tprintf("%#lx", addr);
1269 return;
1270 }
1271 if (umove(tcp, addr, &statbuf) < 0) {
1272 tprintf("{...}");
1273 return;
1274 }
1275#ifdef ALPHA
1276
1277 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1278 sprintfstype(statbuf.f_type),
1279 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001280 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_namelen=%u",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001281 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree, statbuf.f_namelen);
1282#else /* !ALPHA */
1283 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1284 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001285 (unsigned long)statbuf.f_bsize,
1286 (unsigned long)statbuf.f_blocks,
1287 (unsigned long)statbuf.f_bfree);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001288 tprintf("f_files=%lu, f_ffree=%lu",
Nate Sammons5c74d201999-04-06 01:37:51 +00001289 (unsigned long)statbuf.f_files,
1290 (unsigned long)statbuf.f_ffree);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001291#ifdef linux
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001292 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001293#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001294#endif /* !ALPHA */
1295 tprintf("}");
1296}
1297
1298int
1299sys_statfs(tcp)
1300struct tcb *tcp;
1301{
1302 if (entering(tcp)) {
1303 printpath(tcp, tcp->u_arg[0]);
1304 tprintf(", ");
1305 } else {
1306 printstatfs(tcp, tcp->u_arg[1]);
1307 }
1308 return 0;
1309}
1310
1311int
1312sys_fstatfs(tcp)
1313struct tcb *tcp;
1314{
1315 if (entering(tcp)) {
1316 tprintf("%lu, ", tcp->u_arg[0]);
1317 } else {
1318 printstatfs(tcp, tcp->u_arg[1]);
1319 }
1320 return 0;
1321}
1322
Wichert Akkermana0f36c61999-04-16 14:01:34 +00001323#if defined(linux) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001324
1325int
1326osf_statfs(tcp)
1327struct tcb *tcp;
1328{
1329 if (entering(tcp)) {
1330 printpath(tcp, tcp->u_arg[0]);
1331 tprintf(", ");
1332 } else {
1333 printstatfs(tcp, tcp->u_arg[1]);
1334 tprintf(", %lu", tcp->u_arg[2]);
1335 }
1336 return 0;
1337}
1338
1339int
1340osf_fstatfs(tcp)
1341struct tcb *tcp;
1342{
1343 if (entering(tcp)) {
1344 tprintf("%lu, ", tcp->u_arg[0]);
1345 } else {
1346 printstatfs(tcp, tcp->u_arg[1]);
1347 tprintf(", %lu", tcp->u_arg[2]);
1348 }
1349 return 0;
1350}
Wichert Akkermana0f36c61999-04-16 14:01:34 +00001351#endif /* linux && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001352
1353#endif /* !SVR4 */
1354
1355#ifdef SUNOS4
1356
1357int
1358sys_ustat(tcp)
1359struct tcb *tcp;
1360{
1361 struct ustat statbuf;
1362
1363 if (entering(tcp)) {
1364 tprintf("makedev(%lu, %lu), ",
1365 (long) major(tcp->u_arg[0]),
1366 (long) minor(tcp->u_arg[0]));
1367 }
1368 else {
1369 if (syserror(tcp) || !verbose(tcp))
1370 tprintf("%#lx", tcp->u_arg[1]);
1371 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1372 tprintf("{...}");
1373 else {
1374 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1375 statbuf.f_tfree, statbuf.f_tinode);
1376 tprintf("f_fname=\"%.*s\", ",
1377 (int) sizeof(statbuf.f_fname),
1378 statbuf.f_fname);
1379 tprintf("f_fpack=\"%.*s\"}",
1380 (int) sizeof(statbuf.f_fpack),
1381 statbuf.f_fpack);
1382 }
1383 }
1384 return 0;
1385}
1386
1387#endif /* SUNOS4 */
1388
Wichert Akkermanc7926982000-04-10 22:22:31 +00001389int
1390sys_pivotroot(tcp)
1391struct tcb *tcp;
1392{
1393 if (entering(tcp)) {
1394 printpath(tcp, tcp->u_arg[0]);
1395 tprintf(", ");
1396 printpath(tcp, tcp->u_arg[1]);
1397 }
1398 return 0;
1399}
1400
1401
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001402/* directory */
1403int
1404sys_chdir(tcp)
1405struct tcb *tcp;
1406{
1407 if (entering(tcp)) {
1408 printpath(tcp, tcp->u_arg[0]);
1409 }
1410 return 0;
1411}
1412
1413int
1414sys_mkdir(tcp)
1415struct tcb *tcp;
1416{
1417 if (entering(tcp)) {
1418 printpath(tcp, tcp->u_arg[0]);
1419 tprintf(", %#lo", tcp->u_arg[1]);
1420 }
1421 return 0;
1422}
1423
1424int
1425sys_rmdir(tcp)
1426struct tcb *tcp;
1427{
1428 if (entering(tcp)) {
1429 printpath(tcp, tcp->u_arg[0]);
1430 }
1431 return 0;
1432}
1433
1434int
1435sys_fchdir(tcp)
1436struct tcb *tcp;
1437{
1438 if (entering(tcp)) {
1439 tprintf("%ld", tcp->u_arg[0]);
1440 }
1441 return 0;
1442}
1443
1444int
1445sys_chroot(tcp)
1446struct tcb *tcp;
1447{
1448 if (entering(tcp)) {
1449 printpath(tcp, tcp->u_arg[0]);
1450 }
1451 return 0;
1452}
1453
1454int
1455sys_fchroot(tcp)
1456struct tcb *tcp;
1457{
1458 if (entering(tcp)) {
1459 tprintf("%ld", tcp->u_arg[0]);
1460 }
1461 return 0;
1462}
1463
1464int
1465sys_link(tcp)
1466struct tcb *tcp;
1467{
1468 if (entering(tcp)) {
1469 printpath(tcp, tcp->u_arg[0]);
1470 tprintf(", ");
1471 printpath(tcp, tcp->u_arg[1]);
1472 }
1473 return 0;
1474}
1475
1476int
1477sys_unlink(tcp)
1478struct tcb *tcp;
1479{
1480 if (entering(tcp)) {
1481 printpath(tcp, tcp->u_arg[0]);
1482 }
1483 return 0;
1484}
1485
1486int
1487sys_symlink(tcp)
1488struct tcb *tcp;
1489{
1490 if (entering(tcp)) {
1491 printpath(tcp, tcp->u_arg[0]);
1492 tprintf(", ");
1493 printpath(tcp, tcp->u_arg[1]);
1494 }
1495 return 0;
1496}
1497
1498int
1499sys_readlink(tcp)
1500struct tcb *tcp;
1501{
1502 if (entering(tcp)) {
1503 printpath(tcp, tcp->u_arg[0]);
1504 tprintf(", ");
1505 } else {
1506 if (syserror(tcp))
1507 tprintf("%#lx", tcp->u_arg[1]);
1508 else
1509 printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
1510 tprintf(", %lu", tcp->u_arg[2]);
1511 }
1512 return 0;
1513}
1514
1515int
1516sys_rename(tcp)
1517struct tcb *tcp;
1518{
1519 if (entering(tcp)) {
1520 printpath(tcp, tcp->u_arg[0]);
1521 tprintf(", ");
1522 printpath(tcp, tcp->u_arg[1]);
1523 }
1524 return 0;
1525}
1526
1527int
1528sys_chown(tcp)
1529struct tcb *tcp;
1530{
1531 if (entering(tcp)) {
1532 printpath(tcp, tcp->u_arg[0]);
1533 tprintf(", %lu, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1534 }
1535 return 0;
1536}
1537
1538int
1539sys_fchown(tcp)
1540struct tcb *tcp;
1541{
1542 if (entering(tcp)) {
1543 tprintf("%ld, %lu, %lu",
1544 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1545 }
1546 return 0;
1547}
1548
1549int
1550sys_chmod(tcp)
1551struct tcb *tcp;
1552{
1553 if (entering(tcp)) {
1554 printpath(tcp, tcp->u_arg[0]);
1555 tprintf(", %#lo", tcp->u_arg[1]);
1556 }
1557 return 0;
1558}
1559
1560int
1561sys_fchmod(tcp)
1562struct tcb *tcp;
1563{
1564 if (entering(tcp)) {
1565 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
1566 }
1567 return 0;
1568}
1569
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001570#ifdef ALPHA
1571int
1572sys_osf_utimes(tcp)
1573struct tcb *tcp;
1574{
1575 if (entering(tcp)) {
1576 printpath(tcp, tcp->u_arg[0]);
1577 tprintf(", ");
1578 printtv32(tcp, tcp->u_arg[1]);
1579 }
1580 return 0;
1581}
1582#endif
1583
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001584int
1585sys_utimes(tcp)
1586struct tcb *tcp;
1587{
1588 if (entering(tcp)) {
1589 printpath(tcp, tcp->u_arg[0]);
1590 tprintf(", ");
1591 printtv(tcp, tcp->u_arg[1]);
1592 }
1593 return 0;
1594}
1595
1596int
1597sys_utime(tcp)
1598struct tcb *tcp;
1599{
1600 long ut[2];
1601
1602 if (entering(tcp)) {
1603 printpath(tcp, tcp->u_arg[0]);
1604 tprintf(", ");
1605 if (!tcp->u_arg[1])
1606 tprintf("NULL");
1607 else if (!verbose(tcp))
1608 tprintf("%#lx", tcp->u_arg[1]);
1609 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
1610 (char *) ut) < 0)
1611 tprintf("[?, ?]");
1612 else {
1613 tprintf("[%s,", sprinttime(ut[0]));
1614 tprintf(" %s]", sprinttime(ut[1]));
1615 }
1616 }
1617 return 0;
1618}
1619
1620int
1621sys_mknod(tcp)
1622struct tcb *tcp;
1623{
1624 int mode = tcp->u_arg[1];
1625
1626 if (entering(tcp)) {
1627 printpath(tcp, tcp->u_arg[0]);
1628 tprintf(", %s", sprintmode(mode));
1629 switch (mode & S_IFMT) {
1630 case S_IFCHR: case S_IFBLK:
1631#ifdef LINUXSPARC
1632 if (current_personality == 1)
1633 tprintf(", makedev(%lu, %lu)",
1634 (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
1635 (unsigned long) (tcp->u_arg[2] & 0x3ffff));
1636 else
1637#endif
1638 tprintf(", makedev(%lu, %lu)",
1639 (unsigned long) major(tcp->u_arg[2]),
1640 (unsigned long) minor(tcp->u_arg[2]));
1641 break;
1642 default:
1643 break;
1644 }
1645 }
1646 return 0;
1647}
1648
1649int
1650sys_mkfifo(tcp)
1651struct tcb *tcp;
1652{
1653 if (entering(tcp)) {
1654 printpath(tcp, tcp->u_arg[0]);
1655 tprintf(", %#lo", tcp->u_arg[1]);
1656 }
1657 return 0;
1658}
1659
1660int
1661sys_fsync(tcp)
1662struct tcb *tcp;
1663{
1664 if (entering(tcp)) {
1665 tprintf("%ld", tcp->u_arg[0]);
1666 }
1667 return 0;
1668}
1669
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001670#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001671
1672static void
1673printdir(tcp, addr)
1674struct tcb *tcp;
1675long addr;
1676{
1677 struct dirent d;
1678
1679 if (!verbose(tcp)) {
1680 tprintf("%#lx", addr);
1681 return;
1682 }
1683 if (umove(tcp, addr, &d) < 0) {
1684 tprintf("{...}");
1685 return;
1686 }
1687 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001688 tprintf("d_name=");
1689 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
1690 tprintf("}");
1691}
1692
1693int
1694sys_readdir(tcp)
1695struct tcb *tcp;
1696{
1697 if (entering(tcp)) {
1698 tprintf("%lu, ", tcp->u_arg[0]);
1699 } else {
1700 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
1701 tprintf("%#lx", tcp->u_arg[1]);
1702 else
1703 printdir(tcp, tcp->u_arg[1]);
1704 /* Not much point in printing this out, it is always 1. */
1705 if (tcp->u_arg[2] != 1)
1706 tprintf(", %lu", tcp->u_arg[2]);
1707 }
1708 return 0;
1709}
1710
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001711#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001712
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001713#ifdef FREEBSD
1714struct xlat direnttypes[] = {
1715 { DT_FIFO, "DT_FIFO" },
1716 { DT_CHR, "DT_CHR" },
1717 { DT_DIR, "DT_DIR" },
1718 { DT_BLK, "DT_BLK" },
1719 { DT_REG, "DT_REG" },
1720 { DT_LNK, "DT_LNK" },
1721 { DT_SOCK, "DT_SOCK" },
1722 { DT_WHT, "DT_WHT" },
1723 { 0, NULL },
1724};
1725
1726#endif
1727
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001728int
1729sys_getdents(tcp)
1730struct tcb *tcp;
1731{
1732 int i, len, dents = 0;
1733 char *buf;
1734
1735 if (entering(tcp)) {
1736 tprintf("%lu, ", tcp->u_arg[0]);
1737 return 0;
1738 }
1739 if (syserror(tcp) || !verbose(tcp)) {
1740 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1741 return 0;
1742 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001743 len = tcp->u_rval;
1744 if ((buf = malloc(len)) == NULL) {
1745 tprintf("out of memory\n");
1746 return 0;
1747 }
1748 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1749 tprintf("{...}, %lu", tcp->u_arg[2]);
1750 free(buf);
1751 return 0;
1752 }
1753 if (!abbrev(tcp))
1754 tprintf("{");
1755 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00001756 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001757#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001758 if (!abbrev(tcp)) {
1759 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1760 i ? " " : "", d->d_ino, d->d_off);
1761 tprintf("d_reclen=%u, d_name=\"%s\"}",
1762 d->d_reclen, d->d_name);
1763 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001764#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001765#ifdef SVR4
1766 if (!abbrev(tcp)) {
1767 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1768 i ? " " : "", d->d_ino, d->d_off);
1769 tprintf("d_reclen=%u, d_name=\"%s\"}",
1770 d->d_reclen, d->d_name);
1771 }
1772#endif /* SVR4 */
1773#ifdef SUNOS4
1774 if (!abbrev(tcp)) {
1775 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
1776 i ? " " : "", d->d_off, d->d_fileno,
1777 d->d_reclen);
1778 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
1779 d->d_namlen, d->d_namlen, d->d_name);
1780 }
1781#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001782#ifdef FREEBSD
1783 if (!abbrev(tcp)) {
1784 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
1785 i ? " " : "", d->d_fileno, d->d_reclen);
1786 printxval(direnttypes, d->d_type, "DT_???");
1787 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
1788 d->d_namlen, d->d_namlen, d->d_name);
1789 }
1790#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00001791 if (!d->d_reclen) {
1792 tprintf("/* d_reclen == 0, problem here */");
1793 break;
1794 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001795 i += d->d_reclen;
1796 dents++;
1797 }
1798 if (!abbrev(tcp))
1799 tprintf("}");
1800 else
1801 tprintf("/* %u entries */", dents);
1802 tprintf(", %lu", tcp->u_arg[2]);
1803 free(buf);
1804 return 0;
1805}
1806
John Hughesbdf48f52001-03-06 15:08:09 +00001807
1808#if _LFS64_LARGEFILE
1809int
1810sys_getdents64(tcp)
1811struct tcb *tcp;
1812{
1813 int i, len, dents = 0;
1814 char *buf;
1815
1816 if (entering(tcp)) {
1817 tprintf("%lu, ", tcp->u_arg[0]);
1818 return 0;
1819 }
1820 if (syserror(tcp) || !verbose(tcp)) {
1821 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1822 return 0;
1823 }
1824 len = tcp->u_rval;
1825 if ((buf = malloc(len)) == NULL) {
1826 tprintf("out of memory\n");
1827 return 0;
1828 }
1829 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1830 tprintf("{...}, %lu", tcp->u_arg[2]);
1831 free(buf);
1832 return 0;
1833 }
1834 if (!abbrev(tcp))
1835 tprintf("{");
1836 for (i = 0; i < len;) {
1837 struct dirent64 *d = (struct dirent64 *) &buf[i];
1838#ifdef linux
1839 if (!abbrev(tcp)) {
1840 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1841 i ? " " : "", d->d_ino, d->d_off);
1842 tprintf("d_reclen=%u, d_name=\"%s\"}",
1843 d->d_reclen, d->d_name);
1844 }
1845#endif /* linux */
1846#ifdef SVR4
1847 if (!abbrev(tcp)) {
1848 tprintf("%s{d_ino=%llu, d_off=%llu, ",
1849 i ? " " : "", d->d_ino, d->d_off);
1850 tprintf("d_reclen=%u, d_name=\"%s\"}",
1851 d->d_reclen, d->d_name);
1852 }
1853#endif /* SVR4 */
1854#ifdef SUNOS4
1855 if (!abbrev(tcp)) {
1856 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
1857 i ? " " : "", d->d_off, d->d_fileno,
1858 d->d_reclen);
1859 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
1860 d->d_namlen, d->d_namlen, d->d_name);
1861 }
1862#endif /* SUNOS4 */
1863 i += d->d_reclen;
1864 dents++;
1865 }
1866 if (!abbrev(tcp))
1867 tprintf("}");
1868 else
1869 tprintf("/* %u entries */", dents);
1870 tprintf(", %lu", tcp->u_arg[2]);
1871 free(buf);
1872 return 0;
1873}
1874#endif
1875
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001876#ifdef FREEBSD
1877int
1878sys_getdirentries(tcp)
1879struct tcb * tcp;
1880{
1881 int i, len, dents = 0;
1882 long basep;
1883 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001884
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001885 if (entering(tcp)) {
1886 tprintf("%lu, ", tcp->u_arg[0]);
1887 return 0;
1888 }
1889 if (syserror(tcp) || !verbose(tcp)) {
1890 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
1891 return 0;
1892 }
1893 len = tcp->u_rval;
1894 if ((buf = malloc(len)) == NULL) {
1895 tprintf("out of memory\n");
1896 return 0;
1897 }
1898 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1899 tprintf("{...}, %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3]);
1900 free(buf);
1901 return 0;
1902 }
1903 if (!abbrev(tcp))
1904 tprintf("{");
1905 for (i = 0; i < len;) {
1906 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
1907 if (!abbrev(tcp)) {
1908 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
1909 i ? " " : "", d->d_fileno, d->d_reclen);
1910 printxval(direnttypes, d->d_type, "DT_???");
1911 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
1912 d->d_namlen, d->d_namlen, d->d_name);
1913 }
1914 i += d->d_reclen;
1915 dents++;
1916 }
1917 if (!abbrev(tcp))
1918 tprintf("}");
1919 else
1920 tprintf("/* %u entries */", dents);
1921 free(buf);
1922 tprintf(", %lu", tcp->u_arg[2]);
1923 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
1924 tprintf(", %#lx", tcp->u_arg[3]);
1925 else
1926 tprintf(", [%lu]", basep);
1927 return 0;
1928}
1929#endif
1930
1931#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001932int
1933sys_getcwd(tcp)
1934struct tcb *tcp;
1935{
1936 if (exiting(tcp)) {
1937 if (syserror(tcp))
1938 tprintf("%#lx", tcp->u_arg[0]);
1939 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001940 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001941 tprintf(", %lu", tcp->u_arg[1]);
1942 }
1943 return 0;
1944}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001945#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001946
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001947#ifdef FREEBSD
1948int
1949sys___getcwd(tcp)
1950struct tcb *tcp;
1951{
1952 if (exiting(tcp)) {
1953 if (syserror(tcp))
1954 tprintf("%#lx", tcp->u_arg[0]);
1955 else
1956 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1957 tprintf(", %lu", tcp->u_arg[1]);
1958 }
1959 return 0;
1960}
1961#endif
1962
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001963#ifdef HAVE_SYS_ASYNCH_H
1964
1965int
1966sys_aioread(tcp)
1967struct tcb *tcp;
1968{
1969 struct aio_result_t res;
1970
1971 if (entering(tcp)) {
1972 tprintf("%lu, ", tcp->u_arg[0]);
1973 } else {
1974 if (syserror(tcp))
1975 tprintf("%#lx", tcp->u_arg[1]);
1976 else
1977 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1978 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
1979 printxval(whence, tcp->u_arg[4], "L_???");
1980 if (syserror(tcp) || tcp->u_arg[5] == 0
1981 || umove(tcp, tcp->u_arg[5], &res) < 0)
1982 tprintf(", %#lx", tcp->u_arg[5]);
1983 else
1984 tprintf(", {aio_return %d aio_errno %d}",
1985 res.aio_return, res.aio_errno);
1986 }
1987 return 0;
1988}
1989
1990int
1991sys_aiowrite(tcp)
1992struct tcb *tcp;
1993{
1994 struct aio_result_t res;
1995
1996 if (entering(tcp)) {
1997 tprintf("%lu, ", tcp->u_arg[0]);
1998 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1999 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2000 printxval(whence, tcp->u_arg[4], "L_???");
2001 }
2002 else {
2003 if (tcp->u_arg[5] == 0)
2004 tprintf(", NULL");
2005 else if (syserror(tcp)
2006 || umove(tcp, tcp->u_arg[5], &res) < 0)
2007 tprintf(", %#lx", tcp->u_arg[5]);
2008 else
2009 tprintf(", {aio_return %d aio_errno %d}",
2010 res.aio_return, res.aio_errno);
2011 }
2012 return 0;
2013}
2014
2015int
2016sys_aiowait(tcp)
2017struct tcb *tcp;
2018{
2019 if (entering(tcp))
2020 printtv(tcp, tcp->u_arg[0]);
2021 return 0;
2022}
2023
2024int
2025sys_aiocancel(tcp)
2026struct tcb *tcp;
2027{
2028 struct aio_result_t res;
2029
2030 if (exiting(tcp)) {
2031 if (tcp->u_arg[0] == 0)
2032 tprintf("NULL");
2033 else if (syserror(tcp)
2034 || umove(tcp, tcp->u_arg[0], &res) < 0)
2035 tprintf("%#lx", tcp->u_arg[0]);
2036 else
2037 tprintf("{aio_return %d aio_errno %d}",
2038 res.aio_return, res.aio_errno);
2039 }
2040 return 0;
2041}
2042
2043#endif /* HAVE_SYS_ASYNCH_H */