blob: 57122168f7ad6c87c07cf5e54f0c0ac15e946558 [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
109# include <sys/stat.h>
110# undef stat
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000111#else
112# include <sys/stat.h>
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000113#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000114
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000115#include <fcntl.h>
116
117#ifdef SVR4
118# include <sys/cred.h>
119#endif /* SVR4 */
120
121#include <sys/vfs.h>
122
123#ifdef MAJOR_IN_SYSMACROS
124#include <sys/sysmacros.h>
125#endif
126
127#ifdef MAJOR_IN_MKDEV
128#include <sys/mkdev.h>
129#endif
130
131#ifdef HAVE_SYS_ASYNCH_H
132#include <sys/asynch.h>
133#endif
134
135#ifdef SUNOS4
136#include <ustat.h>
137#endif
138
139/*
140 * This is a really dirty trick but it should always work. Traditional
141 * Unix says r/w/rw are 0/1/2, so we make them true flags 1/2/3 by
142 * adding 1. Just remember to add 1 to any arg decoded with openmodes.
143 */
144struct xlat openmodes[] = {
145 { O_RDWR+1, "O_RDWR" },
146 { O_RDONLY+1, "O_RDONLY" },
147 { O_WRONLY+1, "O_WRONLY" },
148 { O_NONBLOCK, "O_NONBLOCK" },
149 { O_APPEND, "O_APPEND" },
150 { O_CREAT, "O_CREAT" },
151 { O_TRUNC, "O_TRUNC" },
152 { O_EXCL, "O_EXCL" },
153 { O_NOCTTY, "O_NOCTTY" },
154#ifdef O_SYNC
155 { O_SYNC, "O_SYNC" },
156#endif
157#ifdef O_ASYNC
158 { O_ASYNC, "O_ASYNC" },
159#endif
160#ifdef O_DSYNC
161 { O_DSYNC, "O_DSYNC" },
162#endif
163#ifdef O_RSYNC
164 { O_RSYNC, "O_RSYNC" },
165#endif
166#ifdef O_NDELAY
167 { O_NDELAY, "O_NDELAY" },
168#endif
169#ifdef O_PRIV
170 { O_PRIV, "O_PRIV" },
171#endif
172#ifdef O_DIRECT
173 { O_DIRECT, "O_DIRECT" },
174#endif
175#ifdef O_LARGEFILE
176 { O_LARGEFILE, "O_LARGEFILE" },
177#endif
178#ifdef O_DIRECTORY
179 { O_DIRECTORY, "O_DIRECTORY" },
180#endif
181
182#ifdef FNDELAY
183 { FNDELAY, "FNDELAY" },
184#endif
185#ifdef FAPPEND
186 { FAPPEND, "FAPPEND" },
187#endif
188#ifdef FMARK
189 { FMARK, "FMARK" },
190#endif
191#ifdef FDEFER
192 { FDEFER, "FDEFER" },
193#endif
194#ifdef FASYNC
195 { FASYNC, "FASYNC" },
196#endif
197#ifdef FSHLOCK
198 { FSHLOCK, "FSHLOCK" },
199#endif
200#ifdef FEXLOCK
201 { FEXLOCK, "FEXLOCK" },
202#endif
203#ifdef FCREAT
204 { FCREAT, "FCREAT" },
205#endif
206#ifdef FTRUNC
207 { FTRUNC, "FTRUNC" },
208#endif
209#ifdef FEXCL
210 { FEXCL, "FEXCL" },
211#endif
212#ifdef FNBIO
213 { FNBIO, "FNBIO" },
214#endif
215#ifdef FSYNC
216 { FSYNC, "FSYNC" },
217#endif
218#ifdef FNOCTTY
219 { FNOCTTY, "FNOCTTY" },
220#endif
221 { 0, NULL },
222};
223
224int
225sys_open(tcp)
226struct tcb *tcp;
227{
228 if (entering(tcp)) {
229 printpath(tcp, tcp->u_arg[0]);
230 tprintf(", ");
231 /* flags */
232 printflags(openmodes, tcp->u_arg[1] + 1);
233 if (tcp->u_arg[1] & O_CREAT) {
234 /* mode */
235 tprintf(", %#lo", tcp->u_arg[2]);
236 }
237 }
238 return 0;
239}
240
241#ifdef LINUXSPARC
242struct xlat openmodessol[] = {
243 { 0, "O_RDWR" },
244 { 1, "O_RDONLY" },
245 { 2, "O_WRONLY" },
246 { 0x80, "O_NONBLOCK" },
247 { 8, "O_APPEND" },
248 { 0x100, "O_CREAT" },
249 { 0x200, "O_TRUNC" },
250 { 0x400, "O_EXCL" },
251 { 0x800, "O_NOCTTY" },
252 { 0x10, "O_SYNC" },
253 { 0x40, "O_DSYNC" },
254 { 0x8000, "O_RSYNC" },
255 { 4, "O_NDELAY" },
256 { 0x1000, "O_PRIV" },
257 { 0, NULL },
258};
259
260int
261solaris_open(tcp)
262struct tcb *tcp;
263{
264 if (entering(tcp)) {
265 printpath(tcp, tcp->u_arg[0]);
266 tprintf(", ");
267 /* flags */
268 printflags(openmodessol, tcp->u_arg[1] + 1);
269 if (tcp->u_arg[1] & 0x100) {
270 /* mode */
271 tprintf(", %#lo", tcp->u_arg[2]);
272 }
273 }
274 return 0;
275}
276
277#endif
278
279int
280sys_creat(tcp)
281struct tcb *tcp;
282{
283 if (entering(tcp)) {
284 printpath(tcp, tcp->u_arg[0]);
285 tprintf(", %#lo", tcp->u_arg[1]);
286 }
287 return 0;
288}
289
290static struct xlat access_flags[] = {
291 { F_OK, "F_OK", },
292 { R_OK, "R_OK" },
293 { W_OK, "W_OK" },
294 { X_OK, "X_OK" },
295#ifdef EFF_ONLY_OK
296 { EFF_ONLY_OK, "EFF_ONLY_OK" },
297#endif
298#ifdef EX_OK
299 { EX_OK, "EX_OK" },
300#endif
301 { 0, NULL },
302};
303
304int
305sys_access(tcp)
306struct tcb *tcp;
307{
308 if (entering(tcp)) {
309 printpath(tcp, tcp->u_arg[0]);
310 tprintf(", ");
311 printflags(access_flags, tcp->u_arg[1]);
312 }
313 return 0;
314}
315
316int
317sys_umask(tcp)
318struct tcb *tcp;
319{
320 if (entering(tcp)) {
321 tprintf("%#lo", tcp->u_arg[0]);
322 }
323 return RVAL_OCTAL;
324}
325
326static struct xlat whence[] = {
327 { SEEK_SET, "SEEK_SET" },
328 { SEEK_CUR, "SEEK_CUR" },
329 { SEEK_END, "SEEK_END" },
330 { 0, NULL },
331};
332
333int
334sys_lseek(tcp)
335struct tcb *tcp;
336{
337 if (entering(tcp)) {
338 tprintf("%ld, ", tcp->u_arg[0]);
339 if (tcp->u_arg[2] == SEEK_SET)
340 tprintf("%lu, ", tcp->u_arg[1]);
341 else
342 tprintf("%ld, ", tcp->u_arg[1]);
343 printxval(whence, tcp->u_arg[2], "SEEK_???");
344 }
345 return RVAL_UDECIMAL;
346}
347
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000348#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000349int
350sys_llseek (tcp)
351struct tcb *tcp;
352{
353 if (entering(tcp)) {
354 if (tcp->u_arg[4] == SEEK_SET)
355 tprintf("%ld, %llu, ", tcp->u_arg[0],
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000356 (((long long int) tcp->u_arg[1]) << 32
357 | (unsigned long long) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000358 else
359 tprintf("%ld, %lld, ", tcp->u_arg[0],
360 (((long long int) tcp->u_arg[1]) << 32
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000361 | (unsigned long long) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000362 }
363 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000364 long long int off;
365 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000366 tprintf("%#lx, ", tcp->u_arg[3]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000367 else
368 tprintf("[%llu], ", off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000369 printxval(whence, tcp->u_arg[4], "SEEK_???");
370 }
371 return 0;
372}
373#endif
374
375int
376sys_truncate(tcp)
377struct tcb *tcp;
378{
379 if (entering(tcp)) {
380 printpath(tcp, tcp->u_arg[0]);
381 tprintf(", %lu", tcp->u_arg[1]);
382 }
383 return 0;
384}
385
386int
387sys_ftruncate(tcp)
388struct tcb *tcp;
389{
390 if (entering(tcp)) {
391 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
392 }
393 return 0;
394}
395
396/* several stats */
397
398static struct xlat modetypes[] = {
399 { S_IFREG, "S_IFREG" },
400 { S_IFSOCK, "S_IFSOCK" },
401 { S_IFIFO, "S_IFIFO" },
402 { S_IFLNK, "S_IFLNK" },
403 { S_IFDIR, "S_IFDIR" },
404 { S_IFBLK, "S_IFBLK" },
405 { S_IFCHR, "S_IFCHR" },
406 { 0, NULL },
407};
408
409static char *
410sprintmode(mode)
411int mode;
412{
413 static char buf[64];
414 char *s;
415
416 if ((mode & S_IFMT) == 0)
417 s = "";
418 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
419 sprintf(buf, "%#o", mode);
420 return buf;
421 }
422 sprintf(buf, "%s%s%s%s", s,
423 (mode & S_ISUID) ? "|S_ISUID" : "",
424 (mode & S_ISGID) ? "|S_ISGID" : "",
425 (mode & S_ISVTX) ? "|S_ISVTX" : "");
426 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
427 if (mode)
428 sprintf(buf + strlen(buf), "|%#o", mode);
429 s = (*buf == '|') ? buf + 1 : buf;
430 return *s ? s : "0";
431}
432
433static char *
434sprinttime(t)
435time_t t;
436{
437 struct tm *tmp;
438 static char buf[32];
439
440 if (t == 0) {
441 sprintf(buf, "0");
442 return buf;
443 }
444 tmp = localtime(&t);
445 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
446 tmp->tm_year, tmp->tm_mon + 1, tmp->tm_mday,
447 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
448 return buf;
449}
450
451#ifdef LINUXSPARC
452typedef struct {
453 int tv_sec;
454 int tv_nsec;
455} timestruct_t;
456
457struct solstat {
458 unsigned st_dev;
459 int st_pad1[3]; /* network id */
460 unsigned st_ino;
461 unsigned st_mode;
462 unsigned st_nlink;
463 unsigned st_uid;
464 unsigned st_gid;
465 unsigned st_rdev;
466 int st_pad2[2];
467 int st_size;
468 int st_pad3; /* st_size, off_t expansion */
469 timestruct_t st_atime;
470 timestruct_t st_mtime;
471 timestruct_t st_ctime;
472 int st_blksize;
473 int st_blocks;
474 char st_fstype[16];
475 int st_pad4[8]; /* expansion area */
476};
477
478static void
479printstatsol(tcp, addr)
480struct tcb *tcp;
481int addr;
482{
483 struct solstat statbuf;
484
485 if (!addr) {
486 tprintf("NULL");
487 return;
488 }
489 if (syserror(tcp) || !verbose(tcp)) {
490 tprintf("%#x", addr);
491 return;
492 }
493 if (umove(tcp, addr, &statbuf) < 0) {
494 tprintf("{...}");
495 return;
496 }
497 if (!abbrev(tcp)) {
498 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
499 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
500 (unsigned long) (statbuf.st_dev & 0x3ffff),
501 (unsigned long) statbuf.st_ino,
502 sprintmode(statbuf.st_mode));
503 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
504 (unsigned long) statbuf.st_nlink,
505 (unsigned long) statbuf.st_uid,
506 (unsigned long) statbuf.st_gid);
507 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
508 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
509 }
510 else
511 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
512 switch (statbuf.st_mode & S_IFMT) {
513 case S_IFCHR: case S_IFBLK:
514 tprintf("st_rdev=makedev(%lu, %lu), ",
515 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
516 (unsigned long) (statbuf.st_rdev & 0x3ffff));
517 break;
518 default:
519 tprintf("st_size=%u, ", statbuf.st_size);
520 break;
521 }
522 if (!abbrev(tcp)) {
523 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
524 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
525 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
526 }
527 else
528 tprintf("...}");
529}
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000530#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000531
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000532static void
533realprintstat(tcp, statbuf)
534struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000535struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000536{
537 if (!abbrev(tcp)) {
538 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
539 (unsigned long) major(statbuf->st_dev),
540 (unsigned long) minor(statbuf->st_dev),
541 (unsigned long) statbuf->st_ino,
542 sprintmode(statbuf->st_mode));
543 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
544 (unsigned long) statbuf->st_nlink,
545 (unsigned long) statbuf->st_uid,
546 (unsigned long) statbuf->st_gid);
547#ifdef HAVE_ST_BLKSIZE
548 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
549#endif /* HAVE_ST_BLKSIZE */
550#ifdef HAVE_ST_BLOCKS
551 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
552#endif /* HAVE_ST_BLOCKS */
553 }
554 else
555 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
556 switch (statbuf->st_mode & S_IFMT) {
557 case S_IFCHR: case S_IFBLK:
558#ifdef HAVE_ST_RDEV
559 tprintf("st_rdev=makedev(%lu, %lu), ",
560 (unsigned long) major(statbuf->st_rdev),
561 (unsigned long) minor(statbuf->st_rdev));
562#else /* !HAVE_ST_RDEV */
563 tprintf("st_size=makedev(%lu, %lu), ",
564 (unsigned long) major(statbuf->st_size),
565 (unsigned long) minor(statbuf->st_size));
566#endif /* !HAVE_ST_RDEV */
567 break;
568 default:
569 tprintf("st_size=%lu, ", statbuf->st_size);
570 break;
571 }
572 if (!abbrev(tcp)) {
573 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
574 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
575 tprintf("st_ctime=%s}", sprinttime(statbuf->st_ctime));
576 }
577 else
578 tprintf("...}");
579}
580
Nate Sammons771a6ff1999-04-05 22:39:31 +0000581
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000582static void
583printstat(tcp, addr)
584struct tcb *tcp;
585int addr;
586{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000587 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000588
589#ifdef LINUXSPARC
590 if (current_personality == 1) {
591 printstatsol(tcp, addr);
592 return;
593 }
594#endif /* LINUXSPARC */
595
596 if (!addr) {
597 tprintf("NULL");
598 return;
599 }
600 if (syserror(tcp) || !verbose(tcp)) {
601 tprintf("%#x", addr);
602 return;
603 }
604 if (umove(tcp, addr, &statbuf) < 0) {
605 tprintf("{...}");
606 return;
607 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000608
609 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000610}
611
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000612#ifdef linux
613static void
614convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000615const struct __old_kernel_stat *oldbuf;
616struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000617{
618 newbuf->st_dev=oldbuf->st_dev;
619 newbuf->st_ino=oldbuf->st_ino;
620 newbuf->st_mode=oldbuf->st_mode;
621 newbuf->st_nlink=oldbuf->st_nlink;
622 newbuf->st_uid=oldbuf->st_uid;
623 newbuf->st_gid=oldbuf->st_gid;
624 newbuf->st_rdev=oldbuf->st_rdev;
625 newbuf->st_size=oldbuf->st_size;
626 newbuf->st_atime=oldbuf->st_atime;
627 newbuf->st_mtime=oldbuf->st_mtime;
628 newbuf->st_ctime=oldbuf->st_ctime;
629 newbuf->st_blksize=0; /* not supported in old_stat */
630 newbuf->st_blocks=0; /* not supported in old_stat */
631}
632#endif
633
634
635#ifdef linux
636static void
637printoldstat(tcp, addr)
638struct tcb *tcp;
639int addr;
640{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000641 struct __old_kernel_stat statbuf;
642 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000643
644#ifdef LINUXSPARC
645 if (current_personality == 1) {
646 printstatsol(tcp, addr);
647 return;
648 }
649#endif /* LINUXSPARC */
650
651 if (!addr) {
652 tprintf("NULL");
653 return;
654 }
655 if (syserror(tcp) || !verbose(tcp)) {
656 tprintf("%#x", addr);
657 return;
658 }
659 if (umove(tcp, addr, &statbuf) < 0) {
660 tprintf("{...}");
661 return;
662 }
663
664 convertoldstat(&statbuf, &newstatbuf);
665 realprintstat(tcp, &newstatbuf);
666}
667#endif
668
669
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000670int
671sys_stat(tcp)
672struct tcb *tcp;
673{
674 if (entering(tcp)) {
675 printpath(tcp, tcp->u_arg[0]);
676 tprintf(", ");
677 } else {
678 printstat(tcp, tcp->u_arg[1]);
679 }
680 return 0;
681}
682
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000683#ifdef linux
684int
685sys_oldstat(tcp)
686struct tcb *tcp;
687{
688 if (entering(tcp)) {
689 printpath(tcp, tcp->u_arg[0]);
690 tprintf(", ");
691 } else {
692 printoldstat(tcp, tcp->u_arg[1]);
693 }
694 return 0;
695}
696#endif
697
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000698int
699sys_fstat(tcp)
700struct tcb *tcp;
701{
702 if (entering(tcp))
703 tprintf("%ld, ", tcp->u_arg[0]);
704 else {
705 printstat(tcp, tcp->u_arg[1]);
706 }
707 return 0;
708}
709
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000710#ifdef linux
711int
712sys_oldfstat(tcp)
713struct tcb *tcp;
714{
715 if (entering(tcp))
716 tprintf("%ld, ", tcp->u_arg[0]);
717 else {
718 printoldstat(tcp, tcp->u_arg[1]);
719 }
720 return 0;
721}
722#endif
723
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000724int
725sys_lstat(tcp)
726struct tcb *tcp;
727{
728 if (entering(tcp)) {
729 printpath(tcp, tcp->u_arg[0]);
730 tprintf(", ");
731 } else {
732 printstat(tcp, tcp->u_arg[1]);
733 }
734 return 0;
735}
736
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000737#ifdef linux
738int
739sys_oldlstat(tcp)
740struct tcb *tcp;
741{
742 if (entering(tcp)) {
743 printpath(tcp, tcp->u_arg[0]);
744 tprintf(", ");
745 } else {
746 printoldstat(tcp, tcp->u_arg[1]);
747 }
748 return 0;
749}
750#endif
751
752
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000753#if defined(SVR4) || defined(LINUXSPARC)
754
755int
756sys_xstat(tcp)
757struct tcb *tcp;
758{
759 if (entering(tcp)) {
760 tprintf("%ld, ", tcp->u_arg[0]);
761 printpath(tcp, tcp->u_arg[1]);
762 tprintf(", ");
763 } else {
764 printstat(tcp, tcp->u_arg[2]);
765 }
766 return 0;
767}
768
769int
770sys_fxstat(tcp)
771struct tcb *tcp;
772{
773 if (entering(tcp))
774 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
775 else {
776 printstat(tcp, tcp->u_arg[2]);
777 }
778 return 0;
779}
780
781int
782sys_lxstat(tcp)
783struct tcb *tcp;
784{
785 if (entering(tcp)) {
786 tprintf("%ld, ", tcp->u_arg[0]);
787 printpath(tcp, tcp->u_arg[1]);
788 tprintf(", ");
789 } else {
790 printstat(tcp, tcp->u_arg[2]);
791 }
792 return 0;
793}
794
795int
796sys_xmknod(tcp)
797struct tcb *tcp;
798{
799 int mode = tcp->u_arg[2];
800
801 if (entering(tcp)) {
802 tprintf("%ld, ", tcp->u_arg[0]);
803 printpath(tcp, tcp->u_arg[1]);
804 tprintf(", %s", sprintmode(mode));
805 switch (mode & S_IFMT) {
806 case S_IFCHR: case S_IFBLK:
807#ifdef LINUXSPARC
808 tprintf(", makedev(%lu, %lu)",
809 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
810 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
811#else
812 tprintf(", makedev(%lu, %lu)",
813 (unsigned long) major(tcp->u_arg[3]),
814 (unsigned long) minor(tcp->u_arg[3]));
815#endif
816 break;
817 default:
818 break;
819 }
820 }
821 return 0;
822}
823
Wichert Akkerman8829a551999-06-11 13:18:40 +0000824#ifdef HAVE_SYS_ACL_H
825
826#include <sys/acl.h>
827
828struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000829#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +0000830 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000831#endif
832#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +0000833 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000834#endif
835#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +0000836 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000837#endif
838#ifdef ACL_GET
839 { ACL_GET, "ACL_GET" },
840#endif
841#ifdef ACL_SET
842 { ACL_SET, "ACL_SET" },
843#endif
844#ifdef ACL_CNT
845 { ACL_CNT, "ACL_CNT" },
846#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000847 { 0, NULL },
848};
849
850int
851sys_acl(tcp)
852struct tcb *tcp;
853{
854 if (entering(tcp)) {
855 printpath(tcp, tcp->u_arg[0]);
856 tprintf(", ");
857 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
858 tprintf(", %ld", tcp->u_arg[2]);
859 /*
860 * FIXME - dump out the list of aclent_t's pointed to
861 * by "tcp->u_arg[3]" if it's not NULL.
862 */
863 if (tcp->u_arg[3])
864 tprintf(", %#lx", tcp->u_arg[3]);
865 else
866 tprintf(", NULL");
867 }
868 return 0;
869}
870
871
872int
873sys_facl(tcp)
874struct tcb *tcp;
875{
876 if (entering(tcp)) {
877 tprintf("%ld, ", tcp->u_arg[0]);
878 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
879 tprintf(", %ld", tcp->u_arg[2]);
880 /*
881 * FIXME - dump out the list of aclent_t's pointed to
882 * by "tcp->u_arg[3]" if it's not NULL.
883 */
884 if (tcp->u_arg[3])
885 tprintf(", %#lx", tcp->u_arg[3]);
886 else
887 tprintf(", NULL");
888 }
889 return 0;
890}
891
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000892
893struct xlat aclipc[] = {
894#ifdef IPC_SHM
895 { IPC_SHM, "IPC_SHM" },
896#endif
897#ifdef IPC_SEM
898 { IPC_SEM, "IPC_SEM" },
899#endif
900#ifdef IPC_MSG
901 { IPC_MSG, "IPC_MSG" },
902#endif
903 { 0, NULL },
904};
905
906
907int
908sys_aclipc(tcp)
909struct tcb *tcp;
910{
911 if (entering(tcp)) {
912 printxval(aclipc, tcp->u_arg[0], "???IPC???");
913 tprintf(", %#lx, ", tcp->u_arg[1]);
914 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
915 tprintf(", %ld", tcp->u_arg[3]);
916 /*
917 * FIXME - dump out the list of aclent_t's pointed to
918 * by "tcp->u_arg[4]" if it's not NULL.
919 */
920 if (tcp->u_arg[4])
921 tprintf(", %#lx", tcp->u_arg[4]);
922 else
923 tprintf(", NULL");
924 }
925 return 0;
926}
927
928
929
Wichert Akkerman8829a551999-06-11 13:18:40 +0000930#endif /* HAVE_SYS_ACL_H */
931
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000932#endif /* SVR4 || LINUXSPARC */
933
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000934#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000935
936static struct xlat fsmagic[] = {
937 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
938 { 0xef53, "EXT2_SUPER_MAGIC" },
939 { 0x137d, "EXT_SUPER_MAGIC" },
940 { 0x9660, "ISOFS_SUPER_MAGIC" },
941 { 0x137f, "MINIX_SUPER_MAGIC" },
942 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000943 { 0x2468, "MINIX2_SUPER_MAGIC" },
944 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000945 { 0x4d44, "MSDOS_SUPER_MAGIC" },
946 { 0x6969, "NFS_SUPER_MAGIC" },
947 { 0x9fa0, "PROC_SUPER_MAGIC" },
948 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
949 { 0, NULL },
950};
951
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000952#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000953
954#ifndef SVR4
955
956static char *
957sprintfstype(magic)
958int magic;
959{
960 static char buf[32];
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000961#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000962 char *s;
963
964 s = xlookup(fsmagic, magic);
965 if (s) {
966 sprintf(buf, "\"%s\"", s);
967 return buf;
968 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000969#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000970 sprintf(buf, "%#x", magic);
971 return buf;
972}
973
974static void
975printstatfs(tcp, addr)
976struct tcb *tcp;
977long addr;
978{
979 struct statfs statbuf;
980
981 if (syserror(tcp) || !verbose(tcp)) {
982 tprintf("%#lx", addr);
983 return;
984 }
985 if (umove(tcp, addr, &statbuf) < 0) {
986 tprintf("{...}");
987 return;
988 }
989#ifdef ALPHA
990
991 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
992 sprintfstype(statbuf.f_type),
993 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000994 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_namelen=%u",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000995 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree, statbuf.f_namelen);
996#else /* !ALPHA */
997 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
998 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +0000999 (unsigned long)statbuf.f_bsize,
1000 (unsigned long)statbuf.f_blocks,
1001 (unsigned long)statbuf.f_bfree);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001002 tprintf("f_files=%lu, f_ffree=%lu",
Nate Sammons5c74d201999-04-06 01:37:51 +00001003 (unsigned long)statbuf.f_files,
1004 (unsigned long)statbuf.f_ffree);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001005#ifdef linux
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001006 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001007#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001008#endif /* !ALPHA */
1009 tprintf("}");
1010}
1011
1012int
1013sys_statfs(tcp)
1014struct tcb *tcp;
1015{
1016 if (entering(tcp)) {
1017 printpath(tcp, tcp->u_arg[0]);
1018 tprintf(", ");
1019 } else {
1020 printstatfs(tcp, tcp->u_arg[1]);
1021 }
1022 return 0;
1023}
1024
1025int
1026sys_fstatfs(tcp)
1027struct tcb *tcp;
1028{
1029 if (entering(tcp)) {
1030 tprintf("%lu, ", tcp->u_arg[0]);
1031 } else {
1032 printstatfs(tcp, tcp->u_arg[1]);
1033 }
1034 return 0;
1035}
1036
Wichert Akkermana0f36c61999-04-16 14:01:34 +00001037#if defined(linux) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001038
1039int
1040osf_statfs(tcp)
1041struct tcb *tcp;
1042{
1043 if (entering(tcp)) {
1044 printpath(tcp, tcp->u_arg[0]);
1045 tprintf(", ");
1046 } else {
1047 printstatfs(tcp, tcp->u_arg[1]);
1048 tprintf(", %lu", tcp->u_arg[2]);
1049 }
1050 return 0;
1051}
1052
1053int
1054osf_fstatfs(tcp)
1055struct tcb *tcp;
1056{
1057 if (entering(tcp)) {
1058 tprintf("%lu, ", tcp->u_arg[0]);
1059 } else {
1060 printstatfs(tcp, tcp->u_arg[1]);
1061 tprintf(", %lu", tcp->u_arg[2]);
1062 }
1063 return 0;
1064}
Wichert Akkermana0f36c61999-04-16 14:01:34 +00001065#endif /* linux && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001066
1067#endif /* !SVR4 */
1068
1069#ifdef SUNOS4
1070
1071int
1072sys_ustat(tcp)
1073struct tcb *tcp;
1074{
1075 struct ustat statbuf;
1076
1077 if (entering(tcp)) {
1078 tprintf("makedev(%lu, %lu), ",
1079 (long) major(tcp->u_arg[0]),
1080 (long) minor(tcp->u_arg[0]));
1081 }
1082 else {
1083 if (syserror(tcp) || !verbose(tcp))
1084 tprintf("%#lx", tcp->u_arg[1]);
1085 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1086 tprintf("{...}");
1087 else {
1088 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1089 statbuf.f_tfree, statbuf.f_tinode);
1090 tprintf("f_fname=\"%.*s\", ",
1091 (int) sizeof(statbuf.f_fname),
1092 statbuf.f_fname);
1093 tprintf("f_fpack=\"%.*s\"}",
1094 (int) sizeof(statbuf.f_fpack),
1095 statbuf.f_fpack);
1096 }
1097 }
1098 return 0;
1099}
1100
1101#endif /* SUNOS4 */
1102
1103/* directory */
1104int
1105sys_chdir(tcp)
1106struct tcb *tcp;
1107{
1108 if (entering(tcp)) {
1109 printpath(tcp, tcp->u_arg[0]);
1110 }
1111 return 0;
1112}
1113
1114int
1115sys_mkdir(tcp)
1116struct tcb *tcp;
1117{
1118 if (entering(tcp)) {
1119 printpath(tcp, tcp->u_arg[0]);
1120 tprintf(", %#lo", tcp->u_arg[1]);
1121 }
1122 return 0;
1123}
1124
1125int
1126sys_rmdir(tcp)
1127struct tcb *tcp;
1128{
1129 if (entering(tcp)) {
1130 printpath(tcp, tcp->u_arg[0]);
1131 }
1132 return 0;
1133}
1134
1135int
1136sys_fchdir(tcp)
1137struct tcb *tcp;
1138{
1139 if (entering(tcp)) {
1140 tprintf("%ld", tcp->u_arg[0]);
1141 }
1142 return 0;
1143}
1144
1145int
1146sys_chroot(tcp)
1147struct tcb *tcp;
1148{
1149 if (entering(tcp)) {
1150 printpath(tcp, tcp->u_arg[0]);
1151 }
1152 return 0;
1153}
1154
1155int
1156sys_fchroot(tcp)
1157struct tcb *tcp;
1158{
1159 if (entering(tcp)) {
1160 tprintf("%ld", tcp->u_arg[0]);
1161 }
1162 return 0;
1163}
1164
1165int
1166sys_link(tcp)
1167struct tcb *tcp;
1168{
1169 if (entering(tcp)) {
1170 printpath(tcp, tcp->u_arg[0]);
1171 tprintf(", ");
1172 printpath(tcp, tcp->u_arg[1]);
1173 }
1174 return 0;
1175}
1176
1177int
1178sys_unlink(tcp)
1179struct tcb *tcp;
1180{
1181 if (entering(tcp)) {
1182 printpath(tcp, tcp->u_arg[0]);
1183 }
1184 return 0;
1185}
1186
1187int
1188sys_symlink(tcp)
1189struct tcb *tcp;
1190{
1191 if (entering(tcp)) {
1192 printpath(tcp, tcp->u_arg[0]);
1193 tprintf(", ");
1194 printpath(tcp, tcp->u_arg[1]);
1195 }
1196 return 0;
1197}
1198
1199int
1200sys_readlink(tcp)
1201struct tcb *tcp;
1202{
1203 if (entering(tcp)) {
1204 printpath(tcp, tcp->u_arg[0]);
1205 tprintf(", ");
1206 } else {
1207 if (syserror(tcp))
1208 tprintf("%#lx", tcp->u_arg[1]);
1209 else
1210 printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
1211 tprintf(", %lu", tcp->u_arg[2]);
1212 }
1213 return 0;
1214}
1215
1216int
1217sys_rename(tcp)
1218struct tcb *tcp;
1219{
1220 if (entering(tcp)) {
1221 printpath(tcp, tcp->u_arg[0]);
1222 tprintf(", ");
1223 printpath(tcp, tcp->u_arg[1]);
1224 }
1225 return 0;
1226}
1227
1228int
1229sys_chown(tcp)
1230struct tcb *tcp;
1231{
1232 if (entering(tcp)) {
1233 printpath(tcp, tcp->u_arg[0]);
1234 tprintf(", %lu, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1235 }
1236 return 0;
1237}
1238
1239int
1240sys_fchown(tcp)
1241struct tcb *tcp;
1242{
1243 if (entering(tcp)) {
1244 tprintf("%ld, %lu, %lu",
1245 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1246 }
1247 return 0;
1248}
1249
1250int
1251sys_chmod(tcp)
1252struct tcb *tcp;
1253{
1254 if (entering(tcp)) {
1255 printpath(tcp, tcp->u_arg[0]);
1256 tprintf(", %#lo", tcp->u_arg[1]);
1257 }
1258 return 0;
1259}
1260
1261int
1262sys_fchmod(tcp)
1263struct tcb *tcp;
1264{
1265 if (entering(tcp)) {
1266 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
1267 }
1268 return 0;
1269}
1270
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001271#ifdef ALPHA
1272int
1273sys_osf_utimes(tcp)
1274struct tcb *tcp;
1275{
1276 if (entering(tcp)) {
1277 printpath(tcp, tcp->u_arg[0]);
1278 tprintf(", ");
1279 printtv32(tcp, tcp->u_arg[1]);
1280 }
1281 return 0;
1282}
1283#endif
1284
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001285int
1286sys_utimes(tcp)
1287struct tcb *tcp;
1288{
1289 if (entering(tcp)) {
1290 printpath(tcp, tcp->u_arg[0]);
1291 tprintf(", ");
1292 printtv(tcp, tcp->u_arg[1]);
1293 }
1294 return 0;
1295}
1296
1297int
1298sys_utime(tcp)
1299struct tcb *tcp;
1300{
1301 long ut[2];
1302
1303 if (entering(tcp)) {
1304 printpath(tcp, tcp->u_arg[0]);
1305 tprintf(", ");
1306 if (!tcp->u_arg[1])
1307 tprintf("NULL");
1308 else if (!verbose(tcp))
1309 tprintf("%#lx", tcp->u_arg[1]);
1310 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
1311 (char *) ut) < 0)
1312 tprintf("[?, ?]");
1313 else {
1314 tprintf("[%s,", sprinttime(ut[0]));
1315 tprintf(" %s]", sprinttime(ut[1]));
1316 }
1317 }
1318 return 0;
1319}
1320
1321int
1322sys_mknod(tcp)
1323struct tcb *tcp;
1324{
1325 int mode = tcp->u_arg[1];
1326
1327 if (entering(tcp)) {
1328 printpath(tcp, tcp->u_arg[0]);
1329 tprintf(", %s", sprintmode(mode));
1330 switch (mode & S_IFMT) {
1331 case S_IFCHR: case S_IFBLK:
1332#ifdef LINUXSPARC
1333 if (current_personality == 1)
1334 tprintf(", makedev(%lu, %lu)",
1335 (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
1336 (unsigned long) (tcp->u_arg[2] & 0x3ffff));
1337 else
1338#endif
1339 tprintf(", makedev(%lu, %lu)",
1340 (unsigned long) major(tcp->u_arg[2]),
1341 (unsigned long) minor(tcp->u_arg[2]));
1342 break;
1343 default:
1344 break;
1345 }
1346 }
1347 return 0;
1348}
1349
1350int
1351sys_mkfifo(tcp)
1352struct tcb *tcp;
1353{
1354 if (entering(tcp)) {
1355 printpath(tcp, tcp->u_arg[0]);
1356 tprintf(", %#lo", tcp->u_arg[1]);
1357 }
1358 return 0;
1359}
1360
1361int
1362sys_fsync(tcp)
1363struct tcb *tcp;
1364{
1365 if (entering(tcp)) {
1366 tprintf("%ld", tcp->u_arg[0]);
1367 }
1368 return 0;
1369}
1370
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001371#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001372
1373static void
1374printdir(tcp, addr)
1375struct tcb *tcp;
1376long addr;
1377{
1378 struct dirent d;
1379
1380 if (!verbose(tcp)) {
1381 tprintf("%#lx", addr);
1382 return;
1383 }
1384 if (umove(tcp, addr, &d) < 0) {
1385 tprintf("{...}");
1386 return;
1387 }
1388 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001389 tprintf("d_name=");
1390 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
1391 tprintf("}");
1392}
1393
1394int
1395sys_readdir(tcp)
1396struct tcb *tcp;
1397{
1398 if (entering(tcp)) {
1399 tprintf("%lu, ", tcp->u_arg[0]);
1400 } else {
1401 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
1402 tprintf("%#lx", tcp->u_arg[1]);
1403 else
1404 printdir(tcp, tcp->u_arg[1]);
1405 /* Not much point in printing this out, it is always 1. */
1406 if (tcp->u_arg[2] != 1)
1407 tprintf(", %lu", tcp->u_arg[2]);
1408 }
1409 return 0;
1410}
1411
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001412#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001413
1414int
1415sys_getdents(tcp)
1416struct tcb *tcp;
1417{
1418 int i, len, dents = 0;
1419 char *buf;
1420
1421 if (entering(tcp)) {
1422 tprintf("%lu, ", tcp->u_arg[0]);
1423 return 0;
1424 }
1425 if (syserror(tcp) || !verbose(tcp)) {
1426 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1427 return 0;
1428 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001429 len = tcp->u_rval;
1430 if ((buf = malloc(len)) == NULL) {
1431 tprintf("out of memory\n");
1432 return 0;
1433 }
1434 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1435 tprintf("{...}, %lu", tcp->u_arg[2]);
1436 free(buf);
1437 return 0;
1438 }
1439 if (!abbrev(tcp))
1440 tprintf("{");
1441 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00001442 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001443#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001444 if (!abbrev(tcp)) {
1445 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1446 i ? " " : "", d->d_ino, d->d_off);
1447 tprintf("d_reclen=%u, d_name=\"%s\"}",
1448 d->d_reclen, d->d_name);
1449 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001450#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001451#ifdef SVR4
1452 if (!abbrev(tcp)) {
1453 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1454 i ? " " : "", d->d_ino, d->d_off);
1455 tprintf("d_reclen=%u, d_name=\"%s\"}",
1456 d->d_reclen, d->d_name);
1457 }
1458#endif /* SVR4 */
1459#ifdef SUNOS4
1460 if (!abbrev(tcp)) {
1461 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
1462 i ? " " : "", d->d_off, d->d_fileno,
1463 d->d_reclen);
1464 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
1465 d->d_namlen, d->d_namlen, d->d_name);
1466 }
1467#endif /* SUNOS4 */
1468 i += d->d_reclen;
1469 dents++;
1470 }
1471 if (!abbrev(tcp))
1472 tprintf("}");
1473 else
1474 tprintf("/* %u entries */", dents);
1475 tprintf(", %lu", tcp->u_arg[2]);
1476 free(buf);
1477 return 0;
1478}
1479
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001480#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001481
1482int
1483sys_getcwd(tcp)
1484struct tcb *tcp;
1485{
1486 if (exiting(tcp)) {
1487 if (syserror(tcp))
1488 tprintf("%#lx", tcp->u_arg[0]);
1489 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001490 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001491 tprintf(", %lu", tcp->u_arg[1]);
1492 }
1493 return 0;
1494}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001495#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001496
1497#ifdef HAVE_SYS_ASYNCH_H
1498
1499int
1500sys_aioread(tcp)
1501struct tcb *tcp;
1502{
1503 struct aio_result_t res;
1504
1505 if (entering(tcp)) {
1506 tprintf("%lu, ", tcp->u_arg[0]);
1507 } else {
1508 if (syserror(tcp))
1509 tprintf("%#lx", tcp->u_arg[1]);
1510 else
1511 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1512 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
1513 printxval(whence, tcp->u_arg[4], "L_???");
1514 if (syserror(tcp) || tcp->u_arg[5] == 0
1515 || umove(tcp, tcp->u_arg[5], &res) < 0)
1516 tprintf(", %#lx", tcp->u_arg[5]);
1517 else
1518 tprintf(", {aio_return %d aio_errno %d}",
1519 res.aio_return, res.aio_errno);
1520 }
1521 return 0;
1522}
1523
1524int
1525sys_aiowrite(tcp)
1526struct tcb *tcp;
1527{
1528 struct aio_result_t res;
1529
1530 if (entering(tcp)) {
1531 tprintf("%lu, ", tcp->u_arg[0]);
1532 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1533 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
1534 printxval(whence, tcp->u_arg[4], "L_???");
1535 }
1536 else {
1537 if (tcp->u_arg[5] == 0)
1538 tprintf(", NULL");
1539 else if (syserror(tcp)
1540 || umove(tcp, tcp->u_arg[5], &res) < 0)
1541 tprintf(", %#lx", tcp->u_arg[5]);
1542 else
1543 tprintf(", {aio_return %d aio_errno %d}",
1544 res.aio_return, res.aio_errno);
1545 }
1546 return 0;
1547}
1548
1549int
1550sys_aiowait(tcp)
1551struct tcb *tcp;
1552{
1553 if (entering(tcp))
1554 printtv(tcp, tcp->u_arg[0]);
1555 return 0;
1556}
1557
1558int
1559sys_aiocancel(tcp)
1560struct tcb *tcp;
1561{
1562 struct aio_result_t res;
1563
1564 if (exiting(tcp)) {
1565 if (tcp->u_arg[0] == 0)
1566 tprintf("NULL");
1567 else if (syserror(tcp)
1568 || umove(tcp, tcp->u_arg[0], &res) < 0)
1569 tprintf("%#lx", tcp->u_arg[0]);
1570 else
1571 tprintf("{aio_return %d aio_errno %d}",
1572 res.aio_return, res.aio_errno);
1573 }
1574 return 0;
1575}
1576
1577#endif /* HAVE_SYS_ASYNCH_H */