blob: d92948a4a7f9e1ef72d86709f517fc5ee8a5ce49 [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
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000175 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000176#endif
177#ifdef O_LARGEFILE
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000178 { O_LARGEFILE, "O_LARGEFILE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000179#endif
180#ifdef O_DIRECTORY
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000181 { O_DIRECTORY, "O_DIRECTORY" },
182#endif
183#ifdef O_NOFOLLOW
184 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000185#endif
186
187#ifdef FNDELAY
188 { FNDELAY, "FNDELAY" },
189#endif
190#ifdef FAPPEND
191 { FAPPEND, "FAPPEND" },
192#endif
193#ifdef FMARK
194 { FMARK, "FMARK" },
195#endif
196#ifdef FDEFER
197 { FDEFER, "FDEFER" },
198#endif
199#ifdef FASYNC
200 { FASYNC, "FASYNC" },
201#endif
202#ifdef FSHLOCK
203 { FSHLOCK, "FSHLOCK" },
204#endif
205#ifdef FEXLOCK
206 { FEXLOCK, "FEXLOCK" },
207#endif
208#ifdef FCREAT
209 { FCREAT, "FCREAT" },
210#endif
211#ifdef FTRUNC
212 { FTRUNC, "FTRUNC" },
213#endif
214#ifdef FEXCL
215 { FEXCL, "FEXCL" },
216#endif
217#ifdef FNBIO
218 { FNBIO, "FNBIO" },
219#endif
220#ifdef FSYNC
221 { FSYNC, "FSYNC" },
222#endif
223#ifdef FNOCTTY
224 { FNOCTTY, "FNOCTTY" },
225#endif
226 { 0, NULL },
227};
228
229int
230sys_open(tcp)
231struct tcb *tcp;
232{
233 if (entering(tcp)) {
234 printpath(tcp, tcp->u_arg[0]);
235 tprintf(", ");
236 /* flags */
237 printflags(openmodes, tcp->u_arg[1] + 1);
238 if (tcp->u_arg[1] & O_CREAT) {
239 /* mode */
240 tprintf(", %#lo", tcp->u_arg[2]);
241 }
242 }
243 return 0;
244}
245
246#ifdef LINUXSPARC
247struct xlat openmodessol[] = {
248 { 0, "O_RDWR" },
249 { 1, "O_RDONLY" },
250 { 2, "O_WRONLY" },
251 { 0x80, "O_NONBLOCK" },
252 { 8, "O_APPEND" },
253 { 0x100, "O_CREAT" },
254 { 0x200, "O_TRUNC" },
255 { 0x400, "O_EXCL" },
256 { 0x800, "O_NOCTTY" },
257 { 0x10, "O_SYNC" },
258 { 0x40, "O_DSYNC" },
259 { 0x8000, "O_RSYNC" },
260 { 4, "O_NDELAY" },
261 { 0x1000, "O_PRIV" },
262 { 0, NULL },
263};
264
265int
266solaris_open(tcp)
267struct tcb *tcp;
268{
269 if (entering(tcp)) {
270 printpath(tcp, tcp->u_arg[0]);
271 tprintf(", ");
272 /* flags */
273 printflags(openmodessol, tcp->u_arg[1] + 1);
274 if (tcp->u_arg[1] & 0x100) {
275 /* mode */
276 tprintf(", %#lo", tcp->u_arg[2]);
277 }
278 }
279 return 0;
280}
281
282#endif
283
284int
285sys_creat(tcp)
286struct tcb *tcp;
287{
288 if (entering(tcp)) {
289 printpath(tcp, tcp->u_arg[0]);
290 tprintf(", %#lo", tcp->u_arg[1]);
291 }
292 return 0;
293}
294
295static struct xlat access_flags[] = {
296 { F_OK, "F_OK", },
297 { R_OK, "R_OK" },
298 { W_OK, "W_OK" },
299 { X_OK, "X_OK" },
300#ifdef EFF_ONLY_OK
301 { EFF_ONLY_OK, "EFF_ONLY_OK" },
302#endif
303#ifdef EX_OK
304 { EX_OK, "EX_OK" },
305#endif
306 { 0, NULL },
307};
308
309int
310sys_access(tcp)
311struct tcb *tcp;
312{
313 if (entering(tcp)) {
314 printpath(tcp, tcp->u_arg[0]);
315 tprintf(", ");
316 printflags(access_flags, tcp->u_arg[1]);
317 }
318 return 0;
319}
320
321int
322sys_umask(tcp)
323struct tcb *tcp;
324{
325 if (entering(tcp)) {
326 tprintf("%#lo", tcp->u_arg[0]);
327 }
328 return RVAL_OCTAL;
329}
330
331static struct xlat whence[] = {
332 { SEEK_SET, "SEEK_SET" },
333 { SEEK_CUR, "SEEK_CUR" },
334 { SEEK_END, "SEEK_END" },
335 { 0, NULL },
336};
337
338int
339sys_lseek(tcp)
340struct tcb *tcp;
341{
342 if (entering(tcp)) {
343 tprintf("%ld, ", tcp->u_arg[0]);
344 if (tcp->u_arg[2] == SEEK_SET)
345 tprintf("%lu, ", tcp->u_arg[1]);
346 else
347 tprintf("%ld, ", tcp->u_arg[1]);
348 printxval(whence, tcp->u_arg[2], "SEEK_???");
349 }
350 return RVAL_UDECIMAL;
351}
352
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000353#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000354int
355sys_llseek (tcp)
356struct tcb *tcp;
357{
358 if (entering(tcp)) {
359 if (tcp->u_arg[4] == SEEK_SET)
360 tprintf("%ld, %llu, ", tcp->u_arg[0],
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000361 (((long long int) tcp->u_arg[1]) << 32
362 | (unsigned long long) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000363 else
364 tprintf("%ld, %lld, ", tcp->u_arg[0],
365 (((long long int) tcp->u_arg[1]) << 32
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000366 | (unsigned long long) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000367 }
368 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000369 long long int off;
370 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000371 tprintf("%#lx, ", tcp->u_arg[3]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000372 else
373 tprintf("[%llu], ", off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000374 printxval(whence, tcp->u_arg[4], "SEEK_???");
375 }
376 return 0;
377}
378#endif
379
380int
381sys_truncate(tcp)
382struct tcb *tcp;
383{
384 if (entering(tcp)) {
385 printpath(tcp, tcp->u_arg[0]);
386 tprintf(", %lu", tcp->u_arg[1]);
387 }
388 return 0;
389}
390
391int
392sys_ftruncate(tcp)
393struct tcb *tcp;
394{
395 if (entering(tcp)) {
396 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
397 }
398 return 0;
399}
400
401/* several stats */
402
403static struct xlat modetypes[] = {
404 { S_IFREG, "S_IFREG" },
405 { S_IFSOCK, "S_IFSOCK" },
406 { S_IFIFO, "S_IFIFO" },
407 { S_IFLNK, "S_IFLNK" },
408 { S_IFDIR, "S_IFDIR" },
409 { S_IFBLK, "S_IFBLK" },
410 { S_IFCHR, "S_IFCHR" },
411 { 0, NULL },
412};
413
414static char *
415sprintmode(mode)
416int mode;
417{
418 static char buf[64];
419 char *s;
420
421 if ((mode & S_IFMT) == 0)
422 s = "";
423 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
424 sprintf(buf, "%#o", mode);
425 return buf;
426 }
427 sprintf(buf, "%s%s%s%s", s,
428 (mode & S_ISUID) ? "|S_ISUID" : "",
429 (mode & S_ISGID) ? "|S_ISGID" : "",
430 (mode & S_ISVTX) ? "|S_ISVTX" : "");
431 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
432 if (mode)
433 sprintf(buf + strlen(buf), "|%#o", mode);
434 s = (*buf == '|') ? buf + 1 : buf;
435 return *s ? s : "0";
436}
437
438static char *
439sprinttime(t)
440time_t t;
441{
442 struct tm *tmp;
443 static char buf[32];
444
445 if (t == 0) {
446 sprintf(buf, "0");
447 return buf;
448 }
449 tmp = localtime(&t);
450 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
Wichert Akkerman3ed6dc22000-01-11 14:41:09 +0000451 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000452 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
453 return buf;
454}
455
456#ifdef LINUXSPARC
457typedef struct {
458 int tv_sec;
459 int tv_nsec;
460} timestruct_t;
461
462struct solstat {
463 unsigned st_dev;
464 int st_pad1[3]; /* network id */
465 unsigned st_ino;
466 unsigned st_mode;
467 unsigned st_nlink;
468 unsigned st_uid;
469 unsigned st_gid;
470 unsigned st_rdev;
471 int st_pad2[2];
472 int st_size;
473 int st_pad3; /* st_size, off_t expansion */
474 timestruct_t st_atime;
475 timestruct_t st_mtime;
476 timestruct_t st_ctime;
477 int st_blksize;
478 int st_blocks;
479 char st_fstype[16];
480 int st_pad4[8]; /* expansion area */
481};
482
483static void
484printstatsol(tcp, addr)
485struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000486long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000487{
488 struct solstat statbuf;
489
490 if (!addr) {
491 tprintf("NULL");
492 return;
493 }
494 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000495 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000496 return;
497 }
498 if (umove(tcp, addr, &statbuf) < 0) {
499 tprintf("{...}");
500 return;
501 }
502 if (!abbrev(tcp)) {
503 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
504 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
505 (unsigned long) (statbuf.st_dev & 0x3ffff),
506 (unsigned long) statbuf.st_ino,
507 sprintmode(statbuf.st_mode));
508 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
509 (unsigned long) statbuf.st_nlink,
510 (unsigned long) statbuf.st_uid,
511 (unsigned long) statbuf.st_gid);
512 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
513 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
514 }
515 else
516 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
517 switch (statbuf.st_mode & S_IFMT) {
518 case S_IFCHR: case S_IFBLK:
519 tprintf("st_rdev=makedev(%lu, %lu), ",
520 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
521 (unsigned long) (statbuf.st_rdev & 0x3ffff));
522 break;
523 default:
524 tprintf("st_size=%u, ", statbuf.st_size);
525 break;
526 }
527 if (!abbrev(tcp)) {
528 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
529 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
530 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
531 }
532 else
533 tprintf("...}");
534}
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000535#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000536
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000537static void
538realprintstat(tcp, statbuf)
539struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000540struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000541{
542 if (!abbrev(tcp)) {
543 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
544 (unsigned long) major(statbuf->st_dev),
545 (unsigned long) minor(statbuf->st_dev),
546 (unsigned long) statbuf->st_ino,
547 sprintmode(statbuf->st_mode));
548 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
549 (unsigned long) statbuf->st_nlink,
550 (unsigned long) statbuf->st_uid,
551 (unsigned long) statbuf->st_gid);
552#ifdef HAVE_ST_BLKSIZE
553 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
554#endif /* HAVE_ST_BLKSIZE */
555#ifdef HAVE_ST_BLOCKS
556 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
557#endif /* HAVE_ST_BLOCKS */
558 }
559 else
560 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
561 switch (statbuf->st_mode & S_IFMT) {
562 case S_IFCHR: case S_IFBLK:
563#ifdef HAVE_ST_RDEV
564 tprintf("st_rdev=makedev(%lu, %lu), ",
565 (unsigned long) major(statbuf->st_rdev),
566 (unsigned long) minor(statbuf->st_rdev));
567#else /* !HAVE_ST_RDEV */
568 tprintf("st_size=makedev(%lu, %lu), ",
569 (unsigned long) major(statbuf->st_size),
570 (unsigned long) minor(statbuf->st_size));
571#endif /* !HAVE_ST_RDEV */
572 break;
573 default:
574 tprintf("st_size=%lu, ", statbuf->st_size);
575 break;
576 }
577 if (!abbrev(tcp)) {
578 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
579 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
580 tprintf("st_ctime=%s}", sprinttime(statbuf->st_ctime));
581 }
582 else
583 tprintf("...}");
584}
585
Nate Sammons771a6ff1999-04-05 22:39:31 +0000586
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000587static void
588printstat(tcp, addr)
589struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000590long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000591{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000592 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000593
594#ifdef LINUXSPARC
595 if (current_personality == 1) {
596 printstatsol(tcp, addr);
597 return;
598 }
599#endif /* LINUXSPARC */
600
601 if (!addr) {
602 tprintf("NULL");
603 return;
604 }
605 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000606 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000607 return;
608 }
609 if (umove(tcp, addr, &statbuf) < 0) {
610 tprintf("{...}");
611 return;
612 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000613
614 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000615}
616
Wichert Akkermanc7926982000-04-10 22:22:31 +0000617#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000618static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000619printstat64(tcp, addr)
620struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000621long addr;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000622{
623 struct stat64 statbuf;
624
625#ifdef LINUXSPARC
626 if (current_personality == 1) {
627 printstatsol(tcp, addr);
628 return;
629 }
630#endif /* LINUXSPARC */
631
632 if (!addr) {
633 tprintf("NULL");
634 return;
635 }
636 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000637 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000638 return;
639 }
640 if (umove(tcp, addr, &statbuf) < 0) {
641 tprintf("{...}");
642 return;
643 }
644
645 if (!abbrev(tcp)) {
646 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
647 (unsigned long) major(statbuf.st_dev),
648 (unsigned long) minor(statbuf.st_dev),
649 (unsigned long) statbuf.st_ino,
650 sprintmode(statbuf.st_mode));
651 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
652 (unsigned long) statbuf.st_nlink,
653 (unsigned long) statbuf.st_uid,
654 (unsigned long) statbuf.st_gid);
655#ifdef HAVE_ST_BLKSIZE
656 tprintf("st_blksize=%lu, ",
657 (unsigned long) statbuf.st_blksize);
658#endif /* HAVE_ST_BLKSIZE */
659#ifdef HAVE_ST_BLOCKS
660 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
661#endif /* HAVE_ST_BLOCKS */
662 }
663 else
664 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
665 switch (statbuf.st_mode & S_IFMT) {
666 case S_IFCHR: case S_IFBLK:
667#ifdef HAVE_ST_RDEV
668 tprintf("st_rdev=makedev(%lu, %lu), ",
669 (unsigned long) major(statbuf.st_rdev),
670 (unsigned long) minor(statbuf.st_rdev));
671#else /* !HAVE_ST_RDEV */
672 tprintf("st_size=makedev(%lu, %lu), ",
673 (unsigned long) major(statbuf.st_size),
674 (unsigned long) minor(statbuf.st_size));
675#endif /* !HAVE_ST_RDEV */
676 break;
677 default:
678 tprintf("st_size=%llu, ", statbuf.st_size);
679 break;
680 }
681 if (!abbrev(tcp)) {
682 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
683 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
684 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
685 }
686 else
687 tprintf("...}");
688}
Wichert Akkermanc7926982000-04-10 22:22:31 +0000689#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000690
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000691#if defined(linux) && !defined(IA64)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000692static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000693convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000694const struct __old_kernel_stat *oldbuf;
695struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000696{
697 newbuf->st_dev=oldbuf->st_dev;
698 newbuf->st_ino=oldbuf->st_ino;
699 newbuf->st_mode=oldbuf->st_mode;
700 newbuf->st_nlink=oldbuf->st_nlink;
701 newbuf->st_uid=oldbuf->st_uid;
702 newbuf->st_gid=oldbuf->st_gid;
703 newbuf->st_rdev=oldbuf->st_rdev;
704 newbuf->st_size=oldbuf->st_size;
705 newbuf->st_atime=oldbuf->st_atime;
706 newbuf->st_mtime=oldbuf->st_mtime;
707 newbuf->st_ctime=oldbuf->st_ctime;
708 newbuf->st_blksize=0; /* not supported in old_stat */
709 newbuf->st_blocks=0; /* not supported in old_stat */
710}
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000711
712
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000713static void
714printoldstat(tcp, addr)
715struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000716long addr;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000717{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000718 struct __old_kernel_stat statbuf;
719 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000720
721#ifdef LINUXSPARC
722 if (current_personality == 1) {
723 printstatsol(tcp, addr);
724 return;
725 }
726#endif /* LINUXSPARC */
727
728 if (!addr) {
729 tprintf("NULL");
730 return;
731 }
732 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000733 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000734 return;
735 }
736 if (umove(tcp, addr, &statbuf) < 0) {
737 tprintf("{...}");
738 return;
739 }
740
741 convertoldstat(&statbuf, &newstatbuf);
742 realprintstat(tcp, &newstatbuf);
743}
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000744#endif /* linux && !IA64 */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000745
746
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000747int
748sys_stat(tcp)
749struct tcb *tcp;
750{
751 if (entering(tcp)) {
752 printpath(tcp, tcp->u_arg[0]);
753 tprintf(", ");
754 } else {
755 printstat(tcp, tcp->u_arg[1]);
756 }
757 return 0;
758}
759
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000760#ifdef linux
761int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000762sys_stat64(tcp)
763struct tcb *tcp;
764{
765#ifdef HAVE_STAT64
766 if (entering(tcp)) {
767 printpath(tcp, tcp->u_arg[0]);
768 tprintf(", ");
769 } else {
770 printstat64(tcp, tcp->u_arg[1]);
771 }
772 return 0;
773#else
774 return printargs(tcp);
775#endif
776}
777
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000778# if !defined(IA64)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000779int
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000780sys_oldstat(tcp)
781struct tcb *tcp;
782{
783 if (entering(tcp)) {
784 printpath(tcp, tcp->u_arg[0]);
785 tprintf(", ");
786 } else {
787 printoldstat(tcp, tcp->u_arg[1]);
788 }
789 return 0;
790}
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000791# endif /* !IA64 */
792#endif /* linux */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000793
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000794int
795sys_fstat(tcp)
796struct tcb *tcp;
797{
798 if (entering(tcp))
799 tprintf("%ld, ", tcp->u_arg[0]);
800 else {
801 printstat(tcp, tcp->u_arg[1]);
802 }
803 return 0;
804}
805
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000806#ifdef linux
807int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000808sys_fstat64(tcp)
809struct tcb *tcp;
810{
811#ifdef HAVE_STAT64
812 if (entering(tcp))
813 tprintf("%ld, ", tcp->u_arg[0]);
814 else {
815 printstat64(tcp, tcp->u_arg[1]);
816 }
817 return 0;
818#else
819 return printargs(tcp);
820#endif
821}
822
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000823# if !defined(IA64)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000824int
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000825sys_oldfstat(tcp)
826struct tcb *tcp;
827{
828 if (entering(tcp))
829 tprintf("%ld, ", tcp->u_arg[0]);
830 else {
831 printoldstat(tcp, tcp->u_arg[1]);
832 }
833 return 0;
834}
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000835# endif /* !IA64 */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000836#endif
837
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000838int
839sys_lstat(tcp)
840struct tcb *tcp;
841{
842 if (entering(tcp)) {
843 printpath(tcp, tcp->u_arg[0]);
844 tprintf(", ");
845 } else {
846 printstat(tcp, tcp->u_arg[1]);
847 }
848 return 0;
849}
850
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000851#ifdef linux
852int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000853sys_lstat64(tcp)
854struct tcb *tcp;
855{
856#ifdef HAVE_STAT64
857 if (entering(tcp)) {
858 printpath(tcp, tcp->u_arg[0]);
859 tprintf(", ");
860 } else {
861 printstat64(tcp, tcp->u_arg[1]);
862 }
863 return 0;
864#else
865 return printargs(tcp);
866#endif
867}
868
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000869# if !defined(IA64)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000870int
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000871sys_oldlstat(tcp)
872struct tcb *tcp;
873{
874 if (entering(tcp)) {
875 printpath(tcp, tcp->u_arg[0]);
876 tprintf(", ");
877 } else {
878 printoldstat(tcp, tcp->u_arg[1]);
879 }
880 return 0;
881}
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000882# endif /* !IA64 */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000883#endif
884
885
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000886#if defined(SVR4) || defined(LINUXSPARC)
887
888int
889sys_xstat(tcp)
890struct tcb *tcp;
891{
892 if (entering(tcp)) {
893 tprintf("%ld, ", tcp->u_arg[0]);
894 printpath(tcp, tcp->u_arg[1]);
895 tprintf(", ");
896 } else {
897 printstat(tcp, tcp->u_arg[2]);
898 }
899 return 0;
900}
901
902int
903sys_fxstat(tcp)
904struct tcb *tcp;
905{
906 if (entering(tcp))
907 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
908 else {
909 printstat(tcp, tcp->u_arg[2]);
910 }
911 return 0;
912}
913
914int
915sys_lxstat(tcp)
916struct tcb *tcp;
917{
918 if (entering(tcp)) {
919 tprintf("%ld, ", tcp->u_arg[0]);
920 printpath(tcp, tcp->u_arg[1]);
921 tprintf(", ");
922 } else {
923 printstat(tcp, tcp->u_arg[2]);
924 }
925 return 0;
926}
927
928int
929sys_xmknod(tcp)
930struct tcb *tcp;
931{
932 int mode = tcp->u_arg[2];
933
934 if (entering(tcp)) {
935 tprintf("%ld, ", tcp->u_arg[0]);
936 printpath(tcp, tcp->u_arg[1]);
937 tprintf(", %s", sprintmode(mode));
938 switch (mode & S_IFMT) {
939 case S_IFCHR: case S_IFBLK:
940#ifdef LINUXSPARC
941 tprintf(", makedev(%lu, %lu)",
942 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
943 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
944#else
945 tprintf(", makedev(%lu, %lu)",
946 (unsigned long) major(tcp->u_arg[3]),
947 (unsigned long) minor(tcp->u_arg[3]));
948#endif
949 break;
950 default:
951 break;
952 }
953 }
954 return 0;
955}
956
Wichert Akkerman8829a551999-06-11 13:18:40 +0000957#ifdef HAVE_SYS_ACL_H
958
959#include <sys/acl.h>
960
961struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000962#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +0000963 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000964#endif
965#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +0000966 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000967#endif
968#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +0000969 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +0000970#endif
971#ifdef ACL_GET
972 { ACL_GET, "ACL_GET" },
973#endif
974#ifdef ACL_SET
975 { ACL_SET, "ACL_SET" },
976#endif
977#ifdef ACL_CNT
978 { ACL_CNT, "ACL_CNT" },
979#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +0000980 { 0, NULL },
981};
982
983int
984sys_acl(tcp)
985struct tcb *tcp;
986{
987 if (entering(tcp)) {
988 printpath(tcp, tcp->u_arg[0]);
989 tprintf(", ");
990 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
991 tprintf(", %ld", tcp->u_arg[2]);
992 /*
993 * FIXME - dump out the list of aclent_t's pointed to
994 * by "tcp->u_arg[3]" if it's not NULL.
995 */
996 if (tcp->u_arg[3])
997 tprintf(", %#lx", tcp->u_arg[3]);
998 else
999 tprintf(", NULL");
1000 }
1001 return 0;
1002}
1003
1004
1005int
1006sys_facl(tcp)
1007struct tcb *tcp;
1008{
1009 if (entering(tcp)) {
1010 tprintf("%ld, ", tcp->u_arg[0]);
1011 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1012 tprintf(", %ld", tcp->u_arg[2]);
1013 /*
1014 * FIXME - dump out the list of aclent_t's pointed to
1015 * by "tcp->u_arg[3]" if it's not NULL.
1016 */
1017 if (tcp->u_arg[3])
1018 tprintf(", %#lx", tcp->u_arg[3]);
1019 else
1020 tprintf(", NULL");
1021 }
1022 return 0;
1023}
1024
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001025
1026struct xlat aclipc[] = {
1027#ifdef IPC_SHM
1028 { IPC_SHM, "IPC_SHM" },
1029#endif
1030#ifdef IPC_SEM
1031 { IPC_SEM, "IPC_SEM" },
1032#endif
1033#ifdef IPC_MSG
1034 { IPC_MSG, "IPC_MSG" },
1035#endif
1036 { 0, NULL },
1037};
1038
1039
1040int
1041sys_aclipc(tcp)
1042struct tcb *tcp;
1043{
1044 if (entering(tcp)) {
1045 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1046 tprintf(", %#lx, ", tcp->u_arg[1]);
1047 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1048 tprintf(", %ld", tcp->u_arg[3]);
1049 /*
1050 * FIXME - dump out the list of aclent_t's pointed to
1051 * by "tcp->u_arg[4]" if it's not NULL.
1052 */
1053 if (tcp->u_arg[4])
1054 tprintf(", %#lx", tcp->u_arg[4]);
1055 else
1056 tprintf(", NULL");
1057 }
1058 return 0;
1059}
1060
1061
1062
Wichert Akkerman8829a551999-06-11 13:18:40 +00001063#endif /* HAVE_SYS_ACL_H */
1064
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001065#endif /* SVR4 || LINUXSPARC */
1066
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001067#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001068
1069static struct xlat fsmagic[] = {
1070 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1071 { 0xef53, "EXT2_SUPER_MAGIC" },
1072 { 0x137d, "EXT_SUPER_MAGIC" },
1073 { 0x9660, "ISOFS_SUPER_MAGIC" },
1074 { 0x137f, "MINIX_SUPER_MAGIC" },
1075 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001076 { 0x2468, "MINIX2_SUPER_MAGIC" },
1077 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001078 { 0x4d44, "MSDOS_SUPER_MAGIC" },
1079 { 0x6969, "NFS_SUPER_MAGIC" },
1080 { 0x9fa0, "PROC_SUPER_MAGIC" },
1081 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
1082 { 0, NULL },
1083};
1084
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001085#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001086
1087#ifndef SVR4
1088
1089static char *
1090sprintfstype(magic)
1091int magic;
1092{
1093 static char buf[32];
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001094#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001095 char *s;
1096
1097 s = xlookup(fsmagic, magic);
1098 if (s) {
1099 sprintf(buf, "\"%s\"", s);
1100 return buf;
1101 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001102#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001103 sprintf(buf, "%#x", magic);
1104 return buf;
1105}
1106
1107static void
1108printstatfs(tcp, addr)
1109struct tcb *tcp;
1110long addr;
1111{
1112 struct statfs statbuf;
1113
1114 if (syserror(tcp) || !verbose(tcp)) {
1115 tprintf("%#lx", addr);
1116 return;
1117 }
1118 if (umove(tcp, addr, &statbuf) < 0) {
1119 tprintf("{...}");
1120 return;
1121 }
1122#ifdef ALPHA
1123
1124 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1125 sprintfstype(statbuf.f_type),
1126 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001127 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_namelen=%u",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001128 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree, statbuf.f_namelen);
1129#else /* !ALPHA */
1130 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1131 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001132 (unsigned long)statbuf.f_bsize,
1133 (unsigned long)statbuf.f_blocks,
1134 (unsigned long)statbuf.f_bfree);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001135 tprintf("f_files=%lu, f_ffree=%lu",
Nate Sammons5c74d201999-04-06 01:37:51 +00001136 (unsigned long)statbuf.f_files,
1137 (unsigned long)statbuf.f_ffree);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001138#ifdef linux
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001139 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001140#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001141#endif /* !ALPHA */
1142 tprintf("}");
1143}
1144
1145int
1146sys_statfs(tcp)
1147struct tcb *tcp;
1148{
1149 if (entering(tcp)) {
1150 printpath(tcp, tcp->u_arg[0]);
1151 tprintf(", ");
1152 } else {
1153 printstatfs(tcp, tcp->u_arg[1]);
1154 }
1155 return 0;
1156}
1157
1158int
1159sys_fstatfs(tcp)
1160struct tcb *tcp;
1161{
1162 if (entering(tcp)) {
1163 tprintf("%lu, ", tcp->u_arg[0]);
1164 } else {
1165 printstatfs(tcp, tcp->u_arg[1]);
1166 }
1167 return 0;
1168}
1169
Wichert Akkermana0f36c61999-04-16 14:01:34 +00001170#if defined(linux) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001171
1172int
1173osf_statfs(tcp)
1174struct tcb *tcp;
1175{
1176 if (entering(tcp)) {
1177 printpath(tcp, tcp->u_arg[0]);
1178 tprintf(", ");
1179 } else {
1180 printstatfs(tcp, tcp->u_arg[1]);
1181 tprintf(", %lu", tcp->u_arg[2]);
1182 }
1183 return 0;
1184}
1185
1186int
1187osf_fstatfs(tcp)
1188struct tcb *tcp;
1189{
1190 if (entering(tcp)) {
1191 tprintf("%lu, ", tcp->u_arg[0]);
1192 } else {
1193 printstatfs(tcp, tcp->u_arg[1]);
1194 tprintf(", %lu", tcp->u_arg[2]);
1195 }
1196 return 0;
1197}
Wichert Akkermana0f36c61999-04-16 14:01:34 +00001198#endif /* linux && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001199
1200#endif /* !SVR4 */
1201
1202#ifdef SUNOS4
1203
1204int
1205sys_ustat(tcp)
1206struct tcb *tcp;
1207{
1208 struct ustat statbuf;
1209
1210 if (entering(tcp)) {
1211 tprintf("makedev(%lu, %lu), ",
1212 (long) major(tcp->u_arg[0]),
1213 (long) minor(tcp->u_arg[0]));
1214 }
1215 else {
1216 if (syserror(tcp) || !verbose(tcp))
1217 tprintf("%#lx", tcp->u_arg[1]);
1218 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1219 tprintf("{...}");
1220 else {
1221 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1222 statbuf.f_tfree, statbuf.f_tinode);
1223 tprintf("f_fname=\"%.*s\", ",
1224 (int) sizeof(statbuf.f_fname),
1225 statbuf.f_fname);
1226 tprintf("f_fpack=\"%.*s\"}",
1227 (int) sizeof(statbuf.f_fpack),
1228 statbuf.f_fpack);
1229 }
1230 }
1231 return 0;
1232}
1233
1234#endif /* SUNOS4 */
1235
Wichert Akkermanc7926982000-04-10 22:22:31 +00001236int
1237sys_pivotroot(tcp)
1238struct tcb *tcp;
1239{
1240 if (entering(tcp)) {
1241 printpath(tcp, tcp->u_arg[0]);
1242 tprintf(", ");
1243 printpath(tcp, tcp->u_arg[1]);
1244 }
1245 return 0;
1246}
1247
1248
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001249/* directory */
1250int
1251sys_chdir(tcp)
1252struct tcb *tcp;
1253{
1254 if (entering(tcp)) {
1255 printpath(tcp, tcp->u_arg[0]);
1256 }
1257 return 0;
1258}
1259
1260int
1261sys_mkdir(tcp)
1262struct tcb *tcp;
1263{
1264 if (entering(tcp)) {
1265 printpath(tcp, tcp->u_arg[0]);
1266 tprintf(", %#lo", tcp->u_arg[1]);
1267 }
1268 return 0;
1269}
1270
1271int
1272sys_rmdir(tcp)
1273struct tcb *tcp;
1274{
1275 if (entering(tcp)) {
1276 printpath(tcp, tcp->u_arg[0]);
1277 }
1278 return 0;
1279}
1280
1281int
1282sys_fchdir(tcp)
1283struct tcb *tcp;
1284{
1285 if (entering(tcp)) {
1286 tprintf("%ld", tcp->u_arg[0]);
1287 }
1288 return 0;
1289}
1290
1291int
1292sys_chroot(tcp)
1293struct tcb *tcp;
1294{
1295 if (entering(tcp)) {
1296 printpath(tcp, tcp->u_arg[0]);
1297 }
1298 return 0;
1299}
1300
1301int
1302sys_fchroot(tcp)
1303struct tcb *tcp;
1304{
1305 if (entering(tcp)) {
1306 tprintf("%ld", tcp->u_arg[0]);
1307 }
1308 return 0;
1309}
1310
1311int
1312sys_link(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_unlink(tcp)
1325struct tcb *tcp;
1326{
1327 if (entering(tcp)) {
1328 printpath(tcp, tcp->u_arg[0]);
1329 }
1330 return 0;
1331}
1332
1333int
1334sys_symlink(tcp)
1335struct tcb *tcp;
1336{
1337 if (entering(tcp)) {
1338 printpath(tcp, tcp->u_arg[0]);
1339 tprintf(", ");
1340 printpath(tcp, tcp->u_arg[1]);
1341 }
1342 return 0;
1343}
1344
1345int
1346sys_readlink(tcp)
1347struct tcb *tcp;
1348{
1349 if (entering(tcp)) {
1350 printpath(tcp, tcp->u_arg[0]);
1351 tprintf(", ");
1352 } else {
1353 if (syserror(tcp))
1354 tprintf("%#lx", tcp->u_arg[1]);
1355 else
1356 printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
1357 tprintf(", %lu", tcp->u_arg[2]);
1358 }
1359 return 0;
1360}
1361
1362int
1363sys_rename(tcp)
1364struct tcb *tcp;
1365{
1366 if (entering(tcp)) {
1367 printpath(tcp, tcp->u_arg[0]);
1368 tprintf(", ");
1369 printpath(tcp, tcp->u_arg[1]);
1370 }
1371 return 0;
1372}
1373
1374int
1375sys_chown(tcp)
1376struct tcb *tcp;
1377{
1378 if (entering(tcp)) {
1379 printpath(tcp, tcp->u_arg[0]);
1380 tprintf(", %lu, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1381 }
1382 return 0;
1383}
1384
1385int
1386sys_fchown(tcp)
1387struct tcb *tcp;
1388{
1389 if (entering(tcp)) {
1390 tprintf("%ld, %lu, %lu",
1391 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1392 }
1393 return 0;
1394}
1395
1396int
1397sys_chmod(tcp)
1398struct tcb *tcp;
1399{
1400 if (entering(tcp)) {
1401 printpath(tcp, tcp->u_arg[0]);
1402 tprintf(", %#lo", tcp->u_arg[1]);
1403 }
1404 return 0;
1405}
1406
1407int
1408sys_fchmod(tcp)
1409struct tcb *tcp;
1410{
1411 if (entering(tcp)) {
1412 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
1413 }
1414 return 0;
1415}
1416
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001417#ifdef ALPHA
1418int
1419sys_osf_utimes(tcp)
1420struct tcb *tcp;
1421{
1422 if (entering(tcp)) {
1423 printpath(tcp, tcp->u_arg[0]);
1424 tprintf(", ");
1425 printtv32(tcp, tcp->u_arg[1]);
1426 }
1427 return 0;
1428}
1429#endif
1430
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001431int
1432sys_utimes(tcp)
1433struct tcb *tcp;
1434{
1435 if (entering(tcp)) {
1436 printpath(tcp, tcp->u_arg[0]);
1437 tprintf(", ");
1438 printtv(tcp, tcp->u_arg[1]);
1439 }
1440 return 0;
1441}
1442
1443int
1444sys_utime(tcp)
1445struct tcb *tcp;
1446{
1447 long ut[2];
1448
1449 if (entering(tcp)) {
1450 printpath(tcp, tcp->u_arg[0]);
1451 tprintf(", ");
1452 if (!tcp->u_arg[1])
1453 tprintf("NULL");
1454 else if (!verbose(tcp))
1455 tprintf("%#lx", tcp->u_arg[1]);
1456 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
1457 (char *) ut) < 0)
1458 tprintf("[?, ?]");
1459 else {
1460 tprintf("[%s,", sprinttime(ut[0]));
1461 tprintf(" %s]", sprinttime(ut[1]));
1462 }
1463 }
1464 return 0;
1465}
1466
1467int
1468sys_mknod(tcp)
1469struct tcb *tcp;
1470{
1471 int mode = tcp->u_arg[1];
1472
1473 if (entering(tcp)) {
1474 printpath(tcp, tcp->u_arg[0]);
1475 tprintf(", %s", sprintmode(mode));
1476 switch (mode & S_IFMT) {
1477 case S_IFCHR: case S_IFBLK:
1478#ifdef LINUXSPARC
1479 if (current_personality == 1)
1480 tprintf(", makedev(%lu, %lu)",
1481 (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
1482 (unsigned long) (tcp->u_arg[2] & 0x3ffff));
1483 else
1484#endif
1485 tprintf(", makedev(%lu, %lu)",
1486 (unsigned long) major(tcp->u_arg[2]),
1487 (unsigned long) minor(tcp->u_arg[2]));
1488 break;
1489 default:
1490 break;
1491 }
1492 }
1493 return 0;
1494}
1495
1496int
1497sys_mkfifo(tcp)
1498struct tcb *tcp;
1499{
1500 if (entering(tcp)) {
1501 printpath(tcp, tcp->u_arg[0]);
1502 tprintf(", %#lo", tcp->u_arg[1]);
1503 }
1504 return 0;
1505}
1506
1507int
1508sys_fsync(tcp)
1509struct tcb *tcp;
1510{
1511 if (entering(tcp)) {
1512 tprintf("%ld", tcp->u_arg[0]);
1513 }
1514 return 0;
1515}
1516
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001517#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001518
1519static void
1520printdir(tcp, addr)
1521struct tcb *tcp;
1522long addr;
1523{
1524 struct dirent d;
1525
1526 if (!verbose(tcp)) {
1527 tprintf("%#lx", addr);
1528 return;
1529 }
1530 if (umove(tcp, addr, &d) < 0) {
1531 tprintf("{...}");
1532 return;
1533 }
1534 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001535 tprintf("d_name=");
1536 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
1537 tprintf("}");
1538}
1539
1540int
1541sys_readdir(tcp)
1542struct tcb *tcp;
1543{
1544 if (entering(tcp)) {
1545 tprintf("%lu, ", tcp->u_arg[0]);
1546 } else {
1547 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
1548 tprintf("%#lx", tcp->u_arg[1]);
1549 else
1550 printdir(tcp, tcp->u_arg[1]);
1551 /* Not much point in printing this out, it is always 1. */
1552 if (tcp->u_arg[2] != 1)
1553 tprintf(", %lu", tcp->u_arg[2]);
1554 }
1555 return 0;
1556}
1557
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001558#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001559
1560int
1561sys_getdents(tcp)
1562struct tcb *tcp;
1563{
1564 int i, len, dents = 0;
1565 char *buf;
1566
1567 if (entering(tcp)) {
1568 tprintf("%lu, ", tcp->u_arg[0]);
1569 return 0;
1570 }
1571 if (syserror(tcp) || !verbose(tcp)) {
1572 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1573 return 0;
1574 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001575 len = tcp->u_rval;
1576 if ((buf = malloc(len)) == NULL) {
1577 tprintf("out of memory\n");
1578 return 0;
1579 }
1580 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1581 tprintf("{...}, %lu", tcp->u_arg[2]);
1582 free(buf);
1583 return 0;
1584 }
1585 if (!abbrev(tcp))
1586 tprintf("{");
1587 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00001588 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001589#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001590 if (!abbrev(tcp)) {
1591 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1592 i ? " " : "", d->d_ino, d->d_off);
1593 tprintf("d_reclen=%u, d_name=\"%s\"}",
1594 d->d_reclen, d->d_name);
1595 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001596#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001597#ifdef SVR4
1598 if (!abbrev(tcp)) {
1599 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1600 i ? " " : "", d->d_ino, d->d_off);
1601 tprintf("d_reclen=%u, d_name=\"%s\"}",
1602 d->d_reclen, d->d_name);
1603 }
1604#endif /* SVR4 */
1605#ifdef SUNOS4
1606 if (!abbrev(tcp)) {
1607 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
1608 i ? " " : "", d->d_off, d->d_fileno,
1609 d->d_reclen);
1610 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
1611 d->d_namlen, d->d_namlen, d->d_name);
1612 }
1613#endif /* SUNOS4 */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00001614 if (!d->d_reclen) {
1615 tprintf("/* d_reclen == 0, problem here */");
1616 break;
1617 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001618 i += d->d_reclen;
1619 dents++;
1620 }
1621 if (!abbrev(tcp))
1622 tprintf("}");
1623 else
1624 tprintf("/* %u entries */", dents);
1625 tprintf(", %lu", tcp->u_arg[2]);
1626 free(buf);
1627 return 0;
1628}
1629
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001630#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001631
1632int
1633sys_getcwd(tcp)
1634struct tcb *tcp;
1635{
1636 if (exiting(tcp)) {
1637 if (syserror(tcp))
1638 tprintf("%#lx", tcp->u_arg[0]);
1639 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001640 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001641 tprintf(", %lu", tcp->u_arg[1]);
1642 }
1643 return 0;
1644}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001645#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001646
1647#ifdef HAVE_SYS_ASYNCH_H
1648
1649int
1650sys_aioread(tcp)
1651struct tcb *tcp;
1652{
1653 struct aio_result_t res;
1654
1655 if (entering(tcp)) {
1656 tprintf("%lu, ", tcp->u_arg[0]);
1657 } else {
1658 if (syserror(tcp))
1659 tprintf("%#lx", tcp->u_arg[1]);
1660 else
1661 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1662 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
1663 printxval(whence, tcp->u_arg[4], "L_???");
1664 if (syserror(tcp) || tcp->u_arg[5] == 0
1665 || umove(tcp, tcp->u_arg[5], &res) < 0)
1666 tprintf(", %#lx", tcp->u_arg[5]);
1667 else
1668 tprintf(", {aio_return %d aio_errno %d}",
1669 res.aio_return, res.aio_errno);
1670 }
1671 return 0;
1672}
1673
1674int
1675sys_aiowrite(tcp)
1676struct tcb *tcp;
1677{
1678 struct aio_result_t res;
1679
1680 if (entering(tcp)) {
1681 tprintf("%lu, ", tcp->u_arg[0]);
1682 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1683 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
1684 printxval(whence, tcp->u_arg[4], "L_???");
1685 }
1686 else {
1687 if (tcp->u_arg[5] == 0)
1688 tprintf(", NULL");
1689 else if (syserror(tcp)
1690 || umove(tcp, tcp->u_arg[5], &res) < 0)
1691 tprintf(", %#lx", tcp->u_arg[5]);
1692 else
1693 tprintf(", {aio_return %d aio_errno %d}",
1694 res.aio_return, res.aio_errno);
1695 }
1696 return 0;
1697}
1698
1699int
1700sys_aiowait(tcp)
1701struct tcb *tcp;
1702{
1703 if (entering(tcp))
1704 printtv(tcp, tcp->u_arg[0]);
1705 return 0;
1706}
1707
1708int
1709sys_aiocancel(tcp)
1710struct tcb *tcp;
1711{
1712 struct aio_result_t res;
1713
1714 if (exiting(tcp)) {
1715 if (tcp->u_arg[0] == 0)
1716 tprintf("NULL");
1717 else if (syserror(tcp)
1718 || umove(tcp, tcp->u_arg[0], &res) < 0)
1719 tprintf("%#lx", tcp->u_arg[0]);
1720 else
1721 tprintf("{aio_return %d aio_errno %d}",
1722 res.aio_return, res.aio_errno);
1723 }
1724 return 0;
1725}
1726
1727#endif /* HAVE_SYS_ASYNCH_H */