blob: a2663d1a5f6076d9489a62532d20c1e067839e34 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
John Hughese2f6d872001-03-07 16:03:20 +00002#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
4 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
5 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00006 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00007 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * $Id$
32 */
33
34#include "defs.h"
35
36#include <dirent.h>
Wichert Akkerman9524bb91999-05-25 23:11:18 +000037#ifdef linux
38#define dirent kernel_dirent
Wichert Akkerman9b0c31d2000-09-03 21:56:29 +000039#define dirent64 kernel_dirent64
Wichert Akkerman9524bb91999-05-25 23:11:18 +000040#include <linux/types.h>
41#include <linux/dirent.h>
42#undef dirent
43#else
44#define kernel_dirent dirent
45#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000046
Wichert Akkerman8bc6cfd1999-04-21 15:57:38 +000047#ifdef linux
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000048# ifdef LINUXSPARC
49struct stat {
50 unsigned short st_dev;
51 unsigned int st_ino;
52 unsigned short st_mode;
53 short st_nlink;
54 unsigned short st_uid;
55 unsigned short st_gid;
56 unsigned short st_rdev;
57 unsigned int st_size;
58 int st_atime;
59 unsigned int __unused1;
60 int st_mtime;
61 unsigned int __unused2;
62 int st_ctime;
63 unsigned int __unused3;
64 int st_blksize;
65 int st_blocks;
66 unsigned int __unused4[2];
67};
68# define stat kernel_stat
69# include <asm/stat.h>
70# undef stat
71# else
Wichert Akkerman5b4d1281999-07-09 00:32:54 +000072# undef dev_t
73# undef ino_t
74# undef mode_t
75# undef nlink_t
76# undef uid_t
77# undef gid_t
78# undef off_t
79# undef loff_t
80
Wichert Akkermana6013701999-07-08 14:00:58 +000081# define dev_t __kernel_dev_t
82# define ino_t __kernel_ino_t
83# define mode_t __kernel_mode_t
84# define nlink_t __kernel_nlink_t
85# define uid_t __kernel_uid_t
86# define gid_t __kernel_gid_t
87# define off_t __kernel_off_t
88# define loff_t __kernel_loff_t
89
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000090# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +000091
92# undef dev_t
93# undef ino_t
94# undef mode_t
95# undef nlink_t
96# undef uid_t
97# undef gid_t
98# undef off_t
99# undef loff_t
Wichert Akkerman5b4d1281999-07-09 00:32:54 +0000100
101# define dev_t dev_t
102# define ino_t ino_t
103# define mode_t mode_t
104# define nlink_t nlink_t
105# define uid_t uid_t
106# define gid_t gid_t
107# define off_t off_t
108# define loff_t loff_t
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000109# endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000110# define stat libc_stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000111# define stat64 libc_stat64
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000112# include <sys/stat.h>
113# undef stat
Ulrich Drepper0fa01d71999-12-24 07:18:28 +0000114# undef stat64
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000115#else
116# include <sys/stat.h>
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000117#endif
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000118
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000119#include <fcntl.h>
120
121#ifdef SVR4
122# include <sys/cred.h>
123#endif /* SVR4 */
124
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000125#ifdef HAVE_SYS_VFS_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000126#include <sys/vfs.h>
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000127#endif
128
129#ifdef FREEBSD
130#include <sys/param.h>
131#include <sys/mount.h>
132#include <sys/stat.h>
John Hughes70623be2001-03-08 13:59:00 +0000133#endif
134
135#if HAVE_LONG_LONG_OFF_T
136/*
137 * Ugly hacks for systems that have typedef long long off_t
138 */
John Hughesb8c9f772001-03-07 16:53:07 +0000139
140#define stat64 stat
141#define HAVE_STAT64 1 /* Ugly hack */
John Hughes70623be2001-03-08 13:59:00 +0000142
143#define sys_stat64 sys_stat
144#define sys_fstat64 sys_fstat
145#define sys_lstat64 sys_lstat
146#define sys_lseek64 sys_lseek
147#define sys_truncate64 sys_truncate
148#define sys_ftruncate64 sys_ftruncate
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000149#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000150
151#ifdef MAJOR_IN_SYSMACROS
152#include <sys/sysmacros.h>
153#endif
154
155#ifdef MAJOR_IN_MKDEV
156#include <sys/mkdev.h>
157#endif
158
159#ifdef HAVE_SYS_ASYNCH_H
160#include <sys/asynch.h>
161#endif
162
163#ifdef SUNOS4
164#include <ustat.h>
165#endif
166
167/*
168 * This is a really dirty trick but it should always work. Traditional
169 * Unix says r/w/rw are 0/1/2, so we make them true flags 1/2/3 by
170 * adding 1. Just remember to add 1 to any arg decoded with openmodes.
171 */
172struct xlat openmodes[] = {
173 { O_RDWR+1, "O_RDWR" },
174 { O_RDONLY+1, "O_RDONLY" },
175 { O_WRONLY+1, "O_WRONLY" },
176 { O_NONBLOCK, "O_NONBLOCK" },
177 { O_APPEND, "O_APPEND" },
178 { O_CREAT, "O_CREAT" },
179 { O_TRUNC, "O_TRUNC" },
180 { O_EXCL, "O_EXCL" },
181 { O_NOCTTY, "O_NOCTTY" },
182#ifdef O_SYNC
183 { O_SYNC, "O_SYNC" },
184#endif
185#ifdef O_ASYNC
186 { O_ASYNC, "O_ASYNC" },
187#endif
188#ifdef O_DSYNC
189 { O_DSYNC, "O_DSYNC" },
190#endif
191#ifdef O_RSYNC
192 { O_RSYNC, "O_RSYNC" },
193#endif
194#ifdef O_NDELAY
195 { O_NDELAY, "O_NDELAY" },
196#endif
197#ifdef O_PRIV
198 { O_PRIV, "O_PRIV" },
199#endif
200#ifdef O_DIRECT
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000201 { O_DIRECT, "O_DIRECT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000202#endif
203#ifdef O_LARGEFILE
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000204 { O_LARGEFILE, "O_LARGEFILE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205#endif
206#ifdef O_DIRECTORY
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000207 { O_DIRECTORY, "O_DIRECTORY" },
208#endif
209#ifdef O_NOFOLLOW
210 { O_NOFOLLOW, "O_NOFOLLOW" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000211#endif
212
213#ifdef FNDELAY
214 { FNDELAY, "FNDELAY" },
215#endif
216#ifdef FAPPEND
217 { FAPPEND, "FAPPEND" },
218#endif
219#ifdef FMARK
220 { FMARK, "FMARK" },
221#endif
222#ifdef FDEFER
223 { FDEFER, "FDEFER" },
224#endif
225#ifdef FASYNC
226 { FASYNC, "FASYNC" },
227#endif
228#ifdef FSHLOCK
229 { FSHLOCK, "FSHLOCK" },
230#endif
231#ifdef FEXLOCK
232 { FEXLOCK, "FEXLOCK" },
233#endif
234#ifdef FCREAT
235 { FCREAT, "FCREAT" },
236#endif
237#ifdef FTRUNC
238 { FTRUNC, "FTRUNC" },
239#endif
240#ifdef FEXCL
241 { FEXCL, "FEXCL" },
242#endif
243#ifdef FNBIO
244 { FNBIO, "FNBIO" },
245#endif
246#ifdef FSYNC
247 { FSYNC, "FSYNC" },
248#endif
249#ifdef FNOCTTY
250 { FNOCTTY, "FNOCTTY" },
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000251#endif
252#ifdef O_SHLOCK
253 { O_SHLOCK, "O_SHLOCK" },
254#endif
255#ifdef O_EXLOCK
256 { O_EXLOCK, "O_EXLOCK" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000257#endif
258 { 0, NULL },
259};
260
261int
262sys_open(tcp)
263struct tcb *tcp;
264{
265 if (entering(tcp)) {
266 printpath(tcp, tcp->u_arg[0]);
267 tprintf(", ");
268 /* flags */
269 printflags(openmodes, tcp->u_arg[1] + 1);
270 if (tcp->u_arg[1] & O_CREAT) {
271 /* mode */
272 tprintf(", %#lo", tcp->u_arg[2]);
273 }
274 }
275 return 0;
276}
277
278#ifdef LINUXSPARC
279struct xlat openmodessol[] = {
280 { 0, "O_RDWR" },
281 { 1, "O_RDONLY" },
282 { 2, "O_WRONLY" },
283 { 0x80, "O_NONBLOCK" },
284 { 8, "O_APPEND" },
285 { 0x100, "O_CREAT" },
286 { 0x200, "O_TRUNC" },
287 { 0x400, "O_EXCL" },
288 { 0x800, "O_NOCTTY" },
289 { 0x10, "O_SYNC" },
290 { 0x40, "O_DSYNC" },
291 { 0x8000, "O_RSYNC" },
292 { 4, "O_NDELAY" },
293 { 0x1000, "O_PRIV" },
294 { 0, NULL },
295};
296
297int
298solaris_open(tcp)
299struct tcb *tcp;
300{
301 if (entering(tcp)) {
302 printpath(tcp, tcp->u_arg[0]);
303 tprintf(", ");
304 /* flags */
305 printflags(openmodessol, tcp->u_arg[1] + 1);
306 if (tcp->u_arg[1] & 0x100) {
307 /* mode */
308 tprintf(", %#lo", tcp->u_arg[2]);
309 }
310 }
311 return 0;
312}
313
314#endif
315
316int
317sys_creat(tcp)
318struct tcb *tcp;
319{
320 if (entering(tcp)) {
321 printpath(tcp, tcp->u_arg[0]);
322 tprintf(", %#lo", tcp->u_arg[1]);
323 }
324 return 0;
325}
326
327static struct xlat access_flags[] = {
328 { F_OK, "F_OK", },
329 { R_OK, "R_OK" },
330 { W_OK, "W_OK" },
331 { X_OK, "X_OK" },
332#ifdef EFF_ONLY_OK
333 { EFF_ONLY_OK, "EFF_ONLY_OK" },
334#endif
335#ifdef EX_OK
336 { EX_OK, "EX_OK" },
337#endif
338 { 0, NULL },
339};
340
341int
342sys_access(tcp)
343struct tcb *tcp;
344{
345 if (entering(tcp)) {
346 printpath(tcp, tcp->u_arg[0]);
347 tprintf(", ");
348 printflags(access_flags, tcp->u_arg[1]);
349 }
350 return 0;
351}
352
353int
354sys_umask(tcp)
355struct tcb *tcp;
356{
357 if (entering(tcp)) {
358 tprintf("%#lo", tcp->u_arg[0]);
359 }
360 return RVAL_OCTAL;
361}
362
363static struct xlat whence[] = {
364 { SEEK_SET, "SEEK_SET" },
365 { SEEK_CUR, "SEEK_CUR" },
366 { SEEK_END, "SEEK_END" },
367 { 0, NULL },
368};
369
John Hughes70623be2001-03-08 13:59:00 +0000370#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000371int
372sys_lseek(tcp)
373struct tcb *tcp;
374{
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000375 off_t offset;
376 int _whence;
377
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000378 if (entering(tcp)) {
379 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000380 offset = tcp->u_arg[1];
381 _whence = tcp->u_arg[2];
382 if (_whence == SEEK_SET)
383 tprintf("%lu, ", offset);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000384 else
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000385 tprintf("%ld, ", offset);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000386 printxval(whence, _whence, "SEEK_???");
387 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000388 return RVAL_UDECIMAL;
389}
John Hughes5a826b82001-03-07 13:21:24 +0000390#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000391
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000392#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000393int
394sys_llseek (tcp)
395struct tcb *tcp;
396{
397 if (entering(tcp)) {
398 if (tcp->u_arg[4] == SEEK_SET)
399 tprintf("%ld, %llu, ", tcp->u_arg[0],
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000400 (((long long int) tcp->u_arg[1]) << 32
401 | (unsigned long long) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000402 else
403 tprintf("%ld, %lld, ", tcp->u_arg[0],
404 (((long long int) tcp->u_arg[1]) << 32
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000405 | (unsigned long long) tcp->u_arg[2]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406 }
407 else {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000408 long long int off;
409 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000410 tprintf("%#lx, ", tcp->u_arg[3]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000411 else
412 tprintf("[%llu], ", off);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000413 printxval(whence, tcp->u_arg[4], "SEEK_???");
414 }
415 return 0;
416}
417#endif
418
John Hughes70623be2001-03-08 13:59:00 +0000419#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000420int
421sys_lseek64 (tcp)
422struct tcb *tcp;
423{
424 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000425 long long offset;
426 ALIGN64 (tcp, 1); /* FreeBSD aligns off_t args */
John Hughes0c79e012001-03-08 14:40:06 +0000427 offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
John Hughesbdf48f52001-03-06 15:08:09 +0000428 if (tcp->u_arg[3] == SEEK_SET)
429 tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
430 else
431 tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
432 printxval(whence, tcp->u_arg[3], "SEEK_???");
433 }
434 return RVAL_LUDECIMAL;
435}
436#endif
437
John Hughes70623be2001-03-08 13:59:00 +0000438#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000439int
440sys_truncate(tcp)
441struct tcb *tcp;
442{
443 if (entering(tcp)) {
444 printpath(tcp, tcp->u_arg[0]);
445 tprintf(", %lu", tcp->u_arg[1]);
446 }
447 return 0;
448}
John Hughes5a826b82001-03-07 13:21:24 +0000449#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000450
John Hughes70623be2001-03-08 13:59:00 +0000451#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000452int
453sys_truncate64(tcp)
454struct tcb *tcp;
455{
456 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000457 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000458 printpath(tcp, tcp->u_arg[0]);
John Hughes0c79e012001-03-08 14:40:06 +0000459 tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000460 }
461 return 0;
462}
463#endif
464
John Hughes70623be2001-03-08 13:59:00 +0000465#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000466int
467sys_ftruncate(tcp)
468struct tcb *tcp;
469{
470 if (entering(tcp)) {
471 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
472 }
473 return 0;
474}
John Hughes5a826b82001-03-07 13:21:24 +0000475#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000476
John Hughes70623be2001-03-08 13:59:00 +0000477#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughes96f51472001-03-06 16:50:41 +0000478int
479sys_ftruncate64(tcp)
480struct tcb *tcp;
481{
482 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000483 ALIGN64 (tcp, 1);
John Hughes96f51472001-03-06 16:50:41 +0000484 tprintf("%ld, %llu", tcp->u_arg[0],
John Hughes0c79e012001-03-08 14:40:06 +0000485 LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
John Hughes96f51472001-03-06 16:50:41 +0000486 }
487 return 0;
488}
489#endif
490
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000491/* several stats */
492
493static struct xlat modetypes[] = {
494 { S_IFREG, "S_IFREG" },
495 { S_IFSOCK, "S_IFSOCK" },
496 { S_IFIFO, "S_IFIFO" },
497 { S_IFLNK, "S_IFLNK" },
498 { S_IFDIR, "S_IFDIR" },
499 { S_IFBLK, "S_IFBLK" },
500 { S_IFCHR, "S_IFCHR" },
501 { 0, NULL },
502};
503
504static char *
505sprintmode(mode)
506int mode;
507{
508 static char buf[64];
509 char *s;
510
511 if ((mode & S_IFMT) == 0)
512 s = "";
513 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
514 sprintf(buf, "%#o", mode);
515 return buf;
516 }
517 sprintf(buf, "%s%s%s%s", s,
518 (mode & S_ISUID) ? "|S_ISUID" : "",
519 (mode & S_ISGID) ? "|S_ISGID" : "",
520 (mode & S_ISVTX) ? "|S_ISVTX" : "");
521 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
522 if (mode)
523 sprintf(buf + strlen(buf), "|%#o", mode);
524 s = (*buf == '|') ? buf + 1 : buf;
525 return *s ? s : "0";
526}
527
528static char *
529sprinttime(t)
530time_t t;
531{
532 struct tm *tmp;
533 static char buf[32];
534
535 if (t == 0) {
536 sprintf(buf, "0");
537 return buf;
538 }
539 tmp = localtime(&t);
540 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
Wichert Akkerman3ed6dc22000-01-11 14:41:09 +0000541 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000542 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
543 return buf;
544}
545
546#ifdef LINUXSPARC
547typedef struct {
548 int tv_sec;
549 int tv_nsec;
550} timestruct_t;
551
552struct solstat {
553 unsigned st_dev;
554 int st_pad1[3]; /* network id */
555 unsigned st_ino;
556 unsigned st_mode;
557 unsigned st_nlink;
558 unsigned st_uid;
559 unsigned st_gid;
560 unsigned st_rdev;
561 int st_pad2[2];
562 int st_size;
563 int st_pad3; /* st_size, off_t expansion */
564 timestruct_t st_atime;
565 timestruct_t st_mtime;
566 timestruct_t st_ctime;
567 int st_blksize;
568 int st_blocks;
569 char st_fstype[16];
570 int st_pad4[8]; /* expansion area */
571};
572
573static void
574printstatsol(tcp, addr)
575struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000576long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000577{
578 struct solstat statbuf;
579
580 if (!addr) {
581 tprintf("NULL");
582 return;
583 }
584 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000585 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000586 return;
587 }
588 if (umove(tcp, addr, &statbuf) < 0) {
589 tprintf("{...}");
590 return;
591 }
592 if (!abbrev(tcp)) {
593 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
594 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
595 (unsigned long) (statbuf.st_dev & 0x3ffff),
596 (unsigned long) statbuf.st_ino,
597 sprintmode(statbuf.st_mode));
598 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
599 (unsigned long) statbuf.st_nlink,
600 (unsigned long) statbuf.st_uid,
601 (unsigned long) statbuf.st_gid);
602 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
603 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
604 }
605 else
606 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
607 switch (statbuf.st_mode & S_IFMT) {
608 case S_IFCHR: case S_IFBLK:
609 tprintf("st_rdev=makedev(%lu, %lu), ",
610 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
611 (unsigned long) (statbuf.st_rdev & 0x3ffff));
612 break;
613 default:
614 tprintf("st_size=%u, ", statbuf.st_size);
615 break;
616 }
617 if (!abbrev(tcp)) {
618 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
619 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
620 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
621 }
622 else
623 tprintf("...}");
624}
Wichert Akkermanb859bea1999-04-18 22:50:50 +0000625#endif /* LINUXSPARC */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000626
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000627static struct xlat fileflags[] = {
John Hughesc0fc3fd2001-03-08 16:10:40 +0000628#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000629 { UF_NODUMP, "UF_NODUMP" },
630 { UF_IMMUTABLE, "UF_IMMUTABLE" },
631 { UF_APPEND, "UF_APPEND" },
632 { UF_OPAQUE, "UF_OPAQUE" },
633 { UF_NOUNLINK, "UF_NOUNLINK" },
634 { SF_ARCHIVED, "SF_ARCHIVED" },
635 { SF_IMMUTABLE, "SF_IMMUTABLE" },
636 { SF_APPEND, "SF_APPEND" },
637 { SF_NOUNLINK, "SF_NOUNLINK" },
John Hughesc0fc3fd2001-03-08 16:10:40 +0000638#elif UNIXWARE >= 2
639#ifdef _S_ISMLD
640 { _S_ISMLD, "_S_ISMLD" },
641#endif
642#ifdef _S_ISMOUNTED
643 { _S_ISMOUNTED, "_S_ISMOUNTED" },
644#endif
645#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000646 { 0, NULL },
647};
648
John Hughesc0fc3fd2001-03-08 16:10:40 +0000649#ifdef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000650int
651sys_chflags(tcp)
652struct tcb *tcp;
653{
654 if (entering(tcp)) {
655 printpath(tcp, tcp->u_arg[0]);
656 tprintf(", ");
657 if (tcp->u_arg[1])
658 printflags(fileflags, tcp->u_arg[1]);
659 else
660 tprintf("0");
661 }
662 return 0;
663}
664
665int
666sys_fchflags(tcp)
667struct tcb *tcp;
668{
669 if (entering(tcp)) {
670 tprintf("%ld, ", tcp->u_arg[0]);
671 if (tcp->u_arg[1])
672 printflags(fileflags, tcp->u_arg[1]);
673 else
674 tprintf("0");
675 }
676 return 0;
677}
678#endif
679
John Hughes70623be2001-03-08 13:59:00 +0000680#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000681static void
682realprintstat(tcp, statbuf)
683struct tcb *tcp;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000684struct stat *statbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000685{
686 if (!abbrev(tcp)) {
687 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
688 (unsigned long) major(statbuf->st_dev),
689 (unsigned long) minor(statbuf->st_dev),
690 (unsigned long) statbuf->st_ino,
691 sprintmode(statbuf->st_mode));
692 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
693 (unsigned long) statbuf->st_nlink,
694 (unsigned long) statbuf->st_uid,
695 (unsigned long) statbuf->st_gid);
696#ifdef HAVE_ST_BLKSIZE
697 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
698#endif /* HAVE_ST_BLKSIZE */
699#ifdef HAVE_ST_BLOCKS
700 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
701#endif /* HAVE_ST_BLOCKS */
702 }
703 else
704 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
705 switch (statbuf->st_mode & S_IFMT) {
706 case S_IFCHR: case S_IFBLK:
707#ifdef HAVE_ST_RDEV
708 tprintf("st_rdev=makedev(%lu, %lu), ",
709 (unsigned long) major(statbuf->st_rdev),
710 (unsigned long) minor(statbuf->st_rdev));
711#else /* !HAVE_ST_RDEV */
712 tprintf("st_size=makedev(%lu, %lu), ",
713 (unsigned long) major(statbuf->st_size),
714 (unsigned long) minor(statbuf->st_size));
715#endif /* !HAVE_ST_RDEV */
716 break;
717 default:
718 tprintf("st_size=%lu, ", statbuf->st_size);
719 break;
720 }
721 if (!abbrev(tcp)) {
722 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
723 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000724 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
725#if HAVE_ST_FLAGS
726 tprintf(", st_flags=");
727 if (statbuf->st_flags) {
728 printflags(fileflags, statbuf->st_flags);
729 } else
730 tprintf("0");
731#endif
732#if HAVE_ST_ACLCNT
733 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
734#endif
735#if HAVE_ST_LEVEL
736 tprintf(", st_level=%ld", statbuf->st_level);
737#endif
738#if HAVE_ST_FSTYPE
739 tprintf(", st_fstype=%.*s",
740 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
741#endif
742#if HAVE_ST_GEN
743 tprintf(", st_gen=%u", statbuf->st_gen);
744#endif
745 tprintf("}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000746 }
747 else
748 tprintf("...}");
749}
750
Nate Sammons771a6ff1999-04-05 22:39:31 +0000751
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000752static void
753printstat(tcp, addr)
754struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000755long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000756{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000757 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000758
759#ifdef LINUXSPARC
760 if (current_personality == 1) {
761 printstatsol(tcp, addr);
762 return;
763 }
764#endif /* LINUXSPARC */
765
766 if (!addr) {
767 tprintf("NULL");
768 return;
769 }
770 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000771 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000772 return;
773 }
774 if (umove(tcp, addr, &statbuf) < 0) {
775 tprintf("{...}");
776 return;
777 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000778
779 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000780}
John Hughes70623be2001-03-08 13:59:00 +0000781#endif /* !HAVE_LONG_LONG_OFF_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000782
Wichert Akkermanc7926982000-04-10 22:22:31 +0000783#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000784static void
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000785printstat64(tcp, addr)
786struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000787long addr;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000788{
789 struct stat64 statbuf;
790
791#ifdef LINUXSPARC
792 if (current_personality == 1) {
793 printstatsol(tcp, addr);
794 return;
795 }
796#endif /* LINUXSPARC */
797
798 if (!addr) {
799 tprintf("NULL");
800 return;
801 }
802 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000803 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000804 return;
805 }
806 if (umove(tcp, addr, &statbuf) < 0) {
807 tprintf("{...}");
808 return;
809 }
810
811 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +0000812#ifdef HAVE_LONG_LONG
813 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
814#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000815 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
Wichert Akkermand077c452000-08-10 18:16:15 +0000816#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000817 (unsigned long) major(statbuf.st_dev),
818 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +0000819#ifdef HAVE_LONG_LONG
820 (unsigned long long) statbuf.st_ino,
821#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000822 (unsigned long) statbuf.st_ino,
Wichert Akkermand077c452000-08-10 18:16:15 +0000823#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000824 sprintmode(statbuf.st_mode));
825 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
826 (unsigned long) statbuf.st_nlink,
827 (unsigned long) statbuf.st_uid,
828 (unsigned long) statbuf.st_gid);
829#ifdef HAVE_ST_BLKSIZE
830 tprintf("st_blksize=%lu, ",
831 (unsigned long) statbuf.st_blksize);
832#endif /* HAVE_ST_BLKSIZE */
833#ifdef HAVE_ST_BLOCKS
834 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
835#endif /* HAVE_ST_BLOCKS */
836 }
837 else
838 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
839 switch (statbuf.st_mode & S_IFMT) {
840 case S_IFCHR: case S_IFBLK:
841#ifdef HAVE_ST_RDEV
842 tprintf("st_rdev=makedev(%lu, %lu), ",
843 (unsigned long) major(statbuf.st_rdev),
844 (unsigned long) minor(statbuf.st_rdev));
845#else /* !HAVE_ST_RDEV */
846 tprintf("st_size=makedev(%lu, %lu), ",
847 (unsigned long) major(statbuf.st_size),
848 (unsigned long) minor(statbuf.st_size));
849#endif /* !HAVE_ST_RDEV */
850 break;
851 default:
852 tprintf("st_size=%llu, ", statbuf.st_size);
853 break;
854 }
855 if (!abbrev(tcp)) {
856 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
857 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000858 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
859#if HAVE_ST_FLAGS
860 tprintf(", st_flags=");
John Hughesb8c9f772001-03-07 16:53:07 +0000861 if (statbuf.st_flags) {
862 printflags(fileflags, statbuf.st_flags);
863 } else
864 tprintf("0");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000865#endif
866#if HAVE_ST_ACLCNT
867 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
868#endif
869#if HAVE_ST_LEVEL
870 tprintf(", st_level=%ld", statbuf.st_level);
871#endif
872#if HAVE_ST_FSTYPE
873 tprintf(", st_fstype=%.*s",
874 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
875#endif
876#if HAVE_ST_GEN
877 tprintf(", st_gen=%u", statbuf.st_gen);
878#endif
879 tprintf("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000880 }
881 else
882 tprintf("...}");
883}
Wichert Akkermanc7926982000-04-10 22:22:31 +0000884#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000885
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000886#if defined(linux) && !defined(IA64)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000887static void
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000888convertoldstat(oldbuf, newbuf)
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000889const struct __old_kernel_stat *oldbuf;
890struct stat *newbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000891{
892 newbuf->st_dev=oldbuf->st_dev;
893 newbuf->st_ino=oldbuf->st_ino;
894 newbuf->st_mode=oldbuf->st_mode;
895 newbuf->st_nlink=oldbuf->st_nlink;
896 newbuf->st_uid=oldbuf->st_uid;
897 newbuf->st_gid=oldbuf->st_gid;
898 newbuf->st_rdev=oldbuf->st_rdev;
899 newbuf->st_size=oldbuf->st_size;
900 newbuf->st_atime=oldbuf->st_atime;
901 newbuf->st_mtime=oldbuf->st_mtime;
902 newbuf->st_ctime=oldbuf->st_ctime;
903 newbuf->st_blksize=0; /* not supported in old_stat */
904 newbuf->st_blocks=0; /* not supported in old_stat */
905}
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000906
907
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000908static void
909printoldstat(tcp, addr)
910struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000911long addr;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000912{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000913 struct __old_kernel_stat statbuf;
914 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000915
916#ifdef LINUXSPARC
917 if (current_personality == 1) {
918 printstatsol(tcp, addr);
919 return;
920 }
921#endif /* LINUXSPARC */
922
923 if (!addr) {
924 tprintf("NULL");
925 return;
926 }
927 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000928 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000929 return;
930 }
931 if (umove(tcp, addr, &statbuf) < 0) {
932 tprintf("{...}");
933 return;
934 }
935
936 convertoldstat(&statbuf, &newstatbuf);
937 realprintstat(tcp, &newstatbuf);
938}
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000939#endif /* linux && !IA64 */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000940
John Hughes70623be2001-03-08 13:59:00 +0000941#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000942int
943sys_stat(tcp)
944struct tcb *tcp;
945{
946 if (entering(tcp)) {
947 printpath(tcp, tcp->u_arg[0]);
948 tprintf(", ");
949 } else {
950 printstat(tcp, tcp->u_arg[1]);
951 }
952 return 0;
953}
John Hughesb8c9f772001-03-07 16:53:07 +0000954#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000955
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000956int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000957sys_stat64(tcp)
958struct tcb *tcp;
959{
960#ifdef HAVE_STAT64
961 if (entering(tcp)) {
962 printpath(tcp, tcp->u_arg[0]);
963 tprintf(", ");
964 } else {
965 printstat64(tcp, tcp->u_arg[1]);
966 }
967 return 0;
968#else
969 return printargs(tcp);
970#endif
971}
972
John Hughese2f6d872001-03-07 16:03:20 +0000973#ifdef linux
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000974# if !defined(IA64)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000975int
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000976sys_oldstat(tcp)
977struct tcb *tcp;
978{
979 if (entering(tcp)) {
980 printpath(tcp, tcp->u_arg[0]);
981 tprintf(", ");
982 } else {
983 printoldstat(tcp, tcp->u_arg[1]);
984 }
985 return 0;
986}
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000987# endif /* !IA64 */
988#endif /* linux */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000989
John Hughes70623be2001-03-08 13:59:00 +0000990#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000991int
992sys_fstat(tcp)
993struct tcb *tcp;
994{
995 if (entering(tcp))
996 tprintf("%ld, ", tcp->u_arg[0]);
997 else {
998 printstat(tcp, tcp->u_arg[1]);
999 }
1000 return 0;
1001}
John Hughesb8c9f772001-03-07 16:53:07 +00001002#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001003
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001004int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001005sys_fstat64(tcp)
1006struct tcb *tcp;
1007{
1008#ifdef HAVE_STAT64
1009 if (entering(tcp))
1010 tprintf("%ld, ", tcp->u_arg[0]);
1011 else {
1012 printstat64(tcp, tcp->u_arg[1]);
1013 }
1014 return 0;
1015#else
1016 return printargs(tcp);
1017#endif
1018}
1019
John Hughese2f6d872001-03-07 16:03:20 +00001020#ifdef linux
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001021# if !defined(IA64)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001022int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001023sys_oldfstat(tcp)
1024struct tcb *tcp;
1025{
1026 if (entering(tcp))
1027 tprintf("%ld, ", tcp->u_arg[0]);
1028 else {
1029 printoldstat(tcp, tcp->u_arg[1]);
1030 }
1031 return 0;
1032}
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001033# endif /* !IA64 */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001034#endif
1035
John Hughes70623be2001-03-08 13:59:00 +00001036#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001037int
1038sys_lstat(tcp)
1039struct tcb *tcp;
1040{
1041 if (entering(tcp)) {
1042 printpath(tcp, tcp->u_arg[0]);
1043 tprintf(", ");
1044 } else {
1045 printstat(tcp, tcp->u_arg[1]);
1046 }
1047 return 0;
1048}
John Hughesb8c9f772001-03-07 16:53:07 +00001049#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001050
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001051int
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001052sys_lstat64(tcp)
1053struct tcb *tcp;
1054{
1055#ifdef HAVE_STAT64
1056 if (entering(tcp)) {
1057 printpath(tcp, tcp->u_arg[0]);
1058 tprintf(", ");
1059 } else {
1060 printstat64(tcp, tcp->u_arg[1]);
1061 }
1062 return 0;
1063#else
1064 return printargs(tcp);
1065#endif
1066}
1067
John Hughese2f6d872001-03-07 16:03:20 +00001068#ifdef linux
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001069# if !defined(IA64)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001070int
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001071sys_oldlstat(tcp)
1072struct tcb *tcp;
1073{
1074 if (entering(tcp)) {
1075 printpath(tcp, tcp->u_arg[0]);
1076 tprintf(", ");
1077 } else {
1078 printoldstat(tcp, tcp->u_arg[1]);
1079 }
1080 return 0;
1081}
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +00001082# endif /* !IA64 */
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001083#endif
1084
1085
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001086#if defined(SVR4) || defined(LINUXSPARC)
1087
1088int
1089sys_xstat(tcp)
1090struct tcb *tcp;
1091{
1092 if (entering(tcp)) {
1093 tprintf("%ld, ", tcp->u_arg[0]);
1094 printpath(tcp, tcp->u_arg[1]);
1095 tprintf(", ");
1096 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001097#ifdef _STAT64_VER
1098 if (tcp->u_arg[0] == _STAT64_VER)
1099 printstat64 (tcp, tcp->u_arg[2]);
1100 else
1101#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001102 printstat(tcp, tcp->u_arg[2]);
1103 }
1104 return 0;
1105}
1106
1107int
1108sys_fxstat(tcp)
1109struct tcb *tcp;
1110{
1111 if (entering(tcp))
1112 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1113 else {
John Hughes8fe2c982001-03-06 09:45:18 +00001114#ifdef _STAT64_VER
1115 if (tcp->u_arg[0] == _STAT64_VER)
1116 printstat64 (tcp, tcp->u_arg[2]);
1117 else
1118#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001119 printstat(tcp, tcp->u_arg[2]);
1120 }
1121 return 0;
1122}
1123
1124int
1125sys_lxstat(tcp)
1126struct tcb *tcp;
1127{
1128 if (entering(tcp)) {
1129 tprintf("%ld, ", tcp->u_arg[0]);
1130 printpath(tcp, tcp->u_arg[1]);
1131 tprintf(", ");
1132 } else {
John Hughes8fe2c982001-03-06 09:45:18 +00001133#ifdef _STAT64_VER
1134 if (tcp->u_arg[0] == _STAT64_VER)
1135 printstat64 (tcp, tcp->u_arg[2]);
1136 else
1137#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001138 printstat(tcp, tcp->u_arg[2]);
1139 }
1140 return 0;
1141}
1142
1143int
1144sys_xmknod(tcp)
1145struct tcb *tcp;
1146{
1147 int mode = tcp->u_arg[2];
1148
1149 if (entering(tcp)) {
1150 tprintf("%ld, ", tcp->u_arg[0]);
1151 printpath(tcp, tcp->u_arg[1]);
1152 tprintf(", %s", sprintmode(mode));
1153 switch (mode & S_IFMT) {
1154 case S_IFCHR: case S_IFBLK:
1155#ifdef LINUXSPARC
1156 tprintf(", makedev(%lu, %lu)",
1157 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1158 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1159#else
1160 tprintf(", makedev(%lu, %lu)",
1161 (unsigned long) major(tcp->u_arg[3]),
1162 (unsigned long) minor(tcp->u_arg[3]));
1163#endif
1164 break;
1165 default:
1166 break;
1167 }
1168 }
1169 return 0;
1170}
1171
Wichert Akkerman8829a551999-06-11 13:18:40 +00001172#ifdef HAVE_SYS_ACL_H
1173
1174#include <sys/acl.h>
1175
1176struct xlat aclcmds[] = {
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001177#ifdef SETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001178 { SETACL, "SETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001179#endif
1180#ifdef GETACL
Wichert Akkerman8829a551999-06-11 13:18:40 +00001181 { GETACL, "GETACL" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001182#endif
1183#ifdef GETACLCNT
Wichert Akkerman8829a551999-06-11 13:18:40 +00001184 { GETACLCNT, "GETACLCNT" },
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001185#endif
1186#ifdef ACL_GET
1187 { ACL_GET, "ACL_GET" },
1188#endif
1189#ifdef ACL_SET
1190 { ACL_SET, "ACL_SET" },
1191#endif
1192#ifdef ACL_CNT
1193 { ACL_CNT, "ACL_CNT" },
1194#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +00001195 { 0, NULL },
1196};
1197
1198int
1199sys_acl(tcp)
1200struct tcb *tcp;
1201{
1202 if (entering(tcp)) {
1203 printpath(tcp, tcp->u_arg[0]);
1204 tprintf(", ");
1205 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1206 tprintf(", %ld", tcp->u_arg[2]);
1207 /*
1208 * FIXME - dump out the list of aclent_t's pointed to
1209 * by "tcp->u_arg[3]" if it's not NULL.
1210 */
1211 if (tcp->u_arg[3])
1212 tprintf(", %#lx", tcp->u_arg[3]);
1213 else
1214 tprintf(", NULL");
1215 }
1216 return 0;
1217}
1218
1219
1220int
1221sys_facl(tcp)
1222struct tcb *tcp;
1223{
1224 if (entering(tcp)) {
1225 tprintf("%ld, ", tcp->u_arg[0]);
1226 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1227 tprintf(", %ld", tcp->u_arg[2]);
1228 /*
1229 * FIXME - dump out the list of aclent_t's pointed to
1230 * by "tcp->u_arg[3]" if it's not NULL.
1231 */
1232 if (tcp->u_arg[3])
1233 tprintf(", %#lx", tcp->u_arg[3]);
1234 else
1235 tprintf(", NULL");
1236 }
1237 return 0;
1238}
1239
Wichert Akkermane4aafd41999-11-26 09:54:08 +00001240
1241struct xlat aclipc[] = {
1242#ifdef IPC_SHM
1243 { IPC_SHM, "IPC_SHM" },
1244#endif
1245#ifdef IPC_SEM
1246 { IPC_SEM, "IPC_SEM" },
1247#endif
1248#ifdef IPC_MSG
1249 { IPC_MSG, "IPC_MSG" },
1250#endif
1251 { 0, NULL },
1252};
1253
1254
1255int
1256sys_aclipc(tcp)
1257struct tcb *tcp;
1258{
1259 if (entering(tcp)) {
1260 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1261 tprintf(", %#lx, ", tcp->u_arg[1]);
1262 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1263 tprintf(", %ld", tcp->u_arg[3]);
1264 /*
1265 * FIXME - dump out the list of aclent_t's pointed to
1266 * by "tcp->u_arg[4]" if it's not NULL.
1267 */
1268 if (tcp->u_arg[4])
1269 tprintf(", %#lx", tcp->u_arg[4]);
1270 else
1271 tprintf(", NULL");
1272 }
1273 return 0;
1274}
1275
1276
1277
Wichert Akkerman8829a551999-06-11 13:18:40 +00001278#endif /* HAVE_SYS_ACL_H */
1279
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001280#endif /* SVR4 || LINUXSPARC */
1281
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001282#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001283
1284static struct xlat fsmagic[] = {
Wichert Akkerman43a74822000-06-27 17:33:32 +00001285 { 0x73757245, "CODA_SUPER_MAGIC" },
1286 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1287 { 0x1373, "DEVFS_SUPER_MAGIC" },
1288 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1289 { 0x414A53, "EFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001290 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1291 { 0xef53, "EXT2_SUPER_MAGIC" },
1292 { 0x137d, "EXT_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001293 { 0xf995e849, "HPFS_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001294 { 0x9660, "ISOFS_SUPER_MAGIC" },
1295 { 0x137f, "MINIX_SUPER_MAGIC" },
1296 { 0x138f, "MINIX_SUPER_MAGIC2" },
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001297 { 0x2468, "MINIX2_SUPER_MAGIC" },
1298 { 0x2478, "MINIX2_SUPER_MAGIC2" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001299 { 0x4d44, "MSDOS_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001300 { 0x564c, "NCP_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001301 { 0x6969, "NFS_SUPER_MAGIC" },
1302 { 0x9fa0, "PROC_SUPER_MAGIC" },
Wichert Akkerman43a74822000-06-27 17:33:32 +00001303 { 0x002f, "QNX4_SUPER_MAGIC" },
1304 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1305 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1306 { 0x517b, "SMB_SUPER_MAGIC" },
1307 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1308 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1309 { 0x00011954, "UFS_MAGIC" },
1310 { 0x54190100, "UFS_CIGAM" },
1311 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001312 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
1313 { 0, NULL },
1314};
1315
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001316#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001317
1318#ifndef SVR4
1319
1320static char *
1321sprintfstype(magic)
1322int magic;
1323{
1324 static char buf[32];
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001325#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001326 char *s;
1327
1328 s = xlookup(fsmagic, magic);
1329 if (s) {
1330 sprintf(buf, "\"%s\"", s);
1331 return buf;
1332 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001333#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001334 sprintf(buf, "%#x", magic);
1335 return buf;
1336}
1337
1338static void
1339printstatfs(tcp, addr)
1340struct tcb *tcp;
1341long addr;
1342{
1343 struct statfs statbuf;
1344
1345 if (syserror(tcp) || !verbose(tcp)) {
1346 tprintf("%#lx", addr);
1347 return;
1348 }
1349 if (umove(tcp, addr, &statbuf) < 0) {
1350 tprintf("{...}");
1351 return;
1352 }
1353#ifdef ALPHA
1354
1355 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1356 sprintfstype(statbuf.f_type),
1357 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001358 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_namelen=%u",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001359 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree, statbuf.f_namelen);
1360#else /* !ALPHA */
1361 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1362 sprintfstype(statbuf.f_type),
Nate Sammons5c74d201999-04-06 01:37:51 +00001363 (unsigned long)statbuf.f_bsize,
1364 (unsigned long)statbuf.f_blocks,
1365 (unsigned long)statbuf.f_bfree);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001366 tprintf("f_files=%lu, f_ffree=%lu",
Nate Sammons5c74d201999-04-06 01:37:51 +00001367 (unsigned long)statbuf.f_files,
1368 (unsigned long)statbuf.f_ffree);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001369#ifdef linux
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00001370 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001371#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001372#endif /* !ALPHA */
1373 tprintf("}");
1374}
1375
1376int
1377sys_statfs(tcp)
1378struct tcb *tcp;
1379{
1380 if (entering(tcp)) {
1381 printpath(tcp, tcp->u_arg[0]);
1382 tprintf(", ");
1383 } else {
1384 printstatfs(tcp, tcp->u_arg[1]);
1385 }
1386 return 0;
1387}
1388
1389int
1390sys_fstatfs(tcp)
1391struct tcb *tcp;
1392{
1393 if (entering(tcp)) {
1394 tprintf("%lu, ", tcp->u_arg[0]);
1395 } else {
1396 printstatfs(tcp, tcp->u_arg[1]);
1397 }
1398 return 0;
1399}
1400
Wichert Akkermana0f36c61999-04-16 14:01:34 +00001401#if defined(linux) && defined(__alpha)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001402
1403int
1404osf_statfs(tcp)
1405struct tcb *tcp;
1406{
1407 if (entering(tcp)) {
1408 printpath(tcp, tcp->u_arg[0]);
1409 tprintf(", ");
1410 } else {
1411 printstatfs(tcp, tcp->u_arg[1]);
1412 tprintf(", %lu", tcp->u_arg[2]);
1413 }
1414 return 0;
1415}
1416
1417int
1418osf_fstatfs(tcp)
1419struct tcb *tcp;
1420{
1421 if (entering(tcp)) {
1422 tprintf("%lu, ", tcp->u_arg[0]);
1423 } else {
1424 printstatfs(tcp, tcp->u_arg[1]);
1425 tprintf(", %lu", tcp->u_arg[2]);
1426 }
1427 return 0;
1428}
Wichert Akkermana0f36c61999-04-16 14:01:34 +00001429#endif /* linux && __alpha */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001430
1431#endif /* !SVR4 */
1432
1433#ifdef SUNOS4
1434
1435int
1436sys_ustat(tcp)
1437struct tcb *tcp;
1438{
1439 struct ustat statbuf;
1440
1441 if (entering(tcp)) {
1442 tprintf("makedev(%lu, %lu), ",
1443 (long) major(tcp->u_arg[0]),
1444 (long) minor(tcp->u_arg[0]));
1445 }
1446 else {
1447 if (syserror(tcp) || !verbose(tcp))
1448 tprintf("%#lx", tcp->u_arg[1]);
1449 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1450 tprintf("{...}");
1451 else {
1452 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1453 statbuf.f_tfree, statbuf.f_tinode);
1454 tprintf("f_fname=\"%.*s\", ",
1455 (int) sizeof(statbuf.f_fname),
1456 statbuf.f_fname);
1457 tprintf("f_fpack=\"%.*s\"}",
1458 (int) sizeof(statbuf.f_fpack),
1459 statbuf.f_fpack);
1460 }
1461 }
1462 return 0;
1463}
1464
1465#endif /* SUNOS4 */
1466
Wichert Akkermanc7926982000-04-10 22:22:31 +00001467int
1468sys_pivotroot(tcp)
1469struct tcb *tcp;
1470{
1471 if (entering(tcp)) {
1472 printpath(tcp, tcp->u_arg[0]);
1473 tprintf(", ");
1474 printpath(tcp, tcp->u_arg[1]);
1475 }
1476 return 0;
1477}
1478
1479
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001480/* directory */
1481int
1482sys_chdir(tcp)
1483struct tcb *tcp;
1484{
1485 if (entering(tcp)) {
1486 printpath(tcp, tcp->u_arg[0]);
1487 }
1488 return 0;
1489}
1490
1491int
1492sys_mkdir(tcp)
1493struct tcb *tcp;
1494{
1495 if (entering(tcp)) {
1496 printpath(tcp, tcp->u_arg[0]);
1497 tprintf(", %#lo", tcp->u_arg[1]);
1498 }
1499 return 0;
1500}
1501
1502int
1503sys_rmdir(tcp)
1504struct tcb *tcp;
1505{
1506 if (entering(tcp)) {
1507 printpath(tcp, tcp->u_arg[0]);
1508 }
1509 return 0;
1510}
1511
1512int
1513sys_fchdir(tcp)
1514struct tcb *tcp;
1515{
1516 if (entering(tcp)) {
1517 tprintf("%ld", tcp->u_arg[0]);
1518 }
1519 return 0;
1520}
1521
1522int
1523sys_chroot(tcp)
1524struct tcb *tcp;
1525{
1526 if (entering(tcp)) {
1527 printpath(tcp, tcp->u_arg[0]);
1528 }
1529 return 0;
1530}
1531
1532int
1533sys_fchroot(tcp)
1534struct tcb *tcp;
1535{
1536 if (entering(tcp)) {
1537 tprintf("%ld", tcp->u_arg[0]);
1538 }
1539 return 0;
1540}
1541
1542int
1543sys_link(tcp)
1544struct tcb *tcp;
1545{
1546 if (entering(tcp)) {
1547 printpath(tcp, tcp->u_arg[0]);
1548 tprintf(", ");
1549 printpath(tcp, tcp->u_arg[1]);
1550 }
1551 return 0;
1552}
1553
1554int
1555sys_unlink(tcp)
1556struct tcb *tcp;
1557{
1558 if (entering(tcp)) {
1559 printpath(tcp, tcp->u_arg[0]);
1560 }
1561 return 0;
1562}
1563
1564int
1565sys_symlink(tcp)
1566struct tcb *tcp;
1567{
1568 if (entering(tcp)) {
1569 printpath(tcp, tcp->u_arg[0]);
1570 tprintf(", ");
1571 printpath(tcp, tcp->u_arg[1]);
1572 }
1573 return 0;
1574}
1575
1576int
1577sys_readlink(tcp)
1578struct tcb *tcp;
1579{
1580 if (entering(tcp)) {
1581 printpath(tcp, tcp->u_arg[0]);
1582 tprintf(", ");
1583 } else {
1584 if (syserror(tcp))
1585 tprintf("%#lx", tcp->u_arg[1]);
1586 else
1587 printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
1588 tprintf(", %lu", tcp->u_arg[2]);
1589 }
1590 return 0;
1591}
1592
1593int
1594sys_rename(tcp)
1595struct tcb *tcp;
1596{
1597 if (entering(tcp)) {
1598 printpath(tcp, tcp->u_arg[0]);
1599 tprintf(", ");
1600 printpath(tcp, tcp->u_arg[1]);
1601 }
1602 return 0;
1603}
1604
1605int
1606sys_chown(tcp)
1607struct tcb *tcp;
1608{
1609 if (entering(tcp)) {
1610 printpath(tcp, tcp->u_arg[0]);
1611 tprintf(", %lu, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1612 }
1613 return 0;
1614}
1615
1616int
1617sys_fchown(tcp)
1618struct tcb *tcp;
1619{
1620 if (entering(tcp)) {
1621 tprintf("%ld, %lu, %lu",
1622 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1623 }
1624 return 0;
1625}
1626
1627int
1628sys_chmod(tcp)
1629struct tcb *tcp;
1630{
1631 if (entering(tcp)) {
1632 printpath(tcp, tcp->u_arg[0]);
1633 tprintf(", %#lo", tcp->u_arg[1]);
1634 }
1635 return 0;
1636}
1637
1638int
1639sys_fchmod(tcp)
1640struct tcb *tcp;
1641{
1642 if (entering(tcp)) {
1643 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
1644 }
1645 return 0;
1646}
1647
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +00001648#ifdef ALPHA
1649int
1650sys_osf_utimes(tcp)
1651struct tcb *tcp;
1652{
1653 if (entering(tcp)) {
1654 printpath(tcp, tcp->u_arg[0]);
1655 tprintf(", ");
1656 printtv32(tcp, tcp->u_arg[1]);
1657 }
1658 return 0;
1659}
1660#endif
1661
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001662int
1663sys_utimes(tcp)
1664struct tcb *tcp;
1665{
1666 if (entering(tcp)) {
1667 printpath(tcp, tcp->u_arg[0]);
1668 tprintf(", ");
1669 printtv(tcp, tcp->u_arg[1]);
1670 }
1671 return 0;
1672}
1673
1674int
1675sys_utime(tcp)
1676struct tcb *tcp;
1677{
1678 long ut[2];
1679
1680 if (entering(tcp)) {
1681 printpath(tcp, tcp->u_arg[0]);
1682 tprintf(", ");
1683 if (!tcp->u_arg[1])
1684 tprintf("NULL");
1685 else if (!verbose(tcp))
1686 tprintf("%#lx", tcp->u_arg[1]);
1687 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
1688 (char *) ut) < 0)
1689 tprintf("[?, ?]");
1690 else {
1691 tprintf("[%s,", sprinttime(ut[0]));
1692 tprintf(" %s]", sprinttime(ut[1]));
1693 }
1694 }
1695 return 0;
1696}
1697
1698int
1699sys_mknod(tcp)
1700struct tcb *tcp;
1701{
1702 int mode = tcp->u_arg[1];
1703
1704 if (entering(tcp)) {
1705 printpath(tcp, tcp->u_arg[0]);
1706 tprintf(", %s", sprintmode(mode));
1707 switch (mode & S_IFMT) {
1708 case S_IFCHR: case S_IFBLK:
1709#ifdef LINUXSPARC
1710 if (current_personality == 1)
1711 tprintf(", makedev(%lu, %lu)",
1712 (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
1713 (unsigned long) (tcp->u_arg[2] & 0x3ffff));
1714 else
1715#endif
1716 tprintf(", makedev(%lu, %lu)",
1717 (unsigned long) major(tcp->u_arg[2]),
1718 (unsigned long) minor(tcp->u_arg[2]));
1719 break;
1720 default:
1721 break;
1722 }
1723 }
1724 return 0;
1725}
1726
1727int
1728sys_mkfifo(tcp)
1729struct tcb *tcp;
1730{
1731 if (entering(tcp)) {
1732 printpath(tcp, tcp->u_arg[0]);
1733 tprintf(", %#lo", tcp->u_arg[1]);
1734 }
1735 return 0;
1736}
1737
1738int
1739sys_fsync(tcp)
1740struct tcb *tcp;
1741{
1742 if (entering(tcp)) {
1743 tprintf("%ld", tcp->u_arg[0]);
1744 }
1745 return 0;
1746}
1747
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001748#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001749
1750static void
1751printdir(tcp, addr)
1752struct tcb *tcp;
1753long addr;
1754{
1755 struct dirent d;
1756
1757 if (!verbose(tcp)) {
1758 tprintf("%#lx", addr);
1759 return;
1760 }
1761 if (umove(tcp, addr, &d) < 0) {
1762 tprintf("{...}");
1763 return;
1764 }
1765 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001766 tprintf("d_name=");
1767 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
1768 tprintf("}");
1769}
1770
1771int
1772sys_readdir(tcp)
1773struct tcb *tcp;
1774{
1775 if (entering(tcp)) {
1776 tprintf("%lu, ", tcp->u_arg[0]);
1777 } else {
1778 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
1779 tprintf("%#lx", tcp->u_arg[1]);
1780 else
1781 printdir(tcp, tcp->u_arg[1]);
1782 /* Not much point in printing this out, it is always 1. */
1783 if (tcp->u_arg[2] != 1)
1784 tprintf(", %lu", tcp->u_arg[2]);
1785 }
1786 return 0;
1787}
1788
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001789#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001790
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001791#ifdef FREEBSD
1792struct xlat direnttypes[] = {
1793 { DT_FIFO, "DT_FIFO" },
1794 { DT_CHR, "DT_CHR" },
1795 { DT_DIR, "DT_DIR" },
1796 { DT_BLK, "DT_BLK" },
1797 { DT_REG, "DT_REG" },
1798 { DT_LNK, "DT_LNK" },
1799 { DT_SOCK, "DT_SOCK" },
1800 { DT_WHT, "DT_WHT" },
1801 { 0, NULL },
1802};
1803
1804#endif
1805
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001806int
1807sys_getdents(tcp)
1808struct tcb *tcp;
1809{
1810 int i, len, dents = 0;
1811 char *buf;
1812
1813 if (entering(tcp)) {
1814 tprintf("%lu, ", tcp->u_arg[0]);
1815 return 0;
1816 }
1817 if (syserror(tcp) || !verbose(tcp)) {
1818 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1819 return 0;
1820 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001821 len = tcp->u_rval;
1822 if ((buf = malloc(len)) == NULL) {
1823 tprintf("out of memory\n");
1824 return 0;
1825 }
1826 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1827 tprintf("{...}, %lu", tcp->u_arg[2]);
1828 free(buf);
1829 return 0;
1830 }
1831 if (!abbrev(tcp))
1832 tprintf("{");
1833 for (i = 0; i < len;) {
Wichert Akkerman9524bb91999-05-25 23:11:18 +00001834 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001835#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001836 if (!abbrev(tcp)) {
1837 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1838 i ? " " : "", d->d_ino, d->d_off);
1839 tprintf("d_reclen=%u, d_name=\"%s\"}",
1840 d->d_reclen, d->d_name);
1841 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001842#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001843#ifdef SVR4
1844 if (!abbrev(tcp)) {
1845 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1846 i ? " " : "", d->d_ino, d->d_off);
1847 tprintf("d_reclen=%u, d_name=\"%s\"}",
1848 d->d_reclen, d->d_name);
1849 }
1850#endif /* SVR4 */
1851#ifdef SUNOS4
1852 if (!abbrev(tcp)) {
1853 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
1854 i ? " " : "", d->d_off, d->d_fileno,
1855 d->d_reclen);
1856 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
1857 d->d_namlen, d->d_namlen, d->d_name);
1858 }
1859#endif /* SUNOS4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001860#ifdef FREEBSD
1861 if (!abbrev(tcp)) {
1862 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
1863 i ? " " : "", d->d_fileno, d->d_reclen);
1864 printxval(direnttypes, d->d_type, "DT_???");
1865 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
1866 d->d_namlen, d->d_namlen, d->d_name);
1867 }
1868#endif /* FREEBSD */
Pavel Machek9a9f10b2000-02-01 16:22:52 +00001869 if (!d->d_reclen) {
1870 tprintf("/* d_reclen == 0, problem here */");
1871 break;
1872 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001873 i += d->d_reclen;
1874 dents++;
1875 }
1876 if (!abbrev(tcp))
1877 tprintf("}");
1878 else
1879 tprintf("/* %u entries */", dents);
1880 tprintf(", %lu", tcp->u_arg[2]);
1881 free(buf);
1882 return 0;
1883}
1884
John Hughesbdf48f52001-03-06 15:08:09 +00001885
1886#if _LFS64_LARGEFILE
1887int
1888sys_getdents64(tcp)
1889struct tcb *tcp;
1890{
1891 int i, len, dents = 0;
1892 char *buf;
1893
1894 if (entering(tcp)) {
1895 tprintf("%lu, ", tcp->u_arg[0]);
1896 return 0;
1897 }
1898 if (syserror(tcp) || !verbose(tcp)) {
1899 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1900 return 0;
1901 }
1902 len = tcp->u_rval;
1903 if ((buf = malloc(len)) == NULL) {
1904 tprintf("out of memory\n");
1905 return 0;
1906 }
1907 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1908 tprintf("{...}, %lu", tcp->u_arg[2]);
1909 free(buf);
1910 return 0;
1911 }
1912 if (!abbrev(tcp))
1913 tprintf("{");
1914 for (i = 0; i < len;) {
1915 struct dirent64 *d = (struct dirent64 *) &buf[i];
1916#ifdef linux
1917 if (!abbrev(tcp)) {
1918 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1919 i ? " " : "", d->d_ino, d->d_off);
1920 tprintf("d_reclen=%u, d_name=\"%s\"}",
1921 d->d_reclen, d->d_name);
1922 }
1923#endif /* linux */
1924#ifdef SVR4
1925 if (!abbrev(tcp)) {
1926 tprintf("%s{d_ino=%llu, d_off=%llu, ",
1927 i ? " " : "", d->d_ino, d->d_off);
1928 tprintf("d_reclen=%u, d_name=\"%s\"}",
1929 d->d_reclen, d->d_name);
1930 }
1931#endif /* SVR4 */
1932#ifdef SUNOS4
1933 if (!abbrev(tcp)) {
1934 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
1935 i ? " " : "", d->d_off, d->d_fileno,
1936 d->d_reclen);
1937 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
1938 d->d_namlen, d->d_namlen, d->d_name);
1939 }
1940#endif /* SUNOS4 */
1941 i += d->d_reclen;
1942 dents++;
1943 }
1944 if (!abbrev(tcp))
1945 tprintf("}");
1946 else
1947 tprintf("/* %u entries */", dents);
1948 tprintf(", %lu", tcp->u_arg[2]);
1949 free(buf);
1950 return 0;
1951}
1952#endif
1953
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001954#ifdef FREEBSD
1955int
1956sys_getdirentries(tcp)
1957struct tcb * tcp;
1958{
1959 int i, len, dents = 0;
1960 long basep;
1961 char *buf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001962
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001963 if (entering(tcp)) {
1964 tprintf("%lu, ", tcp->u_arg[0]);
1965 return 0;
1966 }
1967 if (syserror(tcp) || !verbose(tcp)) {
1968 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
1969 return 0;
1970 }
1971 len = tcp->u_rval;
1972 if ((buf = malloc(len)) == NULL) {
1973 tprintf("out of memory\n");
1974 return 0;
1975 }
1976 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1977 tprintf("{...}, %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3]);
1978 free(buf);
1979 return 0;
1980 }
1981 if (!abbrev(tcp))
1982 tprintf("{");
1983 for (i = 0; i < len;) {
1984 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
1985 if (!abbrev(tcp)) {
1986 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
1987 i ? " " : "", d->d_fileno, d->d_reclen);
1988 printxval(direnttypes, d->d_type, "DT_???");
1989 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
1990 d->d_namlen, d->d_namlen, d->d_name);
1991 }
1992 i += d->d_reclen;
1993 dents++;
1994 }
1995 if (!abbrev(tcp))
1996 tprintf("}");
1997 else
1998 tprintf("/* %u entries */", dents);
1999 free(buf);
2000 tprintf(", %lu", tcp->u_arg[2]);
2001 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2002 tprintf(", %#lx", tcp->u_arg[3]);
2003 else
2004 tprintf(", [%lu]", basep);
2005 return 0;
2006}
2007#endif
2008
2009#ifdef linux
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002010int
2011sys_getcwd(tcp)
2012struct tcb *tcp;
2013{
2014 if (exiting(tcp)) {
2015 if (syserror(tcp))
2016 tprintf("%#lx", tcp->u_arg[0]);
2017 else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00002018 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002019 tprintf(", %lu", tcp->u_arg[1]);
2020 }
2021 return 0;
2022}
Wichert Akkerman328c5e71999-04-16 00:21:26 +00002023#endif /* linux */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002024
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00002025#ifdef FREEBSD
2026int
2027sys___getcwd(tcp)
2028struct tcb *tcp;
2029{
2030 if (exiting(tcp)) {
2031 if (syserror(tcp))
2032 tprintf("%#lx", tcp->u_arg[0]);
2033 else
2034 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2035 tprintf(", %lu", tcp->u_arg[1]);
2036 }
2037 return 0;
2038}
2039#endif
2040
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00002041#ifdef HAVE_SYS_ASYNCH_H
2042
2043int
2044sys_aioread(tcp)
2045struct tcb *tcp;
2046{
2047 struct aio_result_t res;
2048
2049 if (entering(tcp)) {
2050 tprintf("%lu, ", tcp->u_arg[0]);
2051 } else {
2052 if (syserror(tcp))
2053 tprintf("%#lx", tcp->u_arg[1]);
2054 else
2055 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2056 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2057 printxval(whence, tcp->u_arg[4], "L_???");
2058 if (syserror(tcp) || tcp->u_arg[5] == 0
2059 || umove(tcp, tcp->u_arg[5], &res) < 0)
2060 tprintf(", %#lx", tcp->u_arg[5]);
2061 else
2062 tprintf(", {aio_return %d aio_errno %d}",
2063 res.aio_return, res.aio_errno);
2064 }
2065 return 0;
2066}
2067
2068int
2069sys_aiowrite(tcp)
2070struct tcb *tcp;
2071{
2072 struct aio_result_t res;
2073
2074 if (entering(tcp)) {
2075 tprintf("%lu, ", tcp->u_arg[0]);
2076 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2077 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2078 printxval(whence, tcp->u_arg[4], "L_???");
2079 }
2080 else {
2081 if (tcp->u_arg[5] == 0)
2082 tprintf(", NULL");
2083 else if (syserror(tcp)
2084 || umove(tcp, tcp->u_arg[5], &res) < 0)
2085 tprintf(", %#lx", tcp->u_arg[5]);
2086 else
2087 tprintf(", {aio_return %d aio_errno %d}",
2088 res.aio_return, res.aio_errno);
2089 }
2090 return 0;
2091}
2092
2093int
2094sys_aiowait(tcp)
2095struct tcb *tcp;
2096{
2097 if (entering(tcp))
2098 printtv(tcp, tcp->u_arg[0]);
2099 return 0;
2100}
2101
2102int
2103sys_aiocancel(tcp)
2104struct tcb *tcp;
2105{
2106 struct aio_result_t res;
2107
2108 if (exiting(tcp)) {
2109 if (tcp->u_arg[0] == 0)
2110 tprintf("NULL");
2111 else if (syserror(tcp)
2112 || umove(tcp, tcp->u_arg[0], &res) < 0)
2113 tprintf("%#lx", tcp->u_arg[0]);
2114 else
2115 tprintf("{aio_return %d aio_errno %d}",
2116 res.aio_return, res.aio_errno);
2117 }
2118 return 0;
2119}
2120
2121#endif /* HAVE_SYS_ASYNCH_H */