blob: 090d78d05d694db3e447a4be7f43e9f164290d73 [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 Hughes96f51472001-03-06 16:50:41 +0000414#if _LFS64_LARGEFILE
John Hughesbdf48f52001-03-06 15:08:09 +0000415int
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
John Hughes96f51472001-03-06 16:50:41 +0000446#if _LFS64_LARGEFILE
447int
448sys_truncate64(tcp)
449struct tcb *tcp;
450{
451 if (entering(tcp)) {
452 printpath(tcp, tcp->u_arg[0]);
453 tprintf(", %llu", get64(tcp->u_arg[1],tcp->u_arg[2]));
454 }
455 return 0;
456}
457#endif
458
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000459int
460sys_ftruncate(tcp)
461struct tcb *tcp;
462{
463 if (entering(tcp)) {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000464#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000465 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000466#else
467 tprintf("%ld, %llu", tcp->u_arg[0],
468 ((off_t) tcp->u_arg[1] << 32) + tcp->u_arg[2]);
469#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000470 }
471 return 0;
472}
473
John Hughes96f51472001-03-06 16:50:41 +0000474#if _LFS64_LARGEFILE
475int
476sys_ftruncate64(tcp)
477struct tcb *tcp;
478{
479 if (entering(tcp)) {
480 tprintf("%ld, %llu", tcp->u_arg[0],
481 get64(tcp->u_arg[1] ,tcp->u_arg[2]));
482 }
483 return 0;
484}
485#endif
486
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000487/* several stats */
488
489static struct xlat modetypes[] = {
490 { S_IFREG, "S_IFREG" },
491 { S_IFSOCK, "S_IFSOCK" },
492 { S_IFIFO, "S_IFIFO" },
493 { S_IFLNK, "S_IFLNK" },
494 { S_IFDIR, "S_IFDIR" },
495 { S_IFBLK, "S_IFBLK" },
496 { S_IFCHR, "S_IFCHR" },
497 { 0, NULL },
498};
499
500static char *
501sprintmode(mode)
502int mode;
503{
504 static char buf[64];
505 char *s;
506
507 if ((mode & S_IFMT) == 0)
508 s = "";
509 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
510 sprintf(buf, "%#o", mode);
511 return buf;
512 }
513 sprintf(buf, "%s%s%s%s", s,
514 (mode & S_ISUID) ? "|S_ISUID" : "",
515 (mode & S_ISGID) ? "|S_ISGID" : "",
516 (mode & S_ISVTX) ? "|S_ISVTX" : "");
517 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
518 if (mode)
519 sprintf(buf + strlen(buf), "|%#o", mode);
520 s = (*buf == '|') ? buf + 1 : buf;
521 return *s ? s : "0";
522}
523
524static char *
525sprinttime(t)
526time_t t;
527{
528 struct tm *tmp;
529 static char buf[32];
530
531 if (t == 0) {
532 sprintf(buf, "0");
533 return buf;
534 }
535 tmp = localtime(&t);
536 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
Wichert Akkerman3ed6dc22000-01-11 14:41:09 +0000537 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000538 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
539 return buf;
540}
541
542#ifdef LINUXSPARC
543typedef struct {
544 int tv_sec;
545 int tv_nsec;
546} timestruct_t;
547
548struct solstat {
549 unsigned st_dev;
550 int st_pad1[3]; /* network id */
551 unsigned st_ino;
552 unsigned st_mode;
553 unsigned st_nlink;
554 unsigned st_uid;
555 unsigned st_gid;
556 unsigned st_rdev;
557 int st_pad2[2];
558 int st_size;
559 int st_pad3; /* st_size, off_t expansion */
560 timestruct_t st_atime;
561 timestruct_t st_mtime;
562 timestruct_t st_ctime;
563 int st_blksize;
564 int st_blocks;
565 char st_fstype[16];
566 int st_pad4[8]; /* expansion area */
567};
568
569static void
570printstatsol(tcp, addr)
571struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000572long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000573{
574 struct solstat statbuf;
575
576 if (!addr) {
577 tprintf("NULL");
578 return;
579 }
580 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000581 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000582 return;
583 }
584 if (umove(tcp, addr, &statbuf) < 0) {
585 tprintf("{...}");
586 return;
587 }
588 if (!abbrev(tcp)) {
589 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
590 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
591 (unsigned long) (statbuf.st_dev & 0x3ffff),
592 (unsigned long) statbuf.st_ino,
593 sprintmode(statbuf.st_mode));
594 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
595 (unsigned long) statbuf.st_nlink,
596 (unsigned long) statbuf.st_uid,
597 (unsigned long) statbuf.st_gid);
598 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
599 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
600 }
601 else
602 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
603 switch (statbuf.st_mode & S_IFMT) {
604 case S_IFCHR: case S_IFBLK:
605 tprintf("st_rdev=makedev(%lu, %lu), ",
606 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
607 (unsigned long) (statbuf.st_rdev & 0x3ffff));
608 break;
609 default:
610 tprintf("st_size=%u, ", statbuf.st_size);
611 break;
612 }
613 if (!abbrev(tcp)) {
614 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
615 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
616 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
617 }
618 else
619 tprintf("...}");
620}
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000621#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000622
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000623#ifdef FREEBSD
624static struct xlat fileflags[] = {
625 { UF_NODUMP, "UF_NODUMP" },
626 { UF_IMMUTABLE, "UF_IMMUTABLE" },
627 { UF_APPEND, "UF_APPEND" },
628 { UF_OPAQUE, "UF_OPAQUE" },
629 { UF_NOUNLINK, "UF_NOUNLINK" },
630 { SF_ARCHIVED, "SF_ARCHIVED" },
631 { SF_IMMUTABLE, "SF_IMMUTABLE" },
632 { SF_APPEND, "SF_APPEND" },
633 { SF_NOUNLINK, "SF_NOUNLINK" },
634 { 0, NULL },
635};
636
637int
638sys_chflags(tcp)
639struct tcb *tcp;
640{
641 if (entering(tcp)) {
642 printpath(tcp, tcp->u_arg[0]);
643 tprintf(", ");
644 if (tcp->u_arg[1])
645 printflags(fileflags, tcp->u_arg[1]);
646 else
647 tprintf("0");
648 }
649 return 0;
650}
651
652int
653sys_fchflags(tcp)
654struct tcb *tcp;
655{
656 if (entering(tcp)) {
657 tprintf("%ld, ", tcp->u_arg[0]);
658 if (tcp->u_arg[1])
659 printflags(fileflags, tcp->u_arg[1]);
660 else
661 tprintf("0");
662 }
663 return 0;
664}
665#endif
666
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000667static void
668realprintstat(tcp, statbuf)
669struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000670struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000671{
672 if (!abbrev(tcp)) {
673 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
674 (unsigned long) major(statbuf->st_dev),
675 (unsigned long) minor(statbuf->st_dev),
676 (unsigned long) statbuf->st_ino,
677 sprintmode(statbuf->st_mode));
678 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
679 (unsigned long) statbuf->st_nlink,
680 (unsigned long) statbuf->st_uid,
681 (unsigned long) statbuf->st_gid);
682#ifdef HAVE_ST_BLKSIZE
683 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
684#endif /* HAVE_ST_BLKSIZE */
685#ifdef HAVE_ST_BLOCKS
686 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
687#endif /* HAVE_ST_BLOCKS */
688 }
689 else
690 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
691 switch (statbuf->st_mode & S_IFMT) {
692 case S_IFCHR: case S_IFBLK:
693#ifdef HAVE_ST_RDEV
694 tprintf("st_rdev=makedev(%lu, %lu), ",
695 (unsigned long) major(statbuf->st_rdev),
696 (unsigned long) minor(statbuf->st_rdev));
697#else /* !HAVE_ST_RDEV */
698 tprintf("st_size=makedev(%lu, %lu), ",
699 (unsigned long) major(statbuf->st_size),
700 (unsigned long) minor(statbuf->st_size));
701#endif /* !HAVE_ST_RDEV */
702 break;
703 default:
704 tprintf("st_size=%lu, ", statbuf->st_size);
705 break;
706 }
707 if (!abbrev(tcp)) {
708 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
709 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000710#ifndef FREEBSD
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000711 tprintf("st_ctime=%s}", sprinttime(statbuf->st_ctime));
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000712#else /* FREEBSD */
713 tprintf("st_ctime=%s, ", sprinttime(statbuf->st_ctime));
714 tprintf("st_flags=");
715 if (statbuf->st_flags) {
716 printflags(fileflags, statbuf->st_flags);
717 } else
718 tprintf("0");
719 tprintf(", st_gen=%u}", statbuf->st_gen);
720#endif /* FREEBSD */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000721 }
722 else
723 tprintf("...}");
724}
725
Nate Sammons771a6ff1999-04-05 22:39:31 +0000726
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000727static void
728printstat(tcp, addr)
729struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000730long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000731{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000732 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000733
734#ifdef LINUXSPARC
735 if (current_personality == 1) {
736 printstatsol(tcp, addr);
737 return;
738 }
739#endif /* LINUXSPARC */
740
741 if (!addr) {
742 tprintf("NULL");
743 return;
744 }
745 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000746 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000747 return;
748 }
749 if (umove(tcp, addr, &statbuf) < 0) {
750 tprintf("{...}");
751 return;
752 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000753
754 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000755}
756
Wichert Akkermanc7926982000-04-10 22:22:31 +0000757#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000758static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000759printstat64(tcp, addr)
760struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000761long addr;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000762{
763 struct stat64 statbuf;
764
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);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000778 return;
779 }
780 if (umove(tcp, addr, &statbuf) < 0) {
781 tprintf("{...}");
782 return;
783 }
784
785 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +0000786#ifdef HAVE_LONG_LONG
787 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
788#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000789 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +0000790#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000791 (unsigned long) major(statbuf.st_dev),
792 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +0000793#ifdef HAVE_LONG_LONG
794 (unsigned long long) statbuf.st_ino,
795#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000796 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +0000797#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000798 sprintmode(statbuf.st_mode));
799 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
800 (unsigned long) statbuf.st_nlink,
801 (unsigned long) statbuf.st_uid,
802 (unsigned long) statbuf.st_gid);
803#ifdef HAVE_ST_BLKSIZE
804 tprintf("st_blksize=%lu, ",
805 (unsigned long) statbuf.st_blksize);
806#endif /* HAVE_ST_BLKSIZE */
807#ifdef HAVE_ST_BLOCKS
808 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
809#endif /* HAVE_ST_BLOCKS */
810 }
811 else
812 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
813 switch (statbuf.st_mode & S_IFMT) {
814 case S_IFCHR: case S_IFBLK:
815#ifdef HAVE_ST_RDEV
816 tprintf("st_rdev=makedev(%lu, %lu), ",
817 (unsigned long) major(statbuf.st_rdev),
818 (unsigned long) minor(statbuf.st_rdev));
819#else /* !HAVE_ST_RDEV */
820 tprintf("st_size=makedev(%lu, %lu), ",
821 (unsigned long) major(statbuf.st_size),
822 (unsigned long) minor(statbuf.st_size));
823#endif /* !HAVE_ST_RDEV */
824 break;
825 default:
826 tprintf("st_size=%llu, ", statbuf.st_size);
827 break;
828 }
829 if (!abbrev(tcp)) {
830 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
831 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
832 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
833 }
834 else
835 tprintf("...}");
836}
Wichert Akkermanc7926982000-04-10 22:22:31 +0000837#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000838
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000839#if defined(linux) && !defined(IA64)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000840static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000841convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000842const struct __old_kernel_stat *oldbuf;
843struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000844{
845 newbuf->st_dev=oldbuf->st_dev;
846 newbuf->st_ino=oldbuf->st_ino;
847 newbuf->st_mode=oldbuf->st_mode;
848 newbuf->st_nlink=oldbuf->st_nlink;
849 newbuf->st_uid=oldbuf->st_uid;
850 newbuf->st_gid=oldbuf->st_gid;
851 newbuf->st_rdev=oldbuf->st_rdev;
852 newbuf->st_size=oldbuf->st_size;
853 newbuf->st_atime=oldbuf->st_atime;
854 newbuf->st_mtime=oldbuf->st_mtime;
855 newbuf->st_ctime=oldbuf->st_ctime;
856 newbuf->st_blksize=0; /* not supported in old_stat */
857 newbuf->st_blocks=0; /* not supported in old_stat */
858}
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000859
860
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000861static void
862printoldstat(tcp, addr)
863struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000864long addr;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000865{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000866 struct __old_kernel_stat statbuf;
867 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000868
869#ifdef LINUXSPARC
870 if (current_personality == 1) {
871 printstatsol(tcp, addr);
872 return;
873 }
874#endif /* LINUXSPARC */
875
876 if (!addr) {
877 tprintf("NULL");
878 return;
879 }
880 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000881 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000882 return;
883 }
884 if (umove(tcp, addr, &statbuf) < 0) {
885 tprintf("{...}");
886 return;
887 }
888
889 convertoldstat(&statbuf, &newstatbuf);
890 realprintstat(tcp, &newstatbuf);
891}
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000892#endif /* linux && !IA64 */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000893
894
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000895int
896sys_stat(tcp)
897struct tcb *tcp;
898{
899 if (entering(tcp)) {
900 printpath(tcp, tcp->u_arg[0]);
901 tprintf(", ");
902 } else {
903 printstat(tcp, tcp->u_arg[1]);
904 }
905 return 0;
906}
907
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000908#ifdef linux
909int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000910sys_stat64(tcp)
911struct tcb *tcp;
912{
913#ifdef HAVE_STAT64
914 if (entering(tcp)) {
915 printpath(tcp, tcp->u_arg[0]);
916 tprintf(", ");
917 } else {
918 printstat64(tcp, tcp->u_arg[1]);
919 }
920 return 0;
921#else
922 return printargs(tcp);
923#endif
924}
925
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000926# if !defined(IA64)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000927int
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000928sys_oldstat(tcp)
929struct tcb *tcp;
930{
931 if (entering(tcp)) {
932 printpath(tcp, tcp->u_arg[0]);
933 tprintf(", ");
934 } else {
935 printoldstat(tcp, tcp->u_arg[1]);
936 }
937 return 0;
938}
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000939# endif /* !IA64 */
940#endif /* linux */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000941
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000942int
943sys_fstat(tcp)
944struct tcb *tcp;
945{
946 if (entering(tcp))
947 tprintf("%ld, ", tcp->u_arg[0]);
948 else {
949 printstat(tcp, tcp->u_arg[1]);
950 }
951 return 0;
952}
953
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000954#ifdef linux
955int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000956sys_fstat64(tcp)
957struct tcb *tcp;
958{
959#ifdef HAVE_STAT64
960 if (entering(tcp))
961 tprintf("%ld, ", tcp->u_arg[0]);
962 else {
963 printstat64(tcp, tcp->u_arg[1]);
964 }
965 return 0;
966#else
967 return printargs(tcp);
968#endif
969}
970
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000971# if !defined(IA64)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000972int
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000973sys_oldfstat(tcp)
974struct tcb *tcp;
975{
976 if (entering(tcp))
977 tprintf("%ld, ", tcp->u_arg[0]);
978 else {
979 printoldstat(tcp, tcp->u_arg[1]);
980 }
981 return 0;
982}
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000983# endif /* !IA64 */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000984#endif
985
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000986int
987sys_lstat(tcp)
988struct tcb *tcp;
989{
990 if (entering(tcp)) {
991 printpath(tcp, tcp->u_arg[0]);
992 tprintf(", ");
993 } else {
994 printstat(tcp, tcp->u_arg[1]);
995 }
996 return 0;
997}
998
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000999#ifdef linux
1000int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001001sys_lstat64(tcp)
1002struct tcb *tcp;
1003{
1004#ifdef HAVE_STAT64
1005 if (entering(tcp)) {
1006 printpath(tcp, tcp->u_arg[0]);
1007 tprintf(", ");
1008 } else {
1009 printstat64(tcp, tcp->u_arg[1]);
1010 }
1011 return 0;
1012#else
1013 return printargs(tcp);
1014#endif
1015}
1016
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001017# if !defined(IA64)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001018int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001019sys_oldlstat(tcp)
1020struct tcb *tcp;
1021{
1022 if (entering(tcp)) {
1023 printpath(tcp, tcp->u_arg[0]);
1024 tprintf(", ");
1025 } else {
1026 printoldstat(tcp, tcp->u_arg[1]);
1027 }
1028 return 0;
1029}
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001030# endif /* !IA64 */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001031#endif
1032
1033
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001034#if defined(SVR4) || defined(LINUXSPARC)
1035
1036int
1037sys_xstat(tcp)
1038struct tcb *tcp;
1039{
1040 if (entering(tcp)) {
1041 tprintf("%ld, ", tcp->u_arg[0]);
1042 printpath(tcp, tcp->u_arg[1]);
1043 tprintf(", ");
1044 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001045#ifdef _STAT64_VER
1046 if (tcp->u_arg[0] == _STAT64_VER)
1047 printstat64 (tcp, tcp->u_arg[2]);
1048 else
1049#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001050 printstat(tcp, tcp->u_arg[2]);
1051 }
1052 return 0;
1053}
1054
1055int
1056sys_fxstat(tcp)
1057struct tcb *tcp;
1058{
1059 if (entering(tcp))
1060 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1061 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001062#ifdef _STAT64_VER
1063 if (tcp->u_arg[0] == _STAT64_VER)
1064 printstat64 (tcp, tcp->u_arg[2]);
1065 else
1066#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001067 printstat(tcp, tcp->u_arg[2]);
1068 }
1069 return 0;
1070}
1071
1072int
1073sys_lxstat(tcp)
1074struct tcb *tcp;
1075{
1076 if (entering(tcp)) {
1077 tprintf("%ld, ", tcp->u_arg[0]);
1078 printpath(tcp, tcp->u_arg[1]);
1079 tprintf(", ");
1080 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001081#ifdef _STAT64_VER
1082 if (tcp->u_arg[0] == _STAT64_VER)
1083 printstat64 (tcp, tcp->u_arg[2]);
1084 else
1085#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001086 printstat(tcp, tcp->u_arg[2]);
1087 }
1088 return 0;
1089}
1090
1091int
1092sys_xmknod(tcp)
1093struct tcb *tcp;
1094{
1095 int mode = tcp->u_arg[2];
1096
1097 if (entering(tcp)) {
1098 tprintf("%ld, ", tcp->u_arg[0]);
1099 printpath(tcp, tcp->u_arg[1]);
1100 tprintf(", %s", sprintmode(mode));
1101 switch (mode & S_IFMT) {
1102 case S_IFCHR: case S_IFBLK:
1103#ifdef LINUXSPARC
1104 tprintf(", makedev(%lu, %lu)",
1105 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1106 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1107#else
1108 tprintf(", makedev(%lu, %lu)",
1109 (unsigned long) major(tcp->u_arg[3]),
1110 (unsigned long) minor(tcp->u_arg[3]));
1111#endif
1112 break;
1113 default:
1114 break;
1115 }
1116 }
1117 return 0;
1118}
1119
Wichert Akkerman8829a551999-06-11 13:18:40 +00001120#ifdef HAVE_SYS_ACL_H
1121
1122#include <sys/acl.h>
1123
1124struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001125#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001126 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001127#endif
1128#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001129 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001130#endif
1131#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001132 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001133#endif
1134#ifdef ACL_GET
1135 { ACL_GET, "ACL_GET" },
1136#endif
1137#ifdef ACL_SET
1138 { ACL_SET, "ACL_SET" },
1139#endif
1140#ifdef ACL_CNT
1141 { ACL_CNT, "ACL_CNT" },
1142#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001143 { 0, NULL },
1144};
1145
1146int
1147sys_acl(tcp)
1148struct tcb *tcp;
1149{
1150 if (entering(tcp)) {
1151 printpath(tcp, tcp->u_arg[0]);
1152 tprintf(", ");
1153 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1154 tprintf(", %ld", tcp->u_arg[2]);
1155 /*
1156 * FIXME - dump out the list of aclent_t's pointed to
1157 * by "tcp->u_arg[3]" if it's not NULL.
1158 */
1159 if (tcp->u_arg[3])
1160 tprintf(", %#lx", tcp->u_arg[3]);
1161 else
1162 tprintf(", NULL");
1163 }
1164 return 0;
1165}
1166
1167
1168int
1169sys_facl(tcp)
1170struct tcb *tcp;
1171{
1172 if (entering(tcp)) {
1173 tprintf("%ld, ", tcp->u_arg[0]);
1174 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1175 tprintf(", %ld", tcp->u_arg[2]);
1176 /*
1177 * FIXME - dump out the list of aclent_t's pointed to
1178 * by "tcp->u_arg[3]" if it's not NULL.
1179 */
1180 if (tcp->u_arg[3])
1181 tprintf(", %#lx", tcp->u_arg[3]);
1182 else
1183 tprintf(", NULL");
1184 }
1185 return 0;
1186}
1187
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001188
1189struct xlat aclipc[] = {
1190#ifdef IPC_SHM
1191 { IPC_SHM, "IPC_SHM" },
1192#endif
1193#ifdef IPC_SEM
1194 { IPC_SEM, "IPC_SEM" },
1195#endif
1196#ifdef IPC_MSG
1197 { IPC_MSG, "IPC_MSG" },
1198#endif
1199 { 0, NULL },
1200};
1201
1202
1203int
1204sys_aclipc(tcp)
1205struct tcb *tcp;
1206{
1207 if (entering(tcp)) {
1208 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1209 tprintf(", %#lx, ", tcp->u_arg[1]);
1210 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1211 tprintf(", %ld", tcp->u_arg[3]);
1212 /*
1213 * FIXME - dump out the list of aclent_t's pointed to
1214 * by "tcp->u_arg[4]" if it's not NULL.
1215 */
1216 if (tcp->u_arg[4])
1217 tprintf(", %#lx", tcp->u_arg[4]);
1218 else
1219 tprintf(", NULL");
1220 }
1221 return 0;
1222}
1223
1224
1225
Wichert Akkerman8829a551999-06-11 13:18:40 +00001226#endif /* HAVE_SYS_ACL_H */
1227
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001228#endif /* SVR4 || LINUXSPARC */
1229
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001230#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001231
1232static struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001233 { 0x73757245, "CODA_SUPER_MAGIC" },
1234 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1235 { 0x1373, "DEVFS_SUPER_MAGIC" },
1236 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1237 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001238 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1239 { 0xef53, "EXT2_SUPER_MAGIC" },
1240 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001241 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001242 { 0x9660, "ISOFS_SUPER_MAGIC" },
1243 { 0x137f, "MINIX_SUPER_MAGIC" },
1244 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001245 { 0x2468, "MINIX2_SUPER_MAGIC" },
1246 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001247 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001248 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001249 { 0x6969, "NFS_SUPER_MAGIC" },
1250 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001251 { 0x002f, "QNX4_SUPER_MAGIC" },
1252 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1253 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1254 { 0x517b, "SMB_SUPER_MAGIC" },
1255 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1256 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1257 { 0x00011954, "UFS_MAGIC" },
1258 { 0x54190100, "UFS_CIGAM" },
1259 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001260 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
1261 { 0, NULL },
1262};
1263
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001264#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001265
1266#ifndef SVR4
1267
1268static char *
1269sprintfstype(magic)
1270int magic;
1271{
1272 static char buf[32];
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001273#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001274 char *s;
1275
1276 s = xlookup(fsmagic, magic);
1277 if (s) {
1278 sprintf(buf, "\"%s\"", s);
1279 return buf;
1280 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001281#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001282 sprintf(buf, "%#x", magic);
1283 return buf;
1284}
1285
1286static void
1287printstatfs(tcp, addr)
1288struct tcb *tcp;
1289long addr;
1290{
1291 struct statfs statbuf;
1292
1293 if (syserror(tcp) || !verbose(tcp)) {
1294 tprintf("%#lx", addr);
1295 return;
1296 }
1297 if (umove(tcp, addr, &statbuf) < 0) {
1298 tprintf("{...}");
1299 return;
1300 }
1301#ifdef ALPHA
1302
1303 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1304 sprintfstype(statbuf.f_type),
1305 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001306 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_namelen=%u",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001307 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree, statbuf.f_namelen);
1308#else /* !ALPHA */
1309 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1310 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001311 (unsigned long)statbuf.f_bsize,
1312 (unsigned long)statbuf.f_blocks,
1313 (unsigned long)statbuf.f_bfree);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001314 tprintf("f_files=%lu, f_ffree=%lu",
Nate Sammons5c74d201999-04-06 01:37:51 +00001315 (unsigned long)statbuf.f_files,
1316 (unsigned long)statbuf.f_ffree);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001317#ifdef linux
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001318 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001319#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001320#endif /* !ALPHA */
1321 tprintf("}");
1322}
1323
1324int
1325sys_statfs(tcp)
1326struct tcb *tcp;
1327{
1328 if (entering(tcp)) {
1329 printpath(tcp, tcp->u_arg[0]);
1330 tprintf(", ");
1331 } else {
1332 printstatfs(tcp, tcp->u_arg[1]);
1333 }
1334 return 0;
1335}
1336
1337int
1338sys_fstatfs(tcp)
1339struct tcb *tcp;
1340{
1341 if (entering(tcp)) {
1342 tprintf("%lu, ", tcp->u_arg[0]);
1343 } else {
1344 printstatfs(tcp, tcp->u_arg[1]);
1345 }
1346 return 0;
1347}
1348
Wichert Akkermana0f36c61999-04-16 14:01:34 +00001349#if defined(linux) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001350
1351int
1352osf_statfs(tcp)
1353struct tcb *tcp;
1354{
1355 if (entering(tcp)) {
1356 printpath(tcp, tcp->u_arg[0]);
1357 tprintf(", ");
1358 } else {
1359 printstatfs(tcp, tcp->u_arg[1]);
1360 tprintf(", %lu", tcp->u_arg[2]);
1361 }
1362 return 0;
1363}
1364
1365int
1366osf_fstatfs(tcp)
1367struct tcb *tcp;
1368{
1369 if (entering(tcp)) {
1370 tprintf("%lu, ", tcp->u_arg[0]);
1371 } else {
1372 printstatfs(tcp, tcp->u_arg[1]);
1373 tprintf(", %lu", tcp->u_arg[2]);
1374 }
1375 return 0;
1376}
Wichert Akkermana0f36c61999-04-16 14:01:34 +00001377#endif /* linux && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001378
1379#endif /* !SVR4 */
1380
1381#ifdef SUNOS4
1382
1383int
1384sys_ustat(tcp)
1385struct tcb *tcp;
1386{
1387 struct ustat statbuf;
1388
1389 if (entering(tcp)) {
1390 tprintf("makedev(%lu, %lu), ",
1391 (long) major(tcp->u_arg[0]),
1392 (long) minor(tcp->u_arg[0]));
1393 }
1394 else {
1395 if (syserror(tcp) || !verbose(tcp))
1396 tprintf("%#lx", tcp->u_arg[1]);
1397 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1398 tprintf("{...}");
1399 else {
1400 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1401 statbuf.f_tfree, statbuf.f_tinode);
1402 tprintf("f_fname=\"%.*s\", ",
1403 (int) sizeof(statbuf.f_fname),
1404 statbuf.f_fname);
1405 tprintf("f_fpack=\"%.*s\"}",
1406 (int) sizeof(statbuf.f_fpack),
1407 statbuf.f_fpack);
1408 }
1409 }
1410 return 0;
1411}
1412
1413#endif /* SUNOS4 */
1414
Wichert Akkermanc7926982000-04-10 22:22:31 +00001415int
1416sys_pivotroot(tcp)
1417struct tcb *tcp;
1418{
1419 if (entering(tcp)) {
1420 printpath(tcp, tcp->u_arg[0]);
1421 tprintf(", ");
1422 printpath(tcp, tcp->u_arg[1]);
1423 }
1424 return 0;
1425}
1426
1427
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001428/* directory */
1429int
1430sys_chdir(tcp)
1431struct tcb *tcp;
1432{
1433 if (entering(tcp)) {
1434 printpath(tcp, tcp->u_arg[0]);
1435 }
1436 return 0;
1437}
1438
1439int
1440sys_mkdir(tcp)
1441struct tcb *tcp;
1442{
1443 if (entering(tcp)) {
1444 printpath(tcp, tcp->u_arg[0]);
1445 tprintf(", %#lo", tcp->u_arg[1]);
1446 }
1447 return 0;
1448}
1449
1450int
1451sys_rmdir(tcp)
1452struct tcb *tcp;
1453{
1454 if (entering(tcp)) {
1455 printpath(tcp, tcp->u_arg[0]);
1456 }
1457 return 0;
1458}
1459
1460int
1461sys_fchdir(tcp)
1462struct tcb *tcp;
1463{
1464 if (entering(tcp)) {
1465 tprintf("%ld", tcp->u_arg[0]);
1466 }
1467 return 0;
1468}
1469
1470int
1471sys_chroot(tcp)
1472struct tcb *tcp;
1473{
1474 if (entering(tcp)) {
1475 printpath(tcp, tcp->u_arg[0]);
1476 }
1477 return 0;
1478}
1479
1480int
1481sys_fchroot(tcp)
1482struct tcb *tcp;
1483{
1484 if (entering(tcp)) {
1485 tprintf("%ld", tcp->u_arg[0]);
1486 }
1487 return 0;
1488}
1489
1490int
1491sys_link(tcp)
1492struct tcb *tcp;
1493{
1494 if (entering(tcp)) {
1495 printpath(tcp, tcp->u_arg[0]);
1496 tprintf(", ");
1497 printpath(tcp, tcp->u_arg[1]);
1498 }
1499 return 0;
1500}
1501
1502int
1503sys_unlink(tcp)
1504struct tcb *tcp;
1505{
1506 if (entering(tcp)) {
1507 printpath(tcp, tcp->u_arg[0]);
1508 }
1509 return 0;
1510}
1511
1512int
1513sys_symlink(tcp)
1514struct tcb *tcp;
1515{
1516 if (entering(tcp)) {
1517 printpath(tcp, tcp->u_arg[0]);
1518 tprintf(", ");
1519 printpath(tcp, tcp->u_arg[1]);
1520 }
1521 return 0;
1522}
1523
1524int
1525sys_readlink(tcp)
1526struct tcb *tcp;
1527{
1528 if (entering(tcp)) {
1529 printpath(tcp, tcp->u_arg[0]);
1530 tprintf(", ");
1531 } else {
1532 if (syserror(tcp))
1533 tprintf("%#lx", tcp->u_arg[1]);
1534 else
1535 printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
1536 tprintf(", %lu", tcp->u_arg[2]);
1537 }
1538 return 0;
1539}
1540
1541int
1542sys_rename(tcp)
1543struct tcb *tcp;
1544{
1545 if (entering(tcp)) {
1546 printpath(tcp, tcp->u_arg[0]);
1547 tprintf(", ");
1548 printpath(tcp, tcp->u_arg[1]);
1549 }
1550 return 0;
1551}
1552
1553int
1554sys_chown(tcp)
1555struct tcb *tcp;
1556{
1557 if (entering(tcp)) {
1558 printpath(tcp, tcp->u_arg[0]);
1559 tprintf(", %lu, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1560 }
1561 return 0;
1562}
1563
1564int
1565sys_fchown(tcp)
1566struct tcb *tcp;
1567{
1568 if (entering(tcp)) {
1569 tprintf("%ld, %lu, %lu",
1570 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1571 }
1572 return 0;
1573}
1574
1575int
1576sys_chmod(tcp)
1577struct tcb *tcp;
1578{
1579 if (entering(tcp)) {
1580 printpath(tcp, tcp->u_arg[0]);
1581 tprintf(", %#lo", tcp->u_arg[1]);
1582 }
1583 return 0;
1584}
1585
1586int
1587sys_fchmod(tcp)
1588struct tcb *tcp;
1589{
1590 if (entering(tcp)) {
1591 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
1592 }
1593 return 0;
1594}
1595
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001596#ifdef ALPHA
1597int
1598sys_osf_utimes(tcp)
1599struct tcb *tcp;
1600{
1601 if (entering(tcp)) {
1602 printpath(tcp, tcp->u_arg[0]);
1603 tprintf(", ");
1604 printtv32(tcp, tcp->u_arg[1]);
1605 }
1606 return 0;
1607}
1608#endif
1609
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001610int
1611sys_utimes(tcp)
1612struct tcb *tcp;
1613{
1614 if (entering(tcp)) {
1615 printpath(tcp, tcp->u_arg[0]);
1616 tprintf(", ");
1617 printtv(tcp, tcp->u_arg[1]);
1618 }
1619 return 0;
1620}
1621
1622int
1623sys_utime(tcp)
1624struct tcb *tcp;
1625{
1626 long ut[2];
1627
1628 if (entering(tcp)) {
1629 printpath(tcp, tcp->u_arg[0]);
1630 tprintf(", ");
1631 if (!tcp->u_arg[1])
1632 tprintf("NULL");
1633 else if (!verbose(tcp))
1634 tprintf("%#lx", tcp->u_arg[1]);
1635 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
1636 (char *) ut) < 0)
1637 tprintf("[?, ?]");
1638 else {
1639 tprintf("[%s,", sprinttime(ut[0]));
1640 tprintf(" %s]", sprinttime(ut[1]));
1641 }
1642 }
1643 return 0;
1644}
1645
1646int
1647sys_mknod(tcp)
1648struct tcb *tcp;
1649{
1650 int mode = tcp->u_arg[1];
1651
1652 if (entering(tcp)) {
1653 printpath(tcp, tcp->u_arg[0]);
1654 tprintf(", %s", sprintmode(mode));
1655 switch (mode & S_IFMT) {
1656 case S_IFCHR: case S_IFBLK:
1657#ifdef LINUXSPARC
1658 if (current_personality == 1)
1659 tprintf(", makedev(%lu, %lu)",
1660 (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
1661 (unsigned long) (tcp->u_arg[2] & 0x3ffff));
1662 else
1663#endif
1664 tprintf(", makedev(%lu, %lu)",
1665 (unsigned long) major(tcp->u_arg[2]),
1666 (unsigned long) minor(tcp->u_arg[2]));
1667 break;
1668 default:
1669 break;
1670 }
1671 }
1672 return 0;
1673}
1674
1675int
1676sys_mkfifo(tcp)
1677struct tcb *tcp;
1678{
1679 if (entering(tcp)) {
1680 printpath(tcp, tcp->u_arg[0]);
1681 tprintf(", %#lo", tcp->u_arg[1]);
1682 }
1683 return 0;
1684}
1685
1686int
1687sys_fsync(tcp)
1688struct tcb *tcp;
1689{
1690 if (entering(tcp)) {
1691 tprintf("%ld", tcp->u_arg[0]);
1692 }
1693 return 0;
1694}
1695
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001696#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001697
1698static void
1699printdir(tcp, addr)
1700struct tcb *tcp;
1701long addr;
1702{
1703 struct dirent d;
1704
1705 if (!verbose(tcp)) {
1706 tprintf("%#lx", addr);
1707 return;
1708 }
1709 if (umove(tcp, addr, &d) < 0) {
1710 tprintf("{...}");
1711 return;
1712 }
1713 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001714 tprintf("d_name=");
1715 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
1716 tprintf("}");
1717}
1718
1719int
1720sys_readdir(tcp)
1721struct tcb *tcp;
1722{
1723 if (entering(tcp)) {
1724 tprintf("%lu, ", tcp->u_arg[0]);
1725 } else {
1726 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
1727 tprintf("%#lx", tcp->u_arg[1]);
1728 else
1729 printdir(tcp, tcp->u_arg[1]);
1730 /* Not much point in printing this out, it is always 1. */
1731 if (tcp->u_arg[2] != 1)
1732 tprintf(", %lu", tcp->u_arg[2]);
1733 }
1734 return 0;
1735}
1736
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001737#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001738
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001739#ifdef FREEBSD
1740struct xlat direnttypes[] = {
1741 { DT_FIFO, "DT_FIFO" },
1742 { DT_CHR, "DT_CHR" },
1743 { DT_DIR, "DT_DIR" },
1744 { DT_BLK, "DT_BLK" },
1745 { DT_REG, "DT_REG" },
1746 { DT_LNK, "DT_LNK" },
1747 { DT_SOCK, "DT_SOCK" },
1748 { DT_WHT, "DT_WHT" },
1749 { 0, NULL },
1750};
1751
1752#endif
1753
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001754int
1755sys_getdents(tcp)
1756struct tcb *tcp;
1757{
1758 int i, len, dents = 0;
1759 char *buf;
1760
1761 if (entering(tcp)) {
1762 tprintf("%lu, ", tcp->u_arg[0]);
1763 return 0;
1764 }
1765 if (syserror(tcp) || !verbose(tcp)) {
1766 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1767 return 0;
1768 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001769 len = tcp->u_rval;
1770 if ((buf = malloc(len)) == NULL) {
1771 tprintf("out of memory\n");
1772 return 0;
1773 }
1774 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1775 tprintf("{...}, %lu", tcp->u_arg[2]);
1776 free(buf);
1777 return 0;
1778 }
1779 if (!abbrev(tcp))
1780 tprintf("{");
1781 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00001782 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001783#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001784 if (!abbrev(tcp)) {
1785 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1786 i ? " " : "", d->d_ino, d->d_off);
1787 tprintf("d_reclen=%u, d_name=\"%s\"}",
1788 d->d_reclen, d->d_name);
1789 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001790#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001791#ifdef SVR4
1792 if (!abbrev(tcp)) {
1793 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1794 i ? " " : "", d->d_ino, d->d_off);
1795 tprintf("d_reclen=%u, d_name=\"%s\"}",
1796 d->d_reclen, d->d_name);
1797 }
1798#endif /* SVR4 */
1799#ifdef SUNOS4
1800 if (!abbrev(tcp)) {
1801 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
1802 i ? " " : "", d->d_off, d->d_fileno,
1803 d->d_reclen);
1804 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
1805 d->d_namlen, d->d_namlen, d->d_name);
1806 }
1807#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001808#ifdef FREEBSD
1809 if (!abbrev(tcp)) {
1810 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
1811 i ? " " : "", d->d_fileno, d->d_reclen);
1812 printxval(direnttypes, d->d_type, "DT_???");
1813 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
1814 d->d_namlen, d->d_namlen, d->d_name);
1815 }
1816#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00001817 if (!d->d_reclen) {
1818 tprintf("/* d_reclen == 0, problem here */");
1819 break;
1820 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001821 i += d->d_reclen;
1822 dents++;
1823 }
1824 if (!abbrev(tcp))
1825 tprintf("}");
1826 else
1827 tprintf("/* %u entries */", dents);
1828 tprintf(", %lu", tcp->u_arg[2]);
1829 free(buf);
1830 return 0;
1831}
1832
John Hughesbdf48f52001-03-06 15:08:09 +00001833
1834#if _LFS64_LARGEFILE
1835int
1836sys_getdents64(tcp)
1837struct tcb *tcp;
1838{
1839 int i, len, dents = 0;
1840 char *buf;
1841
1842 if (entering(tcp)) {
1843 tprintf("%lu, ", tcp->u_arg[0]);
1844 return 0;
1845 }
1846 if (syserror(tcp) || !verbose(tcp)) {
1847 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1848 return 0;
1849 }
1850 len = tcp->u_rval;
1851 if ((buf = malloc(len)) == NULL) {
1852 tprintf("out of memory\n");
1853 return 0;
1854 }
1855 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1856 tprintf("{...}, %lu", tcp->u_arg[2]);
1857 free(buf);
1858 return 0;
1859 }
1860 if (!abbrev(tcp))
1861 tprintf("{");
1862 for (i = 0; i < len;) {
1863 struct dirent64 *d = (struct dirent64 *) &buf[i];
1864#ifdef linux
1865 if (!abbrev(tcp)) {
1866 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1867 i ? " " : "", d->d_ino, d->d_off);
1868 tprintf("d_reclen=%u, d_name=\"%s\"}",
1869 d->d_reclen, d->d_name);
1870 }
1871#endif /* linux */
1872#ifdef SVR4
1873 if (!abbrev(tcp)) {
1874 tprintf("%s{d_ino=%llu, d_off=%llu, ",
1875 i ? " " : "", d->d_ino, d->d_off);
1876 tprintf("d_reclen=%u, d_name=\"%s\"}",
1877 d->d_reclen, d->d_name);
1878 }
1879#endif /* SVR4 */
1880#ifdef SUNOS4
1881 if (!abbrev(tcp)) {
1882 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
1883 i ? " " : "", d->d_off, d->d_fileno,
1884 d->d_reclen);
1885 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
1886 d->d_namlen, d->d_namlen, d->d_name);
1887 }
1888#endif /* SUNOS4 */
1889 i += d->d_reclen;
1890 dents++;
1891 }
1892 if (!abbrev(tcp))
1893 tprintf("}");
1894 else
1895 tprintf("/* %u entries */", dents);
1896 tprintf(", %lu", tcp->u_arg[2]);
1897 free(buf);
1898 return 0;
1899}
1900#endif
1901
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001902#ifdef FREEBSD
1903int
1904sys_getdirentries(tcp)
1905struct tcb * tcp;
1906{
1907 int i, len, dents = 0;
1908 long basep;
1909 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001910
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001911 if (entering(tcp)) {
1912 tprintf("%lu, ", tcp->u_arg[0]);
1913 return 0;
1914 }
1915 if (syserror(tcp) || !verbose(tcp)) {
1916 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
1917 return 0;
1918 }
1919 len = tcp->u_rval;
1920 if ((buf = malloc(len)) == NULL) {
1921 tprintf("out of memory\n");
1922 return 0;
1923 }
1924 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1925 tprintf("{...}, %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3]);
1926 free(buf);
1927 return 0;
1928 }
1929 if (!abbrev(tcp))
1930 tprintf("{");
1931 for (i = 0; i < len;) {
1932 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
1933 if (!abbrev(tcp)) {
1934 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
1935 i ? " " : "", d->d_fileno, d->d_reclen);
1936 printxval(direnttypes, d->d_type, "DT_???");
1937 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
1938 d->d_namlen, d->d_namlen, d->d_name);
1939 }
1940 i += d->d_reclen;
1941 dents++;
1942 }
1943 if (!abbrev(tcp))
1944 tprintf("}");
1945 else
1946 tprintf("/* %u entries */", dents);
1947 free(buf);
1948 tprintf(", %lu", tcp->u_arg[2]);
1949 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
1950 tprintf(", %#lx", tcp->u_arg[3]);
1951 else
1952 tprintf(", [%lu]", basep);
1953 return 0;
1954}
1955#endif
1956
1957#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001958int
1959sys_getcwd(tcp)
1960struct tcb *tcp;
1961{
1962 if (exiting(tcp)) {
1963 if (syserror(tcp))
1964 tprintf("%#lx", tcp->u_arg[0]);
1965 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001966 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001967 tprintf(", %lu", tcp->u_arg[1]);
1968 }
1969 return 0;
1970}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001971#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001972
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001973#ifdef FREEBSD
1974int
1975sys___getcwd(tcp)
1976struct tcb *tcp;
1977{
1978 if (exiting(tcp)) {
1979 if (syserror(tcp))
1980 tprintf("%#lx", tcp->u_arg[0]);
1981 else
1982 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1983 tprintf(", %lu", tcp->u_arg[1]);
1984 }
1985 return 0;
1986}
1987#endif
1988
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001989#ifdef HAVE_SYS_ASYNCH_H
1990
1991int
1992sys_aioread(tcp)
1993struct tcb *tcp;
1994{
1995 struct aio_result_t res;
1996
1997 if (entering(tcp)) {
1998 tprintf("%lu, ", tcp->u_arg[0]);
1999 } else {
2000 if (syserror(tcp))
2001 tprintf("%#lx", tcp->u_arg[1]);
2002 else
2003 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2004 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2005 printxval(whence, tcp->u_arg[4], "L_???");
2006 if (syserror(tcp) || tcp->u_arg[5] == 0
2007 || umove(tcp, tcp->u_arg[5], &res) < 0)
2008 tprintf(", %#lx", tcp->u_arg[5]);
2009 else
2010 tprintf(", {aio_return %d aio_errno %d}",
2011 res.aio_return, res.aio_errno);
2012 }
2013 return 0;
2014}
2015
2016int
2017sys_aiowrite(tcp)
2018struct tcb *tcp;
2019{
2020 struct aio_result_t res;
2021
2022 if (entering(tcp)) {
2023 tprintf("%lu, ", tcp->u_arg[0]);
2024 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2025 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2026 printxval(whence, tcp->u_arg[4], "L_???");
2027 }
2028 else {
2029 if (tcp->u_arg[5] == 0)
2030 tprintf(", NULL");
2031 else if (syserror(tcp)
2032 || umove(tcp, tcp->u_arg[5], &res) < 0)
2033 tprintf(", %#lx", tcp->u_arg[5]);
2034 else
2035 tprintf(", {aio_return %d aio_errno %d}",
2036 res.aio_return, res.aio_errno);
2037 }
2038 return 0;
2039}
2040
2041int
2042sys_aiowait(tcp)
2043struct tcb *tcp;
2044{
2045 if (entering(tcp))
2046 printtv(tcp, tcp->u_arg[0]);
2047 return 0;
2048}
2049
2050int
2051sys_aiocancel(tcp)
2052struct tcb *tcp;
2053{
2054 struct aio_result_t res;
2055
2056 if (exiting(tcp)) {
2057 if (tcp->u_arg[0] == 0)
2058 tprintf("NULL");
2059 else if (syserror(tcp)
2060 || umove(tcp, tcp->u_arg[0], &res) < 0)
2061 tprintf("%#lx", tcp->u_arg[0]);
2062 else
2063 tprintf("{aio_return %d aio_errno %d}",
2064 res.aio_return, res.aio_errno);
2065 }
2066 return 0;
2067}
2068
2069#endif /* HAVE_SYS_ASYNCH_H */