blob: b47efc204c9aefb7d4070aca3b2f28350f3a868b [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>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $Id$
30 */
31
32#include "defs.h"
33
34#include <dirent.h>
35
Wichert Akkerman8bc6cfd1999-04-21 15:57:38 +000036#ifdef linux
Wichert Akkermand4d8e921999-04-18 23:30:29 +000037# include <asm/stat.h>
38# define stat libc_stat
39# include <sys/stat.h>
40# undef stat
Wichert Akkermand4d8e921999-04-18 23:30:29 +000041#else
42# include <sys/stat.h>
Wichert Akkerman328c5e71999-04-16 00:21:26 +000043#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +000044
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000045#include <fcntl.h>
46
47#ifdef SVR4
48# include <sys/cred.h>
49#endif /* SVR4 */
50
51#include <sys/vfs.h>
52
53#ifdef MAJOR_IN_SYSMACROS
54#include <sys/sysmacros.h>
55#endif
56
57#ifdef MAJOR_IN_MKDEV
58#include <sys/mkdev.h>
59#endif
60
61#ifdef HAVE_SYS_ASYNCH_H
62#include <sys/asynch.h>
63#endif
64
65#ifdef SUNOS4
66#include <ustat.h>
67#endif
68
69/*
70 * This is a really dirty trick but it should always work. Traditional
71 * Unix says r/w/rw are 0/1/2, so we make them true flags 1/2/3 by
72 * adding 1. Just remember to add 1 to any arg decoded with openmodes.
73 */
74struct xlat openmodes[] = {
75 { O_RDWR+1, "O_RDWR" },
76 { O_RDONLY+1, "O_RDONLY" },
77 { O_WRONLY+1, "O_WRONLY" },
78 { O_NONBLOCK, "O_NONBLOCK" },
79 { O_APPEND, "O_APPEND" },
80 { O_CREAT, "O_CREAT" },
81 { O_TRUNC, "O_TRUNC" },
82 { O_EXCL, "O_EXCL" },
83 { O_NOCTTY, "O_NOCTTY" },
84#ifdef O_SYNC
85 { O_SYNC, "O_SYNC" },
86#endif
87#ifdef O_ASYNC
88 { O_ASYNC, "O_ASYNC" },
89#endif
90#ifdef O_DSYNC
91 { O_DSYNC, "O_DSYNC" },
92#endif
93#ifdef O_RSYNC
94 { O_RSYNC, "O_RSYNC" },
95#endif
96#ifdef O_NDELAY
97 { O_NDELAY, "O_NDELAY" },
98#endif
99#ifdef O_PRIV
100 { O_PRIV, "O_PRIV" },
101#endif
102#ifdef O_DIRECT
103 { O_DIRECT, "O_DIRECT" },
104#endif
105#ifdef O_LARGEFILE
106 { O_LARGEFILE, "O_LARGEFILE" },
107#endif
108#ifdef O_DIRECTORY
109 { O_DIRECTORY, "O_DIRECTORY" },
110#endif
111
112#ifdef FNDELAY
113 { FNDELAY, "FNDELAY" },
114#endif
115#ifdef FAPPEND
116 { FAPPEND, "FAPPEND" },
117#endif
118#ifdef FMARK
119 { FMARK, "FMARK" },
120#endif
121#ifdef FDEFER
122 { FDEFER, "FDEFER" },
123#endif
124#ifdef FASYNC
125 { FASYNC, "FASYNC" },
126#endif
127#ifdef FSHLOCK
128 { FSHLOCK, "FSHLOCK" },
129#endif
130#ifdef FEXLOCK
131 { FEXLOCK, "FEXLOCK" },
132#endif
133#ifdef FCREAT
134 { FCREAT, "FCREAT" },
135#endif
136#ifdef FTRUNC
137 { FTRUNC, "FTRUNC" },
138#endif
139#ifdef FEXCL
140 { FEXCL, "FEXCL" },
141#endif
142#ifdef FNBIO
143 { FNBIO, "FNBIO" },
144#endif
145#ifdef FSYNC
146 { FSYNC, "FSYNC" },
147#endif
148#ifdef FNOCTTY
149 { FNOCTTY, "FNOCTTY" },
150#endif
151 { 0, NULL },
152};
153
154int
155sys_open(tcp)
156struct tcb *tcp;
157{
158 if (entering(tcp)) {
159 printpath(tcp, tcp->u_arg[0]);
160 tprintf(", ");
161 /* flags */
162 printflags(openmodes, tcp->u_arg[1] + 1);
163 if (tcp->u_arg[1] & O_CREAT) {
164 /* mode */
165 tprintf(", %#lo", tcp->u_arg[2]);
166 }
167 }
168 return 0;
169}
170
171#ifdef LINUXSPARC
172struct xlat openmodessol[] = {
173 { 0, "O_RDWR" },
174 { 1, "O_RDONLY" },
175 { 2, "O_WRONLY" },
176 { 0x80, "O_NONBLOCK" },
177 { 8, "O_APPEND" },
178 { 0x100, "O_CREAT" },
179 { 0x200, "O_TRUNC" },
180 { 0x400, "O_EXCL" },
181 { 0x800, "O_NOCTTY" },
182 { 0x10, "O_SYNC" },
183 { 0x40, "O_DSYNC" },
184 { 0x8000, "O_RSYNC" },
185 { 4, "O_NDELAY" },
186 { 0x1000, "O_PRIV" },
187 { 0, NULL },
188};
189
190int
191solaris_open(tcp)
192struct tcb *tcp;
193{
194 if (entering(tcp)) {
195 printpath(tcp, tcp->u_arg[0]);
196 tprintf(", ");
197 /* flags */
198 printflags(openmodessol, tcp->u_arg[1] + 1);
199 if (tcp->u_arg[1] & 0x100) {
200 /* mode */
201 tprintf(", %#lo", tcp->u_arg[2]);
202 }
203 }
204 return 0;
205}
206
207#endif
208
209int
210sys_creat(tcp)
211struct tcb *tcp;
212{
213 if (entering(tcp)) {
214 printpath(tcp, tcp->u_arg[0]);
215 tprintf(", %#lo", tcp->u_arg[1]);
216 }
217 return 0;
218}
219
220static struct xlat access_flags[] = {
221 { F_OK, "F_OK", },
222 { R_OK, "R_OK" },
223 { W_OK, "W_OK" },
224 { X_OK, "X_OK" },
225#ifdef EFF_ONLY_OK
226 { EFF_ONLY_OK, "EFF_ONLY_OK" },
227#endif
228#ifdef EX_OK
229 { EX_OK, "EX_OK" },
230#endif
231 { 0, NULL },
232};
233
234int
235sys_access(tcp)
236struct tcb *tcp;
237{
238 if (entering(tcp)) {
239 printpath(tcp, tcp->u_arg[0]);
240 tprintf(", ");
241 printflags(access_flags, tcp->u_arg[1]);
242 }
243 return 0;
244}
245
246int
247sys_umask(tcp)
248struct tcb *tcp;
249{
250 if (entering(tcp)) {
251 tprintf("%#lo", tcp->u_arg[0]);
252 }
253 return RVAL_OCTAL;
254}
255
256static struct xlat whence[] = {
257 { SEEK_SET, "SEEK_SET" },
258 { SEEK_CUR, "SEEK_CUR" },
259 { SEEK_END, "SEEK_END" },
260 { 0, NULL },
261};
262
263int
264sys_lseek(tcp)
265struct tcb *tcp;
266{
267 if (entering(tcp)) {
268 tprintf("%ld, ", tcp->u_arg[0]);
269 if (tcp->u_arg[2] == SEEK_SET)
270 tprintf("%lu, ", tcp->u_arg[1]);
271 else
272 tprintf("%ld, ", tcp->u_arg[1]);
273 printxval(whence, tcp->u_arg[2], "SEEK_???");
274 }
275 return RVAL_UDECIMAL;
276}
277
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000278#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000279int
280sys_llseek (tcp)
281struct tcb *tcp;
282{
283 if (entering(tcp)) {
284 if (tcp->u_arg[4] == SEEK_SET)
285 tprintf("%ld, %llu, ", tcp->u_arg[0],
286 (((unsigned long long int) tcp->u_arg[1]) << 32
287 | (unsigned long) tcp->u_arg[2]));
288 else
289 tprintf("%ld, %lld, ", tcp->u_arg[0],
290 (((long long int) tcp->u_arg[1]) << 32
291 | (unsigned long) tcp->u_arg[2]));
292 }
293 else {
294 if (syserror(tcp))
295 tprintf("%#lx, ", tcp->u_arg[3]);
296 else {
297 long long int off;
298 umove(tcp, tcp->u_arg[3], &off);
299 tprintf("{%lld}, ", off);
300 }
301 printxval(whence, tcp->u_arg[4], "SEEK_???");
302 }
303 return 0;
304}
305#endif
306
307int
308sys_truncate(tcp)
309struct tcb *tcp;
310{
311 if (entering(tcp)) {
312 printpath(tcp, tcp->u_arg[0]);
313 tprintf(", %lu", tcp->u_arg[1]);
314 }
315 return 0;
316}
317
318int
319sys_ftruncate(tcp)
320struct tcb *tcp;
321{
322 if (entering(tcp)) {
323 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
324 }
325 return 0;
326}
327
328/* several stats */
329
330static struct xlat modetypes[] = {
331 { S_IFREG, "S_IFREG" },
332 { S_IFSOCK, "S_IFSOCK" },
333 { S_IFIFO, "S_IFIFO" },
334 { S_IFLNK, "S_IFLNK" },
335 { S_IFDIR, "S_IFDIR" },
336 { S_IFBLK, "S_IFBLK" },
337 { S_IFCHR, "S_IFCHR" },
338 { 0, NULL },
339};
340
341static char *
342sprintmode(mode)
343int mode;
344{
345 static char buf[64];
346 char *s;
347
348 if ((mode & S_IFMT) == 0)
349 s = "";
350 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
351 sprintf(buf, "%#o", mode);
352 return buf;
353 }
354 sprintf(buf, "%s%s%s%s", s,
355 (mode & S_ISUID) ? "|S_ISUID" : "",
356 (mode & S_ISGID) ? "|S_ISGID" : "",
357 (mode & S_ISVTX) ? "|S_ISVTX" : "");
358 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
359 if (mode)
360 sprintf(buf + strlen(buf), "|%#o", mode);
361 s = (*buf == '|') ? buf + 1 : buf;
362 return *s ? s : "0";
363}
364
365static char *
366sprinttime(t)
367time_t t;
368{
369 struct tm *tmp;
370 static char buf[32];
371
372 if (t == 0) {
373 sprintf(buf, "0");
374 return buf;
375 }
376 tmp = localtime(&t);
377 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
378 tmp->tm_year, tmp->tm_mon + 1, tmp->tm_mday,
379 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
380 return buf;
381}
382
383#ifdef LINUXSPARC
384typedef struct {
385 int tv_sec;
386 int tv_nsec;
387} timestruct_t;
388
389struct solstat {
390 unsigned st_dev;
391 int st_pad1[3]; /* network id */
392 unsigned st_ino;
393 unsigned st_mode;
394 unsigned st_nlink;
395 unsigned st_uid;
396 unsigned st_gid;
397 unsigned st_rdev;
398 int st_pad2[2];
399 int st_size;
400 int st_pad3; /* st_size, off_t expansion */
401 timestruct_t st_atime;
402 timestruct_t st_mtime;
403 timestruct_t st_ctime;
404 int st_blksize;
405 int st_blocks;
406 char st_fstype[16];
407 int st_pad4[8]; /* expansion area */
408};
409
410static void
411printstatsol(tcp, addr)
412struct tcb *tcp;
413int addr;
414{
415 struct solstat statbuf;
416
417 if (!addr) {
418 tprintf("NULL");
419 return;
420 }
421 if (syserror(tcp) || !verbose(tcp)) {
422 tprintf("%#x", addr);
423 return;
424 }
425 if (umove(tcp, addr, &statbuf) < 0) {
426 tprintf("{...}");
427 return;
428 }
429 if (!abbrev(tcp)) {
430 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
431 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
432 (unsigned long) (statbuf.st_dev & 0x3ffff),
433 (unsigned long) statbuf.st_ino,
434 sprintmode(statbuf.st_mode));
435 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
436 (unsigned long) statbuf.st_nlink,
437 (unsigned long) statbuf.st_uid,
438 (unsigned long) statbuf.st_gid);
439 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
440 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
441 }
442 else
443 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
444 switch (statbuf.st_mode & S_IFMT) {
445 case S_IFCHR: case S_IFBLK:
446 tprintf("st_rdev=makedev(%lu, %lu), ",
447 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
448 (unsigned long) (statbuf.st_rdev & 0x3ffff));
449 break;
450 default:
451 tprintf("st_size=%u, ", statbuf.st_size);
452 break;
453 }
454 if (!abbrev(tcp)) {
455 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
456 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
457 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
458 }
459 else
460 tprintf("...}");
461}
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000462#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000463
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000464static void
465realprintstat(tcp, statbuf)
466struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000467struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000468{
469 if (!abbrev(tcp)) {
470 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
471 (unsigned long) major(statbuf->st_dev),
472 (unsigned long) minor(statbuf->st_dev),
473 (unsigned long) statbuf->st_ino,
474 sprintmode(statbuf->st_mode));
475 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
476 (unsigned long) statbuf->st_nlink,
477 (unsigned long) statbuf->st_uid,
478 (unsigned long) statbuf->st_gid);
479#ifdef HAVE_ST_BLKSIZE
480 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
481#endif /* HAVE_ST_BLKSIZE */
482#ifdef HAVE_ST_BLOCKS
483 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
484#endif /* HAVE_ST_BLOCKS */
485 }
486 else
487 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
488 switch (statbuf->st_mode & S_IFMT) {
489 case S_IFCHR: case S_IFBLK:
490#ifdef HAVE_ST_RDEV
491 tprintf("st_rdev=makedev(%lu, %lu), ",
492 (unsigned long) major(statbuf->st_rdev),
493 (unsigned long) minor(statbuf->st_rdev));
494#else /* !HAVE_ST_RDEV */
495 tprintf("st_size=makedev(%lu, %lu), ",
496 (unsigned long) major(statbuf->st_size),
497 (unsigned long) minor(statbuf->st_size));
498#endif /* !HAVE_ST_RDEV */
499 break;
500 default:
501 tprintf("st_size=%lu, ", statbuf->st_size);
502 break;
503 }
504 if (!abbrev(tcp)) {
505 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
506 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
507 tprintf("st_ctime=%s}", sprinttime(statbuf->st_ctime));
508 }
509 else
510 tprintf("...}");
511}
512
Nate Sammons771a6ff1999-04-05 22:39:31 +0000513
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000514static void
515printstat(tcp, addr)
516struct tcb *tcp;
517int addr;
518{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000519 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520
521#ifdef LINUXSPARC
522 if (current_personality == 1) {
523 printstatsol(tcp, addr);
524 return;
525 }
526#endif /* LINUXSPARC */
527
528 if (!addr) {
529 tprintf("NULL");
530 return;
531 }
532 if (syserror(tcp) || !verbose(tcp)) {
533 tprintf("%#x", addr);
534 return;
535 }
536 if (umove(tcp, addr, &statbuf) < 0) {
537 tprintf("{...}");
538 return;
539 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000540
541 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000542}
543
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000544#ifdef linux
545static void
546convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000547const struct __old_kernel_stat *oldbuf;
548struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000549{
550 newbuf->st_dev=oldbuf->st_dev;
551 newbuf->st_ino=oldbuf->st_ino;
552 newbuf->st_mode=oldbuf->st_mode;
553 newbuf->st_nlink=oldbuf->st_nlink;
554 newbuf->st_uid=oldbuf->st_uid;
555 newbuf->st_gid=oldbuf->st_gid;
556 newbuf->st_rdev=oldbuf->st_rdev;
557 newbuf->st_size=oldbuf->st_size;
558 newbuf->st_atime=oldbuf->st_atime;
559 newbuf->st_mtime=oldbuf->st_mtime;
560 newbuf->st_ctime=oldbuf->st_ctime;
561 newbuf->st_blksize=0; /* not supported in old_stat */
562 newbuf->st_blocks=0; /* not supported in old_stat */
563}
564#endif
565
566
567#ifdef linux
568static void
569printoldstat(tcp, addr)
570struct tcb *tcp;
571int addr;
572{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000573 struct __old_kernel_stat statbuf;
574 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000575
576#ifdef LINUXSPARC
577 if (current_personality == 1) {
578 printstatsol(tcp, addr);
579 return;
580 }
581#endif /* LINUXSPARC */
582
583 if (!addr) {
584 tprintf("NULL");
585 return;
586 }
587 if (syserror(tcp) || !verbose(tcp)) {
588 tprintf("%#x", addr);
589 return;
590 }
591 if (umove(tcp, addr, &statbuf) < 0) {
592 tprintf("{...}");
593 return;
594 }
595
596 convertoldstat(&statbuf, &newstatbuf);
597 realprintstat(tcp, &newstatbuf);
598}
599#endif
600
601
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000602int
603sys_stat(tcp)
604struct tcb *tcp;
605{
606 if (entering(tcp)) {
607 printpath(tcp, tcp->u_arg[0]);
608 tprintf(", ");
609 } else {
610 printstat(tcp, tcp->u_arg[1]);
611 }
612 return 0;
613}
614
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000615#ifdef linux
616int
617sys_oldstat(tcp)
618struct tcb *tcp;
619{
620 if (entering(tcp)) {
621 printpath(tcp, tcp->u_arg[0]);
622 tprintf(", ");
623 } else {
624 printoldstat(tcp, tcp->u_arg[1]);
625 }
626 return 0;
627}
628#endif
629
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000630int
631sys_fstat(tcp)
632struct tcb *tcp;
633{
634 if (entering(tcp))
635 tprintf("%ld, ", tcp->u_arg[0]);
636 else {
637 printstat(tcp, tcp->u_arg[1]);
638 }
639 return 0;
640}
641
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000642#ifdef linux
643int
644sys_oldfstat(tcp)
645struct tcb *tcp;
646{
647 if (entering(tcp))
648 tprintf("%ld, ", tcp->u_arg[0]);
649 else {
650 printoldstat(tcp, tcp->u_arg[1]);
651 }
652 return 0;
653}
654#endif
655
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000656int
657sys_lstat(tcp)
658struct tcb *tcp;
659{
660 if (entering(tcp)) {
661 printpath(tcp, tcp->u_arg[0]);
662 tprintf(", ");
663 } else {
664 printstat(tcp, tcp->u_arg[1]);
665 }
666 return 0;
667}
668
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000669#ifdef linux
670int
671sys_oldlstat(tcp)
672struct tcb *tcp;
673{
674 if (entering(tcp)) {
675 printpath(tcp, tcp->u_arg[0]);
676 tprintf(", ");
677 } else {
678 printoldstat(tcp, tcp->u_arg[1]);
679 }
680 return 0;
681}
682#endif
683
684
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000685#if defined(SVR4) || defined(LINUXSPARC)
686
687int
688sys_xstat(tcp)
689struct tcb *tcp;
690{
691 if (entering(tcp)) {
692 tprintf("%ld, ", tcp->u_arg[0]);
693 printpath(tcp, tcp->u_arg[1]);
694 tprintf(", ");
695 } else {
696 printstat(tcp, tcp->u_arg[2]);
697 }
698 return 0;
699}
700
701int
702sys_fxstat(tcp)
703struct tcb *tcp;
704{
705 if (entering(tcp))
706 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
707 else {
708 printstat(tcp, tcp->u_arg[2]);
709 }
710 return 0;
711}
712
713int
714sys_lxstat(tcp)
715struct tcb *tcp;
716{
717 if (entering(tcp)) {
718 tprintf("%ld, ", tcp->u_arg[0]);
719 printpath(tcp, tcp->u_arg[1]);
720 tprintf(", ");
721 } else {
722 printstat(tcp, tcp->u_arg[2]);
723 }
724 return 0;
725}
726
727int
728sys_xmknod(tcp)
729struct tcb *tcp;
730{
731 int mode = tcp->u_arg[2];
732
733 if (entering(tcp)) {
734 tprintf("%ld, ", tcp->u_arg[0]);
735 printpath(tcp, tcp->u_arg[1]);
736 tprintf(", %s", sprintmode(mode));
737 switch (mode & S_IFMT) {
738 case S_IFCHR: case S_IFBLK:
739#ifdef LINUXSPARC
740 tprintf(", makedev(%lu, %lu)",
741 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
742 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
743#else
744 tprintf(", makedev(%lu, %lu)",
745 (unsigned long) major(tcp->u_arg[3]),
746 (unsigned long) minor(tcp->u_arg[3]));
747#endif
748 break;
749 default:
750 break;
751 }
752 }
753 return 0;
754}
755
756#endif /* SVR4 || LINUXSPARC */
757
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000758#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000759
760static struct xlat fsmagic[] = {
761 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
762 { 0xef53, "EXT2_SUPER_MAGIC" },
763 { 0x137d, "EXT_SUPER_MAGIC" },
764 { 0x9660, "ISOFS_SUPER_MAGIC" },
765 { 0x137f, "MINIX_SUPER_MAGIC" },
766 { 0x138f, "MINIX_SUPER_MAGIC2" },
767 { 0x2468, "NEW_MINIX_SUPER_MAGIC" },
768 { 0x4d44, "MSDOS_SUPER_MAGIC" },
769 { 0x6969, "NFS_SUPER_MAGIC" },
770 { 0x9fa0, "PROC_SUPER_MAGIC" },
771 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
772 { 0, NULL },
773};
774
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000775#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000776
777#ifndef SVR4
778
779static char *
780sprintfstype(magic)
781int magic;
782{
783 static char buf[32];
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000784#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000785 char *s;
786
787 s = xlookup(fsmagic, magic);
788 if (s) {
789 sprintf(buf, "\"%s\"", s);
790 return buf;
791 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000792#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000793 sprintf(buf, "%#x", magic);
794 return buf;
795}
796
797static void
798printstatfs(tcp, addr)
799struct tcb *tcp;
800long addr;
801{
802 struct statfs statbuf;
803
804 if (syserror(tcp) || !verbose(tcp)) {
805 tprintf("%#lx", addr);
806 return;
807 }
808 if (umove(tcp, addr, &statbuf) < 0) {
809 tprintf("{...}");
810 return;
811 }
812#ifdef ALPHA
813
814 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
815 sprintfstype(statbuf.f_type),
816 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
817 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_namelen=%u}",
818 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree, statbuf.f_namelen);
819#else /* !ALPHA */
820 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
821 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +0000822 (unsigned long)statbuf.f_bsize,
823 (unsigned long)statbuf.f_blocks,
824 (unsigned long)statbuf.f_bfree);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000825 tprintf("f_files=%lu, f_ffree=%lu",
Nate Sammons5c74d201999-04-06 01:37:51 +0000826 (unsigned long)statbuf.f_files,
827 (unsigned long)statbuf.f_ffree);
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000828#ifdef linux
Nate Sammons5c74d201999-04-06 01:37:51 +0000829 tprintf(", f_namelen=%lu}", (unsigned long)statbuf.f_namelen);
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000830#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000831#endif /* !ALPHA */
832 tprintf("}");
833}
834
835int
836sys_statfs(tcp)
837struct tcb *tcp;
838{
839 if (entering(tcp)) {
840 printpath(tcp, tcp->u_arg[0]);
841 tprintf(", ");
842 } else {
843 printstatfs(tcp, tcp->u_arg[1]);
844 }
845 return 0;
846}
847
848int
849sys_fstatfs(tcp)
850struct tcb *tcp;
851{
852 if (entering(tcp)) {
853 tprintf("%lu, ", tcp->u_arg[0]);
854 } else {
855 printstatfs(tcp, tcp->u_arg[1]);
856 }
857 return 0;
858}
859
Wichert Akkermana0f36c61999-04-16 14:01:34 +0000860#if defined(linux) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000861
862int
863osf_statfs(tcp)
864struct tcb *tcp;
865{
866 if (entering(tcp)) {
867 printpath(tcp, tcp->u_arg[0]);
868 tprintf(", ");
869 } else {
870 printstatfs(tcp, tcp->u_arg[1]);
871 tprintf(", %lu", tcp->u_arg[2]);
872 }
873 return 0;
874}
875
876int
877osf_fstatfs(tcp)
878struct tcb *tcp;
879{
880 if (entering(tcp)) {
881 tprintf("%lu, ", tcp->u_arg[0]);
882 } else {
883 printstatfs(tcp, tcp->u_arg[1]);
884 tprintf(", %lu", tcp->u_arg[2]);
885 }
886 return 0;
887}
Wichert Akkermana0f36c61999-04-16 14:01:34 +0000888#endif /* linux && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000889
890#endif /* !SVR4 */
891
892#ifdef SUNOS4
893
894int
895sys_ustat(tcp)
896struct tcb *tcp;
897{
898 struct ustat statbuf;
899
900 if (entering(tcp)) {
901 tprintf("makedev(%lu, %lu), ",
902 (long) major(tcp->u_arg[0]),
903 (long) minor(tcp->u_arg[0]));
904 }
905 else {
906 if (syserror(tcp) || !verbose(tcp))
907 tprintf("%#lx", tcp->u_arg[1]);
908 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
909 tprintf("{...}");
910 else {
911 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
912 statbuf.f_tfree, statbuf.f_tinode);
913 tprintf("f_fname=\"%.*s\", ",
914 (int) sizeof(statbuf.f_fname),
915 statbuf.f_fname);
916 tprintf("f_fpack=\"%.*s\"}",
917 (int) sizeof(statbuf.f_fpack),
918 statbuf.f_fpack);
919 }
920 }
921 return 0;
922}
923
924#endif /* SUNOS4 */
925
926/* directory */
927int
928sys_chdir(tcp)
929struct tcb *tcp;
930{
931 if (entering(tcp)) {
932 printpath(tcp, tcp->u_arg[0]);
933 }
934 return 0;
935}
936
937int
938sys_mkdir(tcp)
939struct tcb *tcp;
940{
941 if (entering(tcp)) {
942 printpath(tcp, tcp->u_arg[0]);
943 tprintf(", %#lo", tcp->u_arg[1]);
944 }
945 return 0;
946}
947
948int
949sys_rmdir(tcp)
950struct tcb *tcp;
951{
952 if (entering(tcp)) {
953 printpath(tcp, tcp->u_arg[0]);
954 }
955 return 0;
956}
957
958int
959sys_fchdir(tcp)
960struct tcb *tcp;
961{
962 if (entering(tcp)) {
963 tprintf("%ld", tcp->u_arg[0]);
964 }
965 return 0;
966}
967
968int
969sys_chroot(tcp)
970struct tcb *tcp;
971{
972 if (entering(tcp)) {
973 printpath(tcp, tcp->u_arg[0]);
974 }
975 return 0;
976}
977
978int
979sys_fchroot(tcp)
980struct tcb *tcp;
981{
982 if (entering(tcp)) {
983 tprintf("%ld", tcp->u_arg[0]);
984 }
985 return 0;
986}
987
988int
989sys_link(tcp)
990struct tcb *tcp;
991{
992 if (entering(tcp)) {
993 printpath(tcp, tcp->u_arg[0]);
994 tprintf(", ");
995 printpath(tcp, tcp->u_arg[1]);
996 }
997 return 0;
998}
999
1000int
1001sys_unlink(tcp)
1002struct tcb *tcp;
1003{
1004 if (entering(tcp)) {
1005 printpath(tcp, tcp->u_arg[0]);
1006 }
1007 return 0;
1008}
1009
1010int
1011sys_symlink(tcp)
1012struct tcb *tcp;
1013{
1014 if (entering(tcp)) {
1015 printpath(tcp, tcp->u_arg[0]);
1016 tprintf(", ");
1017 printpath(tcp, tcp->u_arg[1]);
1018 }
1019 return 0;
1020}
1021
1022int
1023sys_readlink(tcp)
1024struct tcb *tcp;
1025{
1026 if (entering(tcp)) {
1027 printpath(tcp, tcp->u_arg[0]);
1028 tprintf(", ");
1029 } else {
1030 if (syserror(tcp))
1031 tprintf("%#lx", tcp->u_arg[1]);
1032 else
1033 printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
1034 tprintf(", %lu", tcp->u_arg[2]);
1035 }
1036 return 0;
1037}
1038
1039int
1040sys_rename(tcp)
1041struct tcb *tcp;
1042{
1043 if (entering(tcp)) {
1044 printpath(tcp, tcp->u_arg[0]);
1045 tprintf(", ");
1046 printpath(tcp, tcp->u_arg[1]);
1047 }
1048 return 0;
1049}
1050
1051int
1052sys_chown(tcp)
1053struct tcb *tcp;
1054{
1055 if (entering(tcp)) {
1056 printpath(tcp, tcp->u_arg[0]);
1057 tprintf(", %lu, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1058 }
1059 return 0;
1060}
1061
1062int
1063sys_fchown(tcp)
1064struct tcb *tcp;
1065{
1066 if (entering(tcp)) {
1067 tprintf("%ld, %lu, %lu",
1068 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1069 }
1070 return 0;
1071}
1072
1073int
1074sys_chmod(tcp)
1075struct tcb *tcp;
1076{
1077 if (entering(tcp)) {
1078 printpath(tcp, tcp->u_arg[0]);
1079 tprintf(", %#lo", tcp->u_arg[1]);
1080 }
1081 return 0;
1082}
1083
1084int
1085sys_fchmod(tcp)
1086struct tcb *tcp;
1087{
1088 if (entering(tcp)) {
1089 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
1090 }
1091 return 0;
1092}
1093
1094int
1095sys_utimes(tcp)
1096struct tcb *tcp;
1097{
1098 if (entering(tcp)) {
1099 printpath(tcp, tcp->u_arg[0]);
1100 tprintf(", ");
1101 printtv(tcp, tcp->u_arg[1]);
1102 }
1103 return 0;
1104}
1105
1106int
1107sys_utime(tcp)
1108struct tcb *tcp;
1109{
1110 long ut[2];
1111
1112 if (entering(tcp)) {
1113 printpath(tcp, tcp->u_arg[0]);
1114 tprintf(", ");
1115 if (!tcp->u_arg[1])
1116 tprintf("NULL");
1117 else if (!verbose(tcp))
1118 tprintf("%#lx", tcp->u_arg[1]);
1119 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
1120 (char *) ut) < 0)
1121 tprintf("[?, ?]");
1122 else {
1123 tprintf("[%s,", sprinttime(ut[0]));
1124 tprintf(" %s]", sprinttime(ut[1]));
1125 }
1126 }
1127 return 0;
1128}
1129
1130int
1131sys_mknod(tcp)
1132struct tcb *tcp;
1133{
1134 int mode = tcp->u_arg[1];
1135
1136 if (entering(tcp)) {
1137 printpath(tcp, tcp->u_arg[0]);
1138 tprintf(", %s", sprintmode(mode));
1139 switch (mode & S_IFMT) {
1140 case S_IFCHR: case S_IFBLK:
1141#ifdef LINUXSPARC
1142 if (current_personality == 1)
1143 tprintf(", makedev(%lu, %lu)",
1144 (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
1145 (unsigned long) (tcp->u_arg[2] & 0x3ffff));
1146 else
1147#endif
1148 tprintf(", makedev(%lu, %lu)",
1149 (unsigned long) major(tcp->u_arg[2]),
1150 (unsigned long) minor(tcp->u_arg[2]));
1151 break;
1152 default:
1153 break;
1154 }
1155 }
1156 return 0;
1157}
1158
1159int
1160sys_mkfifo(tcp)
1161struct tcb *tcp;
1162{
1163 if (entering(tcp)) {
1164 printpath(tcp, tcp->u_arg[0]);
1165 tprintf(", %#lo", tcp->u_arg[1]);
1166 }
1167 return 0;
1168}
1169
1170int
1171sys_fsync(tcp)
1172struct tcb *tcp;
1173{
1174 if (entering(tcp)) {
1175 tprintf("%ld", tcp->u_arg[0]);
1176 }
1177 return 0;
1178}
1179
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001180#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001181
1182static void
1183printdir(tcp, addr)
1184struct tcb *tcp;
1185long addr;
1186{
1187 struct dirent d;
1188
1189 if (!verbose(tcp)) {
1190 tprintf("%#lx", addr);
1191 return;
1192 }
1193 if (umove(tcp, addr, &d) < 0) {
1194 tprintf("{...}");
1195 return;
1196 }
1197 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001198 tprintf("d_name=");
1199 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
1200 tprintf("}");
1201}
1202
1203int
1204sys_readdir(tcp)
1205struct tcb *tcp;
1206{
1207 if (entering(tcp)) {
1208 tprintf("%lu, ", tcp->u_arg[0]);
1209 } else {
1210 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
1211 tprintf("%#lx", tcp->u_arg[1]);
1212 else
1213 printdir(tcp, tcp->u_arg[1]);
1214 /* Not much point in printing this out, it is always 1. */
1215 if (tcp->u_arg[2] != 1)
1216 tprintf(", %lu", tcp->u_arg[2]);
1217 }
1218 return 0;
1219}
1220
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001221#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001222
1223int
1224sys_getdents(tcp)
1225struct tcb *tcp;
1226{
1227 int i, len, dents = 0;
1228 char *buf;
1229
1230 if (entering(tcp)) {
1231 tprintf("%lu, ", tcp->u_arg[0]);
1232 return 0;
1233 }
1234 if (syserror(tcp) || !verbose(tcp)) {
1235 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1236 return 0;
1237 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001238 len = tcp->u_rval;
1239 if ((buf = malloc(len)) == NULL) {
1240 tprintf("out of memory\n");
1241 return 0;
1242 }
1243 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1244 tprintf("{...}, %lu", tcp->u_arg[2]);
1245 free(buf);
1246 return 0;
1247 }
1248 if (!abbrev(tcp))
1249 tprintf("{");
1250 for (i = 0; i < len;) {
1251 struct dirent *d = (struct dirent *) &buf[i];
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001252#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001253 if (!abbrev(tcp)) {
1254 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1255 i ? " " : "", d->d_ino, d->d_off);
1256 tprintf("d_reclen=%u, d_name=\"%s\"}",
1257 d->d_reclen, d->d_name);
1258 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001259#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001260#ifdef SVR4
1261 if (!abbrev(tcp)) {
1262 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1263 i ? " " : "", d->d_ino, d->d_off);
1264 tprintf("d_reclen=%u, d_name=\"%s\"}",
1265 d->d_reclen, d->d_name);
1266 }
1267#endif /* SVR4 */
1268#ifdef SUNOS4
1269 if (!abbrev(tcp)) {
1270 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
1271 i ? " " : "", d->d_off, d->d_fileno,
1272 d->d_reclen);
1273 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
1274 d->d_namlen, d->d_namlen, d->d_name);
1275 }
1276#endif /* SUNOS4 */
1277 i += d->d_reclen;
1278 dents++;
1279 }
1280 if (!abbrev(tcp))
1281 tprintf("}");
1282 else
1283 tprintf("/* %u entries */", dents);
1284 tprintf(", %lu", tcp->u_arg[2]);
1285 free(buf);
1286 return 0;
1287}
1288
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001289#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001290
1291int
1292sys_getcwd(tcp)
1293struct tcb *tcp;
1294{
1295 if (exiting(tcp)) {
1296 if (syserror(tcp))
1297 tprintf("%#lx", tcp->u_arg[0]);
1298 else
1299 printstr(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1300 tprintf(", %lu", tcp->u_arg[1]);
1301 }
1302 return 0;
1303}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001304#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001305
1306#ifdef HAVE_SYS_ASYNCH_H
1307
1308int
1309sys_aioread(tcp)
1310struct tcb *tcp;
1311{
1312 struct aio_result_t res;
1313
1314 if (entering(tcp)) {
1315 tprintf("%lu, ", tcp->u_arg[0]);
1316 } else {
1317 if (syserror(tcp))
1318 tprintf("%#lx", tcp->u_arg[1]);
1319 else
1320 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1321 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
1322 printxval(whence, tcp->u_arg[4], "L_???");
1323 if (syserror(tcp) || tcp->u_arg[5] == 0
1324 || umove(tcp, tcp->u_arg[5], &res) < 0)
1325 tprintf(", %#lx", tcp->u_arg[5]);
1326 else
1327 tprintf(", {aio_return %d aio_errno %d}",
1328 res.aio_return, res.aio_errno);
1329 }
1330 return 0;
1331}
1332
1333int
1334sys_aiowrite(tcp)
1335struct tcb *tcp;
1336{
1337 struct aio_result_t res;
1338
1339 if (entering(tcp)) {
1340 tprintf("%lu, ", tcp->u_arg[0]);
1341 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1342 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
1343 printxval(whence, tcp->u_arg[4], "L_???");
1344 }
1345 else {
1346 if (tcp->u_arg[5] == 0)
1347 tprintf(", NULL");
1348 else if (syserror(tcp)
1349 || umove(tcp, tcp->u_arg[5], &res) < 0)
1350 tprintf(", %#lx", tcp->u_arg[5]);
1351 else
1352 tprintf(", {aio_return %d aio_errno %d}",
1353 res.aio_return, res.aio_errno);
1354 }
1355 return 0;
1356}
1357
1358int
1359sys_aiowait(tcp)
1360struct tcb *tcp;
1361{
1362 if (entering(tcp))
1363 printtv(tcp, tcp->u_arg[0]);
1364 return 0;
1365}
1366
1367int
1368sys_aiocancel(tcp)
1369struct tcb *tcp;
1370{
1371 struct aio_result_t res;
1372
1373 if (exiting(tcp)) {
1374 if (tcp->u_arg[0] == 0)
1375 tprintf("NULL");
1376 else if (syserror(tcp)
1377 || umove(tcp, tcp->u_arg[0], &res) < 0)
1378 tprintf("%#lx", tcp->u_arg[0]);
1379 else
1380 tprintf("{aio_return %d aio_errno %d}",
1381 res.aio_return, res.aio_errno);
1382 }
1383 return 0;
1384}
1385
1386#endif /* HAVE_SYS_ASYNCH_H */