blob: 94577ed53f4a71704e7ec5c10bb2d90604f68c84 [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
38#include <linux/types.h>
39#include <linux/dirent.h>
40#undef dirent
41#else
42#define kernel_dirent dirent
43#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000044
Wichert Akkerman8bc6cfd1999-04-21 15:57:38 +000045#ifdef linux
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000046# ifdef LINUXSPARC
47struct stat {
48 unsigned short st_dev;
49 unsigned int st_ino;
50 unsigned short st_mode;
51 short st_nlink;
52 unsigned short st_uid;
53 unsigned short st_gid;
54 unsigned short st_rdev;
55 unsigned int st_size;
56 int st_atime;
57 unsigned int __unused1;
58 int st_mtime;
59 unsigned int __unused2;
60 int st_ctime;
61 unsigned int __unused3;
62 int st_blksize;
63 int st_blocks;
64 unsigned int __unused4[2];
65};
66# define stat kernel_stat
67# include <asm/stat.h>
68# undef stat
69# else
Wichert Akkerman5b4d1281999-07-09 00:32:54 +000070# undef dev_t
71# undef ino_t
72# undef mode_t
73# undef nlink_t
74# undef uid_t
75# undef gid_t
76# undef off_t
77# undef loff_t
78
Wichert Akkermana6013701999-07-08 14:00:58 +000079# define dev_t __kernel_dev_t
80# define ino_t __kernel_ino_t
81# define mode_t __kernel_mode_t
82# define nlink_t __kernel_nlink_t
83# define uid_t __kernel_uid_t
84# define gid_t __kernel_gid_t
85# define off_t __kernel_off_t
86# define loff_t __kernel_loff_t
87
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000088# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +000089
90# undef dev_t
91# undef ino_t
92# undef mode_t
93# undef nlink_t
94# undef uid_t
95# undef gid_t
96# undef off_t
97# undef loff_t
Wichert Akkerman5b4d1281999-07-09 00:32:54 +000098
99# define dev_t dev_t
100# define ino_t ino_t
101# define mode_t mode_t
102# define nlink_t nlink_t
103# define uid_t uid_t
104# define gid_t gid_t
105# define off_t off_t
106# define loff_t loff_t
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000107# endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000108# define stat libc_stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000109# define stat64 libc_stat64
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000110# include <sys/stat.h>
111# undef stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000112# undef stat64
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000113#else
114# include <sys/stat.h>
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000115#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000116
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000117#include <fcntl.h>
118
119#ifdef SVR4
120# include <sys/cred.h>
121#endif /* SVR4 */
122
123#include <sys/vfs.h>
124
125#ifdef MAJOR_IN_SYSMACROS
126#include <sys/sysmacros.h>
127#endif
128
129#ifdef MAJOR_IN_MKDEV
130#include <sys/mkdev.h>
131#endif
132
133#ifdef HAVE_SYS_ASYNCH_H
134#include <sys/asynch.h>
135#endif
136
137#ifdef SUNOS4
138#include <ustat.h>
139#endif
140
141/*
142 * This is a really dirty trick but it should always work. Traditional
143 * Unix says r/w/rw are 0/1/2, so we make them true flags 1/2/3 by
144 * adding 1. Just remember to add 1 to any arg decoded with openmodes.
145 */
146struct xlat openmodes[] = {
147 { O_RDWR+1, "O_RDWR" },
148 { O_RDONLY+1, "O_RDONLY" },
149 { O_WRONLY+1, "O_WRONLY" },
150 { O_NONBLOCK, "O_NONBLOCK" },
151 { O_APPEND, "O_APPEND" },
152 { O_CREAT, "O_CREAT" },
153 { O_TRUNC, "O_TRUNC" },
154 { O_EXCL, "O_EXCL" },
155 { O_NOCTTY, "O_NOCTTY" },
156#ifdef O_SYNC
157 { O_SYNC, "O_SYNC" },
158#endif
159#ifdef O_ASYNC
160 { O_ASYNC, "O_ASYNC" },
161#endif
162#ifdef O_DSYNC
163 { O_DSYNC, "O_DSYNC" },
164#endif
165#ifdef O_RSYNC
166 { O_RSYNC, "O_RSYNC" },
167#endif
168#ifdef O_NDELAY
169 { O_NDELAY, "O_NDELAY" },
170#endif
171#ifdef O_PRIV
172 { O_PRIV, "O_PRIV" },
173#endif
174#ifdef O_DIRECT
175 { O_DIRECT, "O_DIRECT" },
176#endif
177#ifdef O_LARGEFILE
178 { O_LARGEFILE, "O_LARGEFILE" },
179#endif
180#ifdef O_DIRECTORY
181 { O_DIRECTORY, "O_DIRECTORY" },
182#endif
183
184#ifdef FNDELAY
185 { FNDELAY, "FNDELAY" },
186#endif
187#ifdef FAPPEND
188 { FAPPEND, "FAPPEND" },
189#endif
190#ifdef FMARK
191 { FMARK, "FMARK" },
192#endif
193#ifdef FDEFER
194 { FDEFER, "FDEFER" },
195#endif
196#ifdef FASYNC
197 { FASYNC, "FASYNC" },
198#endif
199#ifdef FSHLOCK
200 { FSHLOCK, "FSHLOCK" },
201#endif
202#ifdef FEXLOCK
203 { FEXLOCK, "FEXLOCK" },
204#endif
205#ifdef FCREAT
206 { FCREAT, "FCREAT" },
207#endif
208#ifdef FTRUNC
209 { FTRUNC, "FTRUNC" },
210#endif
211#ifdef FEXCL
212 { FEXCL, "FEXCL" },
213#endif
214#ifdef FNBIO
215 { FNBIO, "FNBIO" },
216#endif
217#ifdef FSYNC
218 { FSYNC, "FSYNC" },
219#endif
220#ifdef FNOCTTY
221 { FNOCTTY, "FNOCTTY" },
222#endif
223 { 0, NULL },
224};
225
226int
227sys_open(tcp)
228struct tcb *tcp;
229{
230 if (entering(tcp)) {
231 printpath(tcp, tcp->u_arg[0]);
232 tprintf(", ");
233 /* flags */
234 printflags(openmodes, tcp->u_arg[1] + 1);
235 if (tcp->u_arg[1] & O_CREAT) {
236 /* mode */
237 tprintf(", %#lo", tcp->u_arg[2]);
238 }
239 }
240 return 0;
241}
242
243#ifdef LINUXSPARC
244struct xlat openmodessol[] = {
245 { 0, "O_RDWR" },
246 { 1, "O_RDONLY" },
247 { 2, "O_WRONLY" },
248 { 0x80, "O_NONBLOCK" },
249 { 8, "O_APPEND" },
250 { 0x100, "O_CREAT" },
251 { 0x200, "O_TRUNC" },
252 { 0x400, "O_EXCL" },
253 { 0x800, "O_NOCTTY" },
254 { 0x10, "O_SYNC" },
255 { 0x40, "O_DSYNC" },
256 { 0x8000, "O_RSYNC" },
257 { 4, "O_NDELAY" },
258 { 0x1000, "O_PRIV" },
259 { 0, NULL },
260};
261
262int
263solaris_open(tcp)
264struct tcb *tcp;
265{
266 if (entering(tcp)) {
267 printpath(tcp, tcp->u_arg[0]);
268 tprintf(", ");
269 /* flags */
270 printflags(openmodessol, tcp->u_arg[1] + 1);
271 if (tcp->u_arg[1] & 0x100) {
272 /* mode */
273 tprintf(", %#lo", tcp->u_arg[2]);
274 }
275 }
276 return 0;
277}
278
279#endif
280
281int
282sys_creat(tcp)
283struct tcb *tcp;
284{
285 if (entering(tcp)) {
286 printpath(tcp, tcp->u_arg[0]);
287 tprintf(", %#lo", tcp->u_arg[1]);
288 }
289 return 0;
290}
291
292static struct xlat access_flags[] = {
293 { F_OK, "F_OK", },
294 { R_OK, "R_OK" },
295 { W_OK, "W_OK" },
296 { X_OK, "X_OK" },
297#ifdef EFF_ONLY_OK
298 { EFF_ONLY_OK, "EFF_ONLY_OK" },
299#endif
300#ifdef EX_OK
301 { EX_OK, "EX_OK" },
302#endif
303 { 0, NULL },
304};
305
306int
307sys_access(tcp)
308struct tcb *tcp;
309{
310 if (entering(tcp)) {
311 printpath(tcp, tcp->u_arg[0]);
312 tprintf(", ");
313 printflags(access_flags, tcp->u_arg[1]);
314 }
315 return 0;
316}
317
318int
319sys_umask(tcp)
320struct tcb *tcp;
321{
322 if (entering(tcp)) {
323 tprintf("%#lo", tcp->u_arg[0]);
324 }
325 return RVAL_OCTAL;
326}
327
328static struct xlat whence[] = {
329 { SEEK_SET, "SEEK_SET" },
330 { SEEK_CUR, "SEEK_CUR" },
331 { SEEK_END, "SEEK_END" },
332 { 0, NULL },
333};
334
335int
336sys_lseek(tcp)
337struct tcb *tcp;
338{
339 if (entering(tcp)) {
340 tprintf("%ld, ", tcp->u_arg[0]);
341 if (tcp->u_arg[2] == SEEK_SET)
342 tprintf("%lu, ", tcp->u_arg[1]);
343 else
344 tprintf("%ld, ", tcp->u_arg[1]);
345 printxval(whence, tcp->u_arg[2], "SEEK_???");
346 }
347 return RVAL_UDECIMAL;
348}
349
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000350#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000351int
352sys_llseek (tcp)
353struct tcb *tcp;
354{
355 if (entering(tcp)) {
356 if (tcp->u_arg[4] == SEEK_SET)
357 tprintf("%ld, %llu, ", tcp->u_arg[0],
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000358 (((long long int) tcp->u_arg[1]) << 32
359 | (unsigned long long) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000360 else
361 tprintf("%ld, %lld, ", tcp->u_arg[0],
362 (((long long int) tcp->u_arg[1]) << 32
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000363 | (unsigned long long) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000364 }
365 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000366 long long int off;
367 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000368 tprintf("%#lx, ", tcp->u_arg[3]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000369 else
370 tprintf("[%llu], ", off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000371 printxval(whence, tcp->u_arg[4], "SEEK_???");
372 }
373 return 0;
374}
375#endif
376
377int
378sys_truncate(tcp)
379struct tcb *tcp;
380{
381 if (entering(tcp)) {
382 printpath(tcp, tcp->u_arg[0]);
383 tprintf(", %lu", tcp->u_arg[1]);
384 }
385 return 0;
386}
387
388int
389sys_ftruncate(tcp)
390struct tcb *tcp;
391{
392 if (entering(tcp)) {
393 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
394 }
395 return 0;
396}
397
398/* several stats */
399
400static struct xlat modetypes[] = {
401 { S_IFREG, "S_IFREG" },
402 { S_IFSOCK, "S_IFSOCK" },
403 { S_IFIFO, "S_IFIFO" },
404 { S_IFLNK, "S_IFLNK" },
405 { S_IFDIR, "S_IFDIR" },
406 { S_IFBLK, "S_IFBLK" },
407 { S_IFCHR, "S_IFCHR" },
408 { 0, NULL },
409};
410
411static char *
412sprintmode(mode)
413int mode;
414{
415 static char buf[64];
416 char *s;
417
418 if ((mode & S_IFMT) == 0)
419 s = "";
420 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
421 sprintf(buf, "%#o", mode);
422 return buf;
423 }
424 sprintf(buf, "%s%s%s%s", s,
425 (mode & S_ISUID) ? "|S_ISUID" : "",
426 (mode & S_ISGID) ? "|S_ISGID" : "",
427 (mode & S_ISVTX) ? "|S_ISVTX" : "");
428 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
429 if (mode)
430 sprintf(buf + strlen(buf), "|%#o", mode);
431 s = (*buf == '|') ? buf + 1 : buf;
432 return *s ? s : "0";
433}
434
435static char *
436sprinttime(t)
437time_t t;
438{
439 struct tm *tmp;
440 static char buf[32];
441
442 if (t == 0) {
443 sprintf(buf, "0");
444 return buf;
445 }
446 tmp = localtime(&t);
447 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
Wichert Akkerman3ed6dc22000-01-11 14:41:09 +0000448 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000449 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
450 return buf;
451}
452
453#ifdef LINUXSPARC
454typedef struct {
455 int tv_sec;
456 int tv_nsec;
457} timestruct_t;
458
459struct solstat {
460 unsigned st_dev;
461 int st_pad1[3]; /* network id */
462 unsigned st_ino;
463 unsigned st_mode;
464 unsigned st_nlink;
465 unsigned st_uid;
466 unsigned st_gid;
467 unsigned st_rdev;
468 int st_pad2[2];
469 int st_size;
470 int st_pad3; /* st_size, off_t expansion */
471 timestruct_t st_atime;
472 timestruct_t st_mtime;
473 timestruct_t st_ctime;
474 int st_blksize;
475 int st_blocks;
476 char st_fstype[16];
477 int st_pad4[8]; /* expansion area */
478};
479
480static void
481printstatsol(tcp, addr)
482struct tcb *tcp;
483int addr;
484{
485 struct solstat statbuf;
486
487 if (!addr) {
488 tprintf("NULL");
489 return;
490 }
491 if (syserror(tcp) || !verbose(tcp)) {
492 tprintf("%#x", addr);
493 return;
494 }
495 if (umove(tcp, addr, &statbuf) < 0) {
496 tprintf("{...}");
497 return;
498 }
499 if (!abbrev(tcp)) {
500 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
501 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
502 (unsigned long) (statbuf.st_dev & 0x3ffff),
503 (unsigned long) statbuf.st_ino,
504 sprintmode(statbuf.st_mode));
505 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
506 (unsigned long) statbuf.st_nlink,
507 (unsigned long) statbuf.st_uid,
508 (unsigned long) statbuf.st_gid);
509 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
510 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
511 }
512 else
513 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
514 switch (statbuf.st_mode & S_IFMT) {
515 case S_IFCHR: case S_IFBLK:
516 tprintf("st_rdev=makedev(%lu, %lu), ",
517 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
518 (unsigned long) (statbuf.st_rdev & 0x3ffff));
519 break;
520 default:
521 tprintf("st_size=%u, ", statbuf.st_size);
522 break;
523 }
524 if (!abbrev(tcp)) {
525 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
526 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
527 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
528 }
529 else
530 tprintf("...}");
531}
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000532#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000533
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000534static void
535realprintstat(tcp, statbuf)
536struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000537struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000538{
539 if (!abbrev(tcp)) {
540 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
541 (unsigned long) major(statbuf->st_dev),
542 (unsigned long) minor(statbuf->st_dev),
543 (unsigned long) statbuf->st_ino,
544 sprintmode(statbuf->st_mode));
545 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
546 (unsigned long) statbuf->st_nlink,
547 (unsigned long) statbuf->st_uid,
548 (unsigned long) statbuf->st_gid);
549#ifdef HAVE_ST_BLKSIZE
550 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
551#endif /* HAVE_ST_BLKSIZE */
552#ifdef HAVE_ST_BLOCKS
553 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
554#endif /* HAVE_ST_BLOCKS */
555 }
556 else
557 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
558 switch (statbuf->st_mode & S_IFMT) {
559 case S_IFCHR: case S_IFBLK:
560#ifdef HAVE_ST_RDEV
561 tprintf("st_rdev=makedev(%lu, %lu), ",
562 (unsigned long) major(statbuf->st_rdev),
563 (unsigned long) minor(statbuf->st_rdev));
564#else /* !HAVE_ST_RDEV */
565 tprintf("st_size=makedev(%lu, %lu), ",
566 (unsigned long) major(statbuf->st_size),
567 (unsigned long) minor(statbuf->st_size));
568#endif /* !HAVE_ST_RDEV */
569 break;
570 default:
571 tprintf("st_size=%lu, ", statbuf->st_size);
572 break;
573 }
574 if (!abbrev(tcp)) {
575 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
576 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
577 tprintf("st_ctime=%s}", sprinttime(statbuf->st_ctime));
578 }
579 else
580 tprintf("...}");
581}
582
Nate Sammons771a6ff1999-04-05 22:39:31 +0000583
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000584static void
585printstat(tcp, addr)
586struct tcb *tcp;
587int addr;
588{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000589 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000590
591#ifdef LINUXSPARC
592 if (current_personality == 1) {
593 printstatsol(tcp, addr);
594 return;
595 }
596#endif /* LINUXSPARC */
597
598 if (!addr) {
599 tprintf("NULL");
600 return;
601 }
602 if (syserror(tcp) || !verbose(tcp)) {
603 tprintf("%#x", addr);
604 return;
605 }
606 if (umove(tcp, addr, &statbuf) < 0) {
607 tprintf("{...}");
608 return;
609 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000610
611 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000612}
613
Wichert Akkerman0396bdc1999-12-24 23:11:57 +0000614#ifdef STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000615static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000616printstat64(tcp, addr)
617struct tcb *tcp;
618int addr;
619{
620 struct stat64 statbuf;
621
622#ifdef LINUXSPARC
623 if (current_personality == 1) {
624 printstatsol(tcp, addr);
625 return;
626 }
627#endif /* LINUXSPARC */
628
629 if (!addr) {
630 tprintf("NULL");
631 return;
632 }
633 if (syserror(tcp) || !verbose(tcp)) {
634 tprintf("%#x", addr);
635 return;
636 }
637 if (umove(tcp, addr, &statbuf) < 0) {
638 tprintf("{...}");
639 return;
640 }
641
642 if (!abbrev(tcp)) {
643 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
644 (unsigned long) major(statbuf.st_dev),
645 (unsigned long) minor(statbuf.st_dev),
646 (unsigned long) statbuf.st_ino,
647 sprintmode(statbuf.st_mode));
648 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
649 (unsigned long) statbuf.st_nlink,
650 (unsigned long) statbuf.st_uid,
651 (unsigned long) statbuf.st_gid);
652#ifdef HAVE_ST_BLKSIZE
653 tprintf("st_blksize=%lu, ",
654 (unsigned long) statbuf.st_blksize);
655#endif /* HAVE_ST_BLKSIZE */
656#ifdef HAVE_ST_BLOCKS
657 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
658#endif /* HAVE_ST_BLOCKS */
659 }
660 else
661 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
662 switch (statbuf.st_mode & S_IFMT) {
663 case S_IFCHR: case S_IFBLK:
664#ifdef HAVE_ST_RDEV
665 tprintf("st_rdev=makedev(%lu, %lu), ",
666 (unsigned long) major(statbuf.st_rdev),
667 (unsigned long) minor(statbuf.st_rdev));
668#else /* !HAVE_ST_RDEV */
669 tprintf("st_size=makedev(%lu, %lu), ",
670 (unsigned long) major(statbuf.st_size),
671 (unsigned long) minor(statbuf.st_size));
672#endif /* !HAVE_ST_RDEV */
673 break;
674 default:
675 tprintf("st_size=%llu, ", statbuf.st_size);
676 break;
677 }
678 if (!abbrev(tcp)) {
679 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
680 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
681 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
682 }
683 else
684 tprintf("...}");
685}
Wichert Akkerman0396bdc1999-12-24 23:11:57 +0000686#endif /* STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000687
Wichert Akkerman0396bdc1999-12-24 23:11:57 +0000688#ifdef linux
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000689static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000690convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000691const struct __old_kernel_stat *oldbuf;
692struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000693{
694 newbuf->st_dev=oldbuf->st_dev;
695 newbuf->st_ino=oldbuf->st_ino;
696 newbuf->st_mode=oldbuf->st_mode;
697 newbuf->st_nlink=oldbuf->st_nlink;
698 newbuf->st_uid=oldbuf->st_uid;
699 newbuf->st_gid=oldbuf->st_gid;
700 newbuf->st_rdev=oldbuf->st_rdev;
701 newbuf->st_size=oldbuf->st_size;
702 newbuf->st_atime=oldbuf->st_atime;
703 newbuf->st_mtime=oldbuf->st_mtime;
704 newbuf->st_ctime=oldbuf->st_ctime;
705 newbuf->st_blksize=0; /* not supported in old_stat */
706 newbuf->st_blocks=0; /* not supported in old_stat */
707}
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000708
709
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000710static void
711printoldstat(tcp, addr)
712struct tcb *tcp;
713int addr;
714{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000715 struct __old_kernel_stat statbuf;
716 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000717
718#ifdef LINUXSPARC
719 if (current_personality == 1) {
720 printstatsol(tcp, addr);
721 return;
722 }
723#endif /* LINUXSPARC */
724
725 if (!addr) {
726 tprintf("NULL");
727 return;
728 }
729 if (syserror(tcp) || !verbose(tcp)) {
730 tprintf("%#x", addr);
731 return;
732 }
733 if (umove(tcp, addr, &statbuf) < 0) {
734 tprintf("{...}");
735 return;
736 }
737
738 convertoldstat(&statbuf, &newstatbuf);
739 realprintstat(tcp, &newstatbuf);
740}
741#endif
742
743
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000744int
745sys_stat(tcp)
746struct tcb *tcp;
747{
748 if (entering(tcp)) {
749 printpath(tcp, tcp->u_arg[0]);
750 tprintf(", ");
751 } else {
752 printstat(tcp, tcp->u_arg[1]);
753 }
754 return 0;
755}
756
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000757#ifdef linux
758int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000759sys_stat64(tcp)
760struct tcb *tcp;
761{
762#ifdef HAVE_STAT64
763 if (entering(tcp)) {
764 printpath(tcp, tcp->u_arg[0]);
765 tprintf(", ");
766 } else {
767 printstat64(tcp, tcp->u_arg[1]);
768 }
769 return 0;
770#else
771 return printargs(tcp);
772#endif
773}
774
775int
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000776sys_oldstat(tcp)
777struct tcb *tcp;
778{
779 if (entering(tcp)) {
780 printpath(tcp, tcp->u_arg[0]);
781 tprintf(", ");
782 } else {
783 printoldstat(tcp, tcp->u_arg[1]);
784 }
785 return 0;
786}
787#endif
788
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000789int
790sys_fstat(tcp)
791struct tcb *tcp;
792{
793 if (entering(tcp))
794 tprintf("%ld, ", tcp->u_arg[0]);
795 else {
796 printstat(tcp, tcp->u_arg[1]);
797 }
798 return 0;
799}
800
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000801#ifdef linux
802int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000803sys_fstat64(tcp)
804struct tcb *tcp;
805{
806#ifdef HAVE_STAT64
807 if (entering(tcp))
808 tprintf("%ld, ", tcp->u_arg[0]);
809 else {
810 printstat64(tcp, tcp->u_arg[1]);
811 }
812 return 0;
813#else
814 return printargs(tcp);
815#endif
816}
817
818int
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000819sys_oldfstat(tcp)
820struct tcb *tcp;
821{
822 if (entering(tcp))
823 tprintf("%ld, ", tcp->u_arg[0]);
824 else {
825 printoldstat(tcp, tcp->u_arg[1]);
826 }
827 return 0;
828}
829#endif
830
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000831int
832sys_lstat(tcp)
833struct tcb *tcp;
834{
835 if (entering(tcp)) {
836 printpath(tcp, tcp->u_arg[0]);
837 tprintf(", ");
838 } else {
839 printstat(tcp, tcp->u_arg[1]);
840 }
841 return 0;
842}
843
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000844#ifdef linux
845int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000846sys_lstat64(tcp)
847struct tcb *tcp;
848{
849#ifdef HAVE_STAT64
850 if (entering(tcp)) {
851 printpath(tcp, tcp->u_arg[0]);
852 tprintf(", ");
853 } else {
854 printstat64(tcp, tcp->u_arg[1]);
855 }
856 return 0;
857#else
858 return printargs(tcp);
859#endif
860}
861
862int
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000863sys_oldlstat(tcp)
864struct tcb *tcp;
865{
866 if (entering(tcp)) {
867 printpath(tcp, tcp->u_arg[0]);
868 tprintf(", ");
869 } else {
870 printoldstat(tcp, tcp->u_arg[1]);
871 }
872 return 0;
873}
874#endif
875
876
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000877#if defined(SVR4) || defined(LINUXSPARC)
878
879int
880sys_xstat(tcp)
881struct tcb *tcp;
882{
883 if (entering(tcp)) {
884 tprintf("%ld, ", tcp->u_arg[0]);
885 printpath(tcp, tcp->u_arg[1]);
886 tprintf(", ");
887 } else {
888 printstat(tcp, tcp->u_arg[2]);
889 }
890 return 0;
891}
892
893int
894sys_fxstat(tcp)
895struct tcb *tcp;
896{
897 if (entering(tcp))
898 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
899 else {
900 printstat(tcp, tcp->u_arg[2]);
901 }
902 return 0;
903}
904
905int
906sys_lxstat(tcp)
907struct tcb *tcp;
908{
909 if (entering(tcp)) {
910 tprintf("%ld, ", tcp->u_arg[0]);
911 printpath(tcp, tcp->u_arg[1]);
912 tprintf(", ");
913 } else {
914 printstat(tcp, tcp->u_arg[2]);
915 }
916 return 0;
917}
918
919int
920sys_xmknod(tcp)
921struct tcb *tcp;
922{
923 int mode = tcp->u_arg[2];
924
925 if (entering(tcp)) {
926 tprintf("%ld, ", tcp->u_arg[0]);
927 printpath(tcp, tcp->u_arg[1]);
928 tprintf(", %s", sprintmode(mode));
929 switch (mode & S_IFMT) {
930 case S_IFCHR: case S_IFBLK:
931#ifdef LINUXSPARC
932 tprintf(", makedev(%lu, %lu)",
933 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
934 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
935#else
936 tprintf(", makedev(%lu, %lu)",
937 (unsigned long) major(tcp->u_arg[3]),
938 (unsigned long) minor(tcp->u_arg[3]));
939#endif
940 break;
941 default:
942 break;
943 }
944 }
945 return 0;
946}
947
Wichert Akkerman8829a551999-06-11 13:18:40 +0000948#ifdef HAVE_SYS_ACL_H
949
950#include <sys/acl.h>
951
952struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000953#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +0000954 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000955#endif
956#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +0000957 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000958#endif
959#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +0000960 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000961#endif
962#ifdef ACL_GET
963 { ACL_GET, "ACL_GET" },
964#endif
965#ifdef ACL_SET
966 { ACL_SET, "ACL_SET" },
967#endif
968#ifdef ACL_CNT
969 { ACL_CNT, "ACL_CNT" },
970#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000971 { 0, NULL },
972};
973
974int
975sys_acl(tcp)
976struct tcb *tcp;
977{
978 if (entering(tcp)) {
979 printpath(tcp, tcp->u_arg[0]);
980 tprintf(", ");
981 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
982 tprintf(", %ld", tcp->u_arg[2]);
983 /*
984 * FIXME - dump out the list of aclent_t's pointed to
985 * by "tcp->u_arg[3]" if it's not NULL.
986 */
987 if (tcp->u_arg[3])
988 tprintf(", %#lx", tcp->u_arg[3]);
989 else
990 tprintf(", NULL");
991 }
992 return 0;
993}
994
995
996int
997sys_facl(tcp)
998struct tcb *tcp;
999{
1000 if (entering(tcp)) {
1001 tprintf("%ld, ", tcp->u_arg[0]);
1002 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1003 tprintf(", %ld", tcp->u_arg[2]);
1004 /*
1005 * FIXME - dump out the list of aclent_t's pointed to
1006 * by "tcp->u_arg[3]" if it's not NULL.
1007 */
1008 if (tcp->u_arg[3])
1009 tprintf(", %#lx", tcp->u_arg[3]);
1010 else
1011 tprintf(", NULL");
1012 }
1013 return 0;
1014}
1015
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001016
1017struct xlat aclipc[] = {
1018#ifdef IPC_SHM
1019 { IPC_SHM, "IPC_SHM" },
1020#endif
1021#ifdef IPC_SEM
1022 { IPC_SEM, "IPC_SEM" },
1023#endif
1024#ifdef IPC_MSG
1025 { IPC_MSG, "IPC_MSG" },
1026#endif
1027 { 0, NULL },
1028};
1029
1030
1031int
1032sys_aclipc(tcp)
1033struct tcb *tcp;
1034{
1035 if (entering(tcp)) {
1036 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1037 tprintf(", %#lx, ", tcp->u_arg[1]);
1038 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1039 tprintf(", %ld", tcp->u_arg[3]);
1040 /*
1041 * FIXME - dump out the list of aclent_t's pointed to
1042 * by "tcp->u_arg[4]" if it's not NULL.
1043 */
1044 if (tcp->u_arg[4])
1045 tprintf(", %#lx", tcp->u_arg[4]);
1046 else
1047 tprintf(", NULL");
1048 }
1049 return 0;
1050}
1051
1052
1053
Wichert Akkerman8829a551999-06-11 13:18:40 +00001054#endif /* HAVE_SYS_ACL_H */
1055
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001056#endif /* SVR4 || LINUXSPARC */
1057
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001058#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001059
1060static struct xlat fsmagic[] = {
1061 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1062 { 0xef53, "EXT2_SUPER_MAGIC" },
1063 { 0x137d, "EXT_SUPER_MAGIC" },
1064 { 0x9660, "ISOFS_SUPER_MAGIC" },
1065 { 0x137f, "MINIX_SUPER_MAGIC" },
1066 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001067 { 0x2468, "MINIX2_SUPER_MAGIC" },
1068 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001069 { 0x4d44, "MSDOS_SUPER_MAGIC" },
1070 { 0x6969, "NFS_SUPER_MAGIC" },
1071 { 0x9fa0, "PROC_SUPER_MAGIC" },
1072 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
1073 { 0, NULL },
1074};
1075
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001076#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001077
1078#ifndef SVR4
1079
1080static char *
1081sprintfstype(magic)
1082int magic;
1083{
1084 static char buf[32];
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001085#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001086 char *s;
1087
1088 s = xlookup(fsmagic, magic);
1089 if (s) {
1090 sprintf(buf, "\"%s\"", s);
1091 return buf;
1092 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001093#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001094 sprintf(buf, "%#x", magic);
1095 return buf;
1096}
1097
1098static void
1099printstatfs(tcp, addr)
1100struct tcb *tcp;
1101long addr;
1102{
1103 struct statfs statbuf;
1104
1105 if (syserror(tcp) || !verbose(tcp)) {
1106 tprintf("%#lx", addr);
1107 return;
1108 }
1109 if (umove(tcp, addr, &statbuf) < 0) {
1110 tprintf("{...}");
1111 return;
1112 }
1113#ifdef ALPHA
1114
1115 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1116 sprintfstype(statbuf.f_type),
1117 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001118 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_namelen=%u",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001119 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree, statbuf.f_namelen);
1120#else /* !ALPHA */
1121 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1122 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001123 (unsigned long)statbuf.f_bsize,
1124 (unsigned long)statbuf.f_blocks,
1125 (unsigned long)statbuf.f_bfree);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001126 tprintf("f_files=%lu, f_ffree=%lu",
Nate Sammons5c74d201999-04-06 01:37:51 +00001127 (unsigned long)statbuf.f_files,
1128 (unsigned long)statbuf.f_ffree);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001129#ifdef linux
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001130 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001131#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001132#endif /* !ALPHA */
1133 tprintf("}");
1134}
1135
1136int
1137sys_statfs(tcp)
1138struct tcb *tcp;
1139{
1140 if (entering(tcp)) {
1141 printpath(tcp, tcp->u_arg[0]);
1142 tprintf(", ");
1143 } else {
1144 printstatfs(tcp, tcp->u_arg[1]);
1145 }
1146 return 0;
1147}
1148
1149int
1150sys_fstatfs(tcp)
1151struct tcb *tcp;
1152{
1153 if (entering(tcp)) {
1154 tprintf("%lu, ", tcp->u_arg[0]);
1155 } else {
1156 printstatfs(tcp, tcp->u_arg[1]);
1157 }
1158 return 0;
1159}
1160
Wichert Akkermana0f36c61999-04-16 14:01:34 +00001161#if defined(linux) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001162
1163int
1164osf_statfs(tcp)
1165struct tcb *tcp;
1166{
1167 if (entering(tcp)) {
1168 printpath(tcp, tcp->u_arg[0]);
1169 tprintf(", ");
1170 } else {
1171 printstatfs(tcp, tcp->u_arg[1]);
1172 tprintf(", %lu", tcp->u_arg[2]);
1173 }
1174 return 0;
1175}
1176
1177int
1178osf_fstatfs(tcp)
1179struct tcb *tcp;
1180{
1181 if (entering(tcp)) {
1182 tprintf("%lu, ", tcp->u_arg[0]);
1183 } else {
1184 printstatfs(tcp, tcp->u_arg[1]);
1185 tprintf(", %lu", tcp->u_arg[2]);
1186 }
1187 return 0;
1188}
Wichert Akkermana0f36c61999-04-16 14:01:34 +00001189#endif /* linux && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001190
1191#endif /* !SVR4 */
1192
1193#ifdef SUNOS4
1194
1195int
1196sys_ustat(tcp)
1197struct tcb *tcp;
1198{
1199 struct ustat statbuf;
1200
1201 if (entering(tcp)) {
1202 tprintf("makedev(%lu, %lu), ",
1203 (long) major(tcp->u_arg[0]),
1204 (long) minor(tcp->u_arg[0]));
1205 }
1206 else {
1207 if (syserror(tcp) || !verbose(tcp))
1208 tprintf("%#lx", tcp->u_arg[1]);
1209 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1210 tprintf("{...}");
1211 else {
1212 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1213 statbuf.f_tfree, statbuf.f_tinode);
1214 tprintf("f_fname=\"%.*s\", ",
1215 (int) sizeof(statbuf.f_fname),
1216 statbuf.f_fname);
1217 tprintf("f_fpack=\"%.*s\"}",
1218 (int) sizeof(statbuf.f_fpack),
1219 statbuf.f_fpack);
1220 }
1221 }
1222 return 0;
1223}
1224
1225#endif /* SUNOS4 */
1226
1227/* directory */
1228int
1229sys_chdir(tcp)
1230struct tcb *tcp;
1231{
1232 if (entering(tcp)) {
1233 printpath(tcp, tcp->u_arg[0]);
1234 }
1235 return 0;
1236}
1237
1238int
1239sys_mkdir(tcp)
1240struct tcb *tcp;
1241{
1242 if (entering(tcp)) {
1243 printpath(tcp, tcp->u_arg[0]);
1244 tprintf(", %#lo", tcp->u_arg[1]);
1245 }
1246 return 0;
1247}
1248
1249int
1250sys_rmdir(tcp)
1251struct tcb *tcp;
1252{
1253 if (entering(tcp)) {
1254 printpath(tcp, tcp->u_arg[0]);
1255 }
1256 return 0;
1257}
1258
1259int
1260sys_fchdir(tcp)
1261struct tcb *tcp;
1262{
1263 if (entering(tcp)) {
1264 tprintf("%ld", tcp->u_arg[0]);
1265 }
1266 return 0;
1267}
1268
1269int
1270sys_chroot(tcp)
1271struct tcb *tcp;
1272{
1273 if (entering(tcp)) {
1274 printpath(tcp, tcp->u_arg[0]);
1275 }
1276 return 0;
1277}
1278
1279int
1280sys_fchroot(tcp)
1281struct tcb *tcp;
1282{
1283 if (entering(tcp)) {
1284 tprintf("%ld", tcp->u_arg[0]);
1285 }
1286 return 0;
1287}
1288
1289int
1290sys_link(tcp)
1291struct tcb *tcp;
1292{
1293 if (entering(tcp)) {
1294 printpath(tcp, tcp->u_arg[0]);
1295 tprintf(", ");
1296 printpath(tcp, tcp->u_arg[1]);
1297 }
1298 return 0;
1299}
1300
1301int
1302sys_unlink(tcp)
1303struct tcb *tcp;
1304{
1305 if (entering(tcp)) {
1306 printpath(tcp, tcp->u_arg[0]);
1307 }
1308 return 0;
1309}
1310
1311int
1312sys_symlink(tcp)
1313struct tcb *tcp;
1314{
1315 if (entering(tcp)) {
1316 printpath(tcp, tcp->u_arg[0]);
1317 tprintf(", ");
1318 printpath(tcp, tcp->u_arg[1]);
1319 }
1320 return 0;
1321}
1322
1323int
1324sys_readlink(tcp)
1325struct tcb *tcp;
1326{
1327 if (entering(tcp)) {
1328 printpath(tcp, tcp->u_arg[0]);
1329 tprintf(", ");
1330 } else {
1331 if (syserror(tcp))
1332 tprintf("%#lx", tcp->u_arg[1]);
1333 else
1334 printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
1335 tprintf(", %lu", tcp->u_arg[2]);
1336 }
1337 return 0;
1338}
1339
1340int
1341sys_rename(tcp)
1342struct tcb *tcp;
1343{
1344 if (entering(tcp)) {
1345 printpath(tcp, tcp->u_arg[0]);
1346 tprintf(", ");
1347 printpath(tcp, tcp->u_arg[1]);
1348 }
1349 return 0;
1350}
1351
1352int
1353sys_chown(tcp)
1354struct tcb *tcp;
1355{
1356 if (entering(tcp)) {
1357 printpath(tcp, tcp->u_arg[0]);
1358 tprintf(", %lu, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1359 }
1360 return 0;
1361}
1362
1363int
1364sys_fchown(tcp)
1365struct tcb *tcp;
1366{
1367 if (entering(tcp)) {
1368 tprintf("%ld, %lu, %lu",
1369 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1370 }
1371 return 0;
1372}
1373
1374int
1375sys_chmod(tcp)
1376struct tcb *tcp;
1377{
1378 if (entering(tcp)) {
1379 printpath(tcp, tcp->u_arg[0]);
1380 tprintf(", %#lo", tcp->u_arg[1]);
1381 }
1382 return 0;
1383}
1384
1385int
1386sys_fchmod(tcp)
1387struct tcb *tcp;
1388{
1389 if (entering(tcp)) {
1390 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
1391 }
1392 return 0;
1393}
1394
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001395#ifdef ALPHA
1396int
1397sys_osf_utimes(tcp)
1398struct tcb *tcp;
1399{
1400 if (entering(tcp)) {
1401 printpath(tcp, tcp->u_arg[0]);
1402 tprintf(", ");
1403 printtv32(tcp, tcp->u_arg[1]);
1404 }
1405 return 0;
1406}
1407#endif
1408
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001409int
1410sys_utimes(tcp)
1411struct tcb *tcp;
1412{
1413 if (entering(tcp)) {
1414 printpath(tcp, tcp->u_arg[0]);
1415 tprintf(", ");
1416 printtv(tcp, tcp->u_arg[1]);
1417 }
1418 return 0;
1419}
1420
1421int
1422sys_utime(tcp)
1423struct tcb *tcp;
1424{
1425 long ut[2];
1426
1427 if (entering(tcp)) {
1428 printpath(tcp, tcp->u_arg[0]);
1429 tprintf(", ");
1430 if (!tcp->u_arg[1])
1431 tprintf("NULL");
1432 else if (!verbose(tcp))
1433 tprintf("%#lx", tcp->u_arg[1]);
1434 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
1435 (char *) ut) < 0)
1436 tprintf("[?, ?]");
1437 else {
1438 tprintf("[%s,", sprinttime(ut[0]));
1439 tprintf(" %s]", sprinttime(ut[1]));
1440 }
1441 }
1442 return 0;
1443}
1444
1445int
1446sys_mknod(tcp)
1447struct tcb *tcp;
1448{
1449 int mode = tcp->u_arg[1];
1450
1451 if (entering(tcp)) {
1452 printpath(tcp, tcp->u_arg[0]);
1453 tprintf(", %s", sprintmode(mode));
1454 switch (mode & S_IFMT) {
1455 case S_IFCHR: case S_IFBLK:
1456#ifdef LINUXSPARC
1457 if (current_personality == 1)
1458 tprintf(", makedev(%lu, %lu)",
1459 (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
1460 (unsigned long) (tcp->u_arg[2] & 0x3ffff));
1461 else
1462#endif
1463 tprintf(", makedev(%lu, %lu)",
1464 (unsigned long) major(tcp->u_arg[2]),
1465 (unsigned long) minor(tcp->u_arg[2]));
1466 break;
1467 default:
1468 break;
1469 }
1470 }
1471 return 0;
1472}
1473
1474int
1475sys_mkfifo(tcp)
1476struct tcb *tcp;
1477{
1478 if (entering(tcp)) {
1479 printpath(tcp, tcp->u_arg[0]);
1480 tprintf(", %#lo", tcp->u_arg[1]);
1481 }
1482 return 0;
1483}
1484
1485int
1486sys_fsync(tcp)
1487struct tcb *tcp;
1488{
1489 if (entering(tcp)) {
1490 tprintf("%ld", tcp->u_arg[0]);
1491 }
1492 return 0;
1493}
1494
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001495#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001496
1497static void
1498printdir(tcp, addr)
1499struct tcb *tcp;
1500long addr;
1501{
1502 struct dirent d;
1503
1504 if (!verbose(tcp)) {
1505 tprintf("%#lx", addr);
1506 return;
1507 }
1508 if (umove(tcp, addr, &d) < 0) {
1509 tprintf("{...}");
1510 return;
1511 }
1512 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001513 tprintf("d_name=");
1514 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
1515 tprintf("}");
1516}
1517
1518int
1519sys_readdir(tcp)
1520struct tcb *tcp;
1521{
1522 if (entering(tcp)) {
1523 tprintf("%lu, ", tcp->u_arg[0]);
1524 } else {
1525 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
1526 tprintf("%#lx", tcp->u_arg[1]);
1527 else
1528 printdir(tcp, tcp->u_arg[1]);
1529 /* Not much point in printing this out, it is always 1. */
1530 if (tcp->u_arg[2] != 1)
1531 tprintf(", %lu", tcp->u_arg[2]);
1532 }
1533 return 0;
1534}
1535
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001536#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001537
1538int
1539sys_getdents(tcp)
1540struct tcb *tcp;
1541{
1542 int i, len, dents = 0;
1543 char *buf;
1544
1545 if (entering(tcp)) {
1546 tprintf("%lu, ", tcp->u_arg[0]);
1547 return 0;
1548 }
1549 if (syserror(tcp) || !verbose(tcp)) {
1550 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1551 return 0;
1552 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001553 len = tcp->u_rval;
1554 if ((buf = malloc(len)) == NULL) {
1555 tprintf("out of memory\n");
1556 return 0;
1557 }
1558 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1559 tprintf("{...}, %lu", tcp->u_arg[2]);
1560 free(buf);
1561 return 0;
1562 }
1563 if (!abbrev(tcp))
1564 tprintf("{");
1565 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00001566 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001567#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001568 if (!abbrev(tcp)) {
1569 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1570 i ? " " : "", d->d_ino, d->d_off);
1571 tprintf("d_reclen=%u, d_name=\"%s\"}",
1572 d->d_reclen, d->d_name);
1573 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001574#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001575#ifdef SVR4
1576 if (!abbrev(tcp)) {
1577 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1578 i ? " " : "", d->d_ino, d->d_off);
1579 tprintf("d_reclen=%u, d_name=\"%s\"}",
1580 d->d_reclen, d->d_name);
1581 }
1582#endif /* SVR4 */
1583#ifdef SUNOS4
1584 if (!abbrev(tcp)) {
1585 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
1586 i ? " " : "", d->d_off, d->d_fileno,
1587 d->d_reclen);
1588 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
1589 d->d_namlen, d->d_namlen, d->d_name);
1590 }
1591#endif /* SUNOS4 */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00001592 if (!d->d_reclen) {
1593 tprintf("/* d_reclen == 0, problem here */");
1594 break;
1595 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001596 i += d->d_reclen;
1597 dents++;
1598 }
1599 if (!abbrev(tcp))
1600 tprintf("}");
1601 else
1602 tprintf("/* %u entries */", dents);
1603 tprintf(", %lu", tcp->u_arg[2]);
1604 free(buf);
1605 return 0;
1606}
1607
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001608#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001609
1610int
1611sys_getcwd(tcp)
1612struct tcb *tcp;
1613{
1614 if (exiting(tcp)) {
1615 if (syserror(tcp))
1616 tprintf("%#lx", tcp->u_arg[0]);
1617 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001618 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001619 tprintf(", %lu", tcp->u_arg[1]);
1620 }
1621 return 0;
1622}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001623#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001624
1625#ifdef HAVE_SYS_ASYNCH_H
1626
1627int
1628sys_aioread(tcp)
1629struct tcb *tcp;
1630{
1631 struct aio_result_t res;
1632
1633 if (entering(tcp)) {
1634 tprintf("%lu, ", tcp->u_arg[0]);
1635 } else {
1636 if (syserror(tcp))
1637 tprintf("%#lx", tcp->u_arg[1]);
1638 else
1639 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1640 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
1641 printxval(whence, tcp->u_arg[4], "L_???");
1642 if (syserror(tcp) || tcp->u_arg[5] == 0
1643 || umove(tcp, tcp->u_arg[5], &res) < 0)
1644 tprintf(", %#lx", tcp->u_arg[5]);
1645 else
1646 tprintf(", {aio_return %d aio_errno %d}",
1647 res.aio_return, res.aio_errno);
1648 }
1649 return 0;
1650}
1651
1652int
1653sys_aiowrite(tcp)
1654struct tcb *tcp;
1655{
1656 struct aio_result_t res;
1657
1658 if (entering(tcp)) {
1659 tprintf("%lu, ", tcp->u_arg[0]);
1660 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1661 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
1662 printxval(whence, tcp->u_arg[4], "L_???");
1663 }
1664 else {
1665 if (tcp->u_arg[5] == 0)
1666 tprintf(", NULL");
1667 else if (syserror(tcp)
1668 || umove(tcp, tcp->u_arg[5], &res) < 0)
1669 tprintf(", %#lx", tcp->u_arg[5]);
1670 else
1671 tprintf(", {aio_return %d aio_errno %d}",
1672 res.aio_return, res.aio_errno);
1673 }
1674 return 0;
1675}
1676
1677int
1678sys_aiowait(tcp)
1679struct tcb *tcp;
1680{
1681 if (entering(tcp))
1682 printtv(tcp, tcp->u_arg[0]);
1683 return 0;
1684}
1685
1686int
1687sys_aiocancel(tcp)
1688struct tcb *tcp;
1689{
1690 struct aio_result_t res;
1691
1692 if (exiting(tcp)) {
1693 if (tcp->u_arg[0] == 0)
1694 tprintf("NULL");
1695 else if (syserror(tcp)
1696 || umove(tcp, tcp->u_arg[0], &res) < 0)
1697 tprintf("%#lx", tcp->u_arg[0]);
1698 else
1699 tprintf("{aio_return %d aio_errno %d}",
1700 res.aio_return, res.aio_errno);
1701 }
1702 return 0;
1703}
1704
1705#endif /* HAVE_SYS_ASYNCH_H */