blob: ad85ef00d23460e0fdbcc5f60ea42681a12d4f8f [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.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Roland McGrathc531e572008-08-01 01:13:10 +000032
Denys Vlasenko9472a272013-02-12 11:43:46 +010033#if defined(SPARC) || defined(SPARC64)
Wichert Akkermandacfb6e1999-06-03 14:21:07 +000034struct stat {
35 unsigned short st_dev;
36 unsigned int st_ino;
37 unsigned short st_mode;
38 short st_nlink;
39 unsigned short st_uid;
40 unsigned short st_gid;
41 unsigned short st_rdev;
42 unsigned int st_size;
43 int st_atime;
44 unsigned int __unused1;
45 int st_mtime;
46 unsigned int __unused2;
47 int st_ctime;
48 unsigned int __unused3;
49 int st_blksize;
50 int st_blocks;
51 unsigned int __unused4[2];
52};
Denys Vlasenko84703742012-02-25 02:38:52 +010053# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +000054struct stat_sparc64 {
55 unsigned int st_dev;
56 unsigned long st_ino;
57 unsigned int st_mode;
58 unsigned int st_nlink;
59 unsigned int st_uid;
60 unsigned int st_gid;
61 unsigned int st_rdev;
62 long st_size;
63 long st_atime;
64 long st_mtime;
65 long st_ctime;
66 long st_blksize;
67 long st_blocks;
68 unsigned long __unused4[2];
69};
Denys Vlasenko84703742012-02-25 02:38:52 +010070# endif /* SPARC64 */
71# define stat kernel_stat
72# include <asm/stat.h>
73# undef stat
H.J. Lu35be5812012-04-16 13:00:01 +020074#elif defined(X32)
75struct stat {
76 unsigned long long st_dev;
77 unsigned long long st_ino;
78 unsigned long long st_nlink;
79
80 unsigned int st_mode;
81 unsigned int st_uid;
82 unsigned int st_gid;
83 unsigned int __pad0;
84 unsigned long long st_rdev;
85 long long st_size;
86 long long st_blksize;
87 long long st_blocks;
88
89 unsigned long long st_atime;
90 unsigned long long st_atime_nsec;
91 unsigned long long st_mtime;
92 unsigned long long st_mtime_nsec;
93 unsigned long long st_ctime;
94 unsigned long long st_ctime_nsec;
95 long long __unused[3];
96};
H.J. Lu085e4282012-04-17 11:05:04 -070097
98struct stat64 {
99 unsigned long long st_dev;
100 unsigned char __pad0[4];
101 unsigned long __st_ino;
102 unsigned int st_mode;
103 unsigned int st_nlink;
104 unsigned long st_uid;
105 unsigned long st_gid;
106 unsigned long long st_rdev;
107 unsigned char __pad3[4];
108 long long st_size;
109 unsigned long st_blksize;
110 unsigned long long st_blocks;
111 unsigned long st_atime;
112 unsigned long st_atime_nsec;
113 unsigned long st_mtime;
114 unsigned int st_mtime_nsec;
115 unsigned long st_ctime;
116 unsigned long st_ctime_nsec;
117 unsigned long long st_ino;
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000118} __attribute__((packed));
119# define HAVE_STAT64 1
Dmitry V. Levinbd2e28a2013-05-01 15:14:25 +0000120
121struct __old_kernel_stat {
122 unsigned short st_dev;
123 unsigned short st_ino;
124 unsigned short st_mode;
125 unsigned short st_nlink;
126 unsigned short st_uid;
127 unsigned short st_gid;
128 unsigned short st_rdev;
129 unsigned int st_size;
130 unsigned int st_atime;
131 unsigned int st_mtime;
132 unsigned int st_ctime;
133};
Denys Vlasenko84703742012-02-25 02:38:52 +0100134#else
135# undef dev_t
136# undef ino_t
137# undef mode_t
138# undef nlink_t
139# undef uid_t
140# undef gid_t
141# undef off_t
142# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100143# define dev_t __kernel_dev_t
144# define ino_t __kernel_ino_t
145# define mode_t __kernel_mode_t
146# define nlink_t __kernel_nlink_t
147# define uid_t __kernel_uid_t
148# define gid_t __kernel_gid_t
149# define off_t __kernel_off_t
150# define loff_t __kernel_loff_t
Wichert Akkermana6013701999-07-08 14:00:58 +0000151
Denys Vlasenko84703742012-02-25 02:38:52 +0100152# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +0000153
Denys Vlasenko84703742012-02-25 02:38:52 +0100154# undef dev_t
155# undef ino_t
156# undef mode_t
157# undef nlink_t
158# undef uid_t
159# undef gid_t
160# undef off_t
161# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100162# define dev_t dev_t
163# define ino_t ino_t
164# define mode_t mode_t
165# define nlink_t nlink_t
166# define uid_t uid_t
167# define gid_t gid_t
168# define off_t off_t
169# define loff_t loff_t
170#endif
171
Denys Vlasenko84703742012-02-25 02:38:52 +0100172#define stat libc_stat
173#define stat64 libc_stat64
174#include <sys/stat.h>
175#undef stat
176#undef stat64
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100177/* These might be macros. */
Denys Vlasenko84703742012-02-25 02:38:52 +0100178#undef st_atime
179#undef st_mtime
180#undef st_ctime
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000181
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000182#include <fcntl.h>
Roland McGrath186c5ac2002-12-15 23:58:23 +0000183
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000184#ifdef MAJOR_IN_SYSMACROS
Denys Vlasenko84703742012-02-25 02:38:52 +0100185# include <sys/sysmacros.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186#endif
187
188#ifdef MAJOR_IN_MKDEV
Denys Vlasenko84703742012-02-25 02:38:52 +0100189# include <sys/mkdev.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000190#endif
191
Dmitry V. Levin63ebcfc2014-04-26 15:35:02 +0000192#ifdef O_LARGEFILE
193# if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
194# undef O_LARGEFILE
195# ifdef SPARC64
196# define O_LARGEFILE 0x40000
197# elif defined X86_64 || defined S390X
198# define O_LARGEFILE 0100000
199# endif
200# endif
201#endif
202
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000203#include "xlat/open_access_modes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000204#include "xlat/open_mode_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000205
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000206#ifndef AT_FDCWD
207# define AT_FDCWD -100
208#endif
209
Denys Vlasenkoe740fd32009-04-16 12:06:16 +0000210/* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
211 * extension to get the right value. We do this by declaring fd as int here.
212 */
Dmitry V. Levin99db95d2014-02-05 04:13:18 +0000213void
Dmitry V. Levin31382132011-03-04 05:08:02 +0300214print_dirfd(struct tcb *tcp, int fd)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000215{
216 if (fd == AT_FDCWD)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200217 tprints("AT_FDCWD, ");
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200218 else {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300219 printfd(tcp, fd);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200220 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300221 }
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000222}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000223
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000224/*
225 * low bits of the open(2) flags define access mode,
226 * other bits are real flags.
227 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000228const char *
Elliott Hughes22e34b92014-09-23 19:09:50 -0700229sprint_open_modes(int flags)
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000230{
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100231 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000232 char *p;
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100233 char sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000234 const char *str;
235 const struct xlat *x;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000236
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100237 sep = ' ';
238 p = stpcpy(outstr, "flags");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000239 str = xlookup(open_access_modes, flags & 3);
240 if (str) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100241 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200242 p = stpcpy(p, str);
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000243 flags &= ~3;
244 if (!flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000245 return outstr;
246 sep = '|';
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000247 }
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000248
249 for (x = open_mode_flags; x->str; x++) {
250 if ((flags & x->val) == x->val) {
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100251 *p++ = sep;
Denys Vlasenko52845572011-08-31 12:07:38 +0200252 p = stpcpy(p, x->str);
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000253 flags &= ~x->val;
254 if (!flags)
255 return outstr;
256 sep = '|';
257 }
258 }
259 /* flags is still nonzero */
Denys Vlasenko4f3df072012-01-29 22:38:35 +0100260 *p++ = sep;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000261 sprintf(p, "%#x", flags);
262 return outstr;
263}
264
265void
Elliott Hughes22e34b92014-09-23 19:09:50 -0700266tprint_open_modes(int flags)
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000267{
Denys Vlasenko5940e652011-09-01 09:55:05 +0200268 tprints(sprint_open_modes(flags) + sizeof("flags"));
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000269}
270
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000271static int
272decode_open(struct tcb *tcp, int offset)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000273{
274 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000275 printpath(tcp, tcp->u_arg[offset]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200276 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000277 /* flags */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000278 tprint_open_modes(tcp->u_arg[offset + 1]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000279 if (tcp->u_arg[offset + 1] & O_CREAT) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000280 /* mode */
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000281 tprintf(", %#lo", tcp->u_arg[offset + 2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000282 }
283 }
Zubin Mithra64aa1b12014-06-04 08:30:41 +0530284 return RVAL_FD;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000285}
286
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000287int
288sys_open(struct tcb *tcp)
289{
290 return decode_open(tcp, 0);
291}
292
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000293int
294sys_openat(struct tcb *tcp)
295{
296 if (entering(tcp))
Dmitry V. Levin31382132011-03-04 05:08:02 +0300297 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000298 return decode_open(tcp, 1);
299}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000300
Denys Vlasenko9472a272013-02-12 11:43:46 +0100301#if defined(SPARC) || defined(SPARC64)
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000302#include "xlat/openmodessol.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000303
304int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000305solaris_open(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000306{
307 if (entering(tcp)) {
308 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200309 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000310 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000311 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000312 if (tcp->u_arg[1] & 0x100) {
313 /* mode */
314 tprintf(", %#lo", tcp->u_arg[2]);
315 }
316 }
317 return 0;
318}
319
320#endif
321
322int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000323sys_creat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000324{
325 if (entering(tcp)) {
326 printpath(tcp, tcp->u_arg[0]);
327 tprintf(", %#lo", tcp->u_arg[1]);
328 }
Zubin Mithra64aa1b12014-06-04 08:30:41 +0530329 return RVAL_FD;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000330}
331
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000332/* several stats */
333
Denys Vlasenko9472a272013-02-12 11:43:46 +0100334#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000335typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000336 int tv_sec;
337 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000338} timestruct_t;
339
340struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000341 unsigned st_dev;
342 int st_pad1[3]; /* network id */
343 unsigned st_ino;
344 unsigned st_mode;
345 unsigned st_nlink;
346 unsigned st_uid;
347 unsigned st_gid;
348 unsigned st_rdev;
349 int st_pad2[2];
350 int st_size;
351 int st_pad3; /* st_size, off_t expansion */
352 timestruct_t st_atime;
353 timestruct_t st_mtime;
354 timestruct_t st_ctime;
355 int st_blksize;
356 int st_blocks;
357 char st_fstype[16];
358 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000359};
360
361static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000362printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000363{
364 struct solstat statbuf;
365
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000366 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200367 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000368 return;
369 }
370 if (!abbrev(tcp)) {
371 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
372 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
373 (unsigned long) (statbuf.st_dev & 0x3ffff),
374 (unsigned long) statbuf.st_ino,
375 sprintmode(statbuf.st_mode));
376 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
377 (unsigned long) statbuf.st_nlink,
378 (unsigned long) statbuf.st_uid,
379 (unsigned long) statbuf.st_gid);
380 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
381 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
382 }
383 else
384 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
385 switch (statbuf.st_mode & S_IFMT) {
386 case S_IFCHR: case S_IFBLK:
387 tprintf("st_rdev=makedev(%lu, %lu), ",
388 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
389 (unsigned long) (statbuf.st_rdev & 0x3ffff));
390 break;
391 default:
392 tprintf("st_size=%u, ", statbuf.st_size);
393 break;
394 }
395 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000396 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
397 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
398 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000399 }
400 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200401 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000402}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000403
Denys Vlasenko9472a272013-02-12 11:43:46 +0100404# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000405static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000406printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000407{
408 struct stat_sparc64 statbuf;
409
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000410 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200411 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000412 return;
413 }
414
415 if (!abbrev(tcp)) {
416 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
417 (unsigned long) major(statbuf.st_dev),
418 (unsigned long) minor(statbuf.st_dev),
419 (unsigned long) statbuf.st_ino,
420 sprintmode(statbuf.st_mode));
421 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
422 (unsigned long) statbuf.st_nlink,
423 (unsigned long) statbuf.st_uid,
424 (unsigned long) statbuf.st_gid);
425 tprintf("st_blksize=%lu, ",
426 (unsigned long) statbuf.st_blksize);
427 tprintf("st_blocks=%lu, ",
428 (unsigned long) statbuf.st_blocks);
429 }
430 else
431 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
432 switch (statbuf.st_mode & S_IFMT) {
433 case S_IFCHR: case S_IFBLK:
434 tprintf("st_rdev=makedev(%lu, %lu), ",
435 (unsigned long) major(statbuf.st_rdev),
436 (unsigned long) minor(statbuf.st_rdev));
437 break;
438 default:
439 tprintf("st_size=%lu, ", statbuf.st_size);
440 break;
441 }
442 if (!abbrev(tcp)) {
443 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
444 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100445 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000446 }
447 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200448 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000449}
Denys Vlasenko9472a272013-02-12 11:43:46 +0100450# endif /* SPARC64 */
451#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000452
Denys Vlasenko84703742012-02-25 02:38:52 +0100453#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200454struct stat_powerpc32 {
455 unsigned int st_dev;
456 unsigned int st_ino;
457 unsigned int st_mode;
458 unsigned short st_nlink;
459 unsigned int st_uid;
460 unsigned int st_gid;
461 unsigned int st_rdev;
462 unsigned int st_size;
463 unsigned int st_blksize;
464 unsigned int st_blocks;
465 unsigned int st_atime;
466 unsigned int st_atime_nsec;
467 unsigned int st_mtime;
468 unsigned int st_mtime_nsec;
469 unsigned int st_ctime;
470 unsigned int st_ctime_nsec;
471 unsigned int __unused4;
472 unsigned int __unused5;
473};
474
475static void
476printstat_powerpc32(struct tcb *tcp, long addr)
477{
478 struct stat_powerpc32 statbuf;
479
480 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200481 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200482 return;
483 }
484
485 if (!abbrev(tcp)) {
486 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
487 major(statbuf.st_dev), minor(statbuf.st_dev),
488 statbuf.st_ino,
489 sprintmode(statbuf.st_mode));
490 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
491 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
492 tprintf("st_blksize=%u, ", statbuf.st_blksize);
493 tprintf("st_blocks=%u, ", statbuf.st_blocks);
494 }
495 else
496 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
497 switch (statbuf.st_mode & S_IFMT) {
498 case S_IFCHR: case S_IFBLK:
499 tprintf("st_rdev=makedev(%lu, %lu), ",
500 (unsigned long) major(statbuf.st_rdev),
501 (unsigned long) minor(statbuf.st_rdev));
502 break;
503 default:
504 tprintf("st_size=%u, ", statbuf.st_size);
505 break;
506 }
507 if (!abbrev(tcp)) {
508 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
509 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100510 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200511 }
512 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200513 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200514}
Denys Vlasenko84703742012-02-25 02:38:52 +0100515#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200516
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000517#include "xlat/fileflags.h"
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000518
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000519static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000520realprintstat(struct tcb *tcp, struct stat *statbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000521{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000522 if (!abbrev(tcp)) {
523 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
524 (unsigned long) major(statbuf->st_dev),
525 (unsigned long) minor(statbuf->st_dev),
526 (unsigned long) statbuf->st_ino,
527 sprintmode(statbuf->st_mode));
528 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
529 (unsigned long) statbuf->st_nlink,
530 (unsigned long) statbuf->st_uid,
531 (unsigned long) statbuf->st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000532#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Denys Vlasenko1d632462009-04-14 12:51:00 +0000533 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
534#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000535#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Denys Vlasenko1d632462009-04-14 12:51:00 +0000536 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
537#endif
538 }
539 else
540 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
541 switch (statbuf->st_mode & S_IFMT) {
542 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000543#ifdef HAVE_STRUCT_STAT_ST_RDEV
Denys Vlasenko1d632462009-04-14 12:51:00 +0000544 tprintf("st_rdev=makedev(%lu, %lu), ",
545 (unsigned long) major(statbuf->st_rdev),
546 (unsigned long) minor(statbuf->st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000547#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000548 tprintf("st_size=makedev(%lu, %lu), ",
549 (unsigned long) major(statbuf->st_size),
550 (unsigned long) minor(statbuf->st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000551#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Denys Vlasenko1d632462009-04-14 12:51:00 +0000552 break;
553 default:
Dmitry V. Levine9a06b72011-02-23 16:16:50 +0000554 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000555 break;
556 }
557 if (!abbrev(tcp)) {
558 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
559 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
560 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000561#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200562 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000563 printflags(fileflags, statbuf->st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000564#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000565#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000566 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
567#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000568#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000569 tprintf(", st_level=%ld", statbuf->st_level);
570#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000571#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000572 tprintf(", st_fstype=%.*s",
573 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
574#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000575#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000576 tprintf(", st_gen=%u", statbuf->st_gen);
577#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200578 tprints("}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000579 }
580 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200581 tprints("...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000582}
583
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000584#ifndef X32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000585static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000586printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000587{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000588 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000589
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000590 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200591 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000592 return;
593 }
594 if (syserror(tcp) || !verbose(tcp)) {
595 tprintf("%#lx", addr);
596 return;
597 }
598
Denys Vlasenko9472a272013-02-12 11:43:46 +0100599#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000600 if (current_personality == 1) {
601 printstatsol(tcp, addr);
602 return;
603 }
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000604#ifdef SPARC64
605 else if (current_personality == 2) {
606 printstat_sparc64(tcp, addr);
607 return;
608 }
609#endif
Denys Vlasenko9472a272013-02-12 11:43:46 +0100610#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000611
Denys Vlasenko84703742012-02-25 02:38:52 +0100612#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200613 if (current_personality == 1) {
614 printstat_powerpc32(tcp, addr);
615 return;
616 }
617#endif
618
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000619 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200620 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000621 return;
622 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000623
624 realprintstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000625}
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000626#else /* X32 */
627# define printstat printstat64
628#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000629
Elliott Hughes391c0d82014-04-03 17:50:14 -0700630#if !defined HAVE_STAT64 && (defined AARCH64 || defined X86_64)
Roland McGrathe6d0f712007-08-07 01:22:49 +0000631/*
632 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
633 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
634 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
635 * __GNUC__ is needed for the required __attribute__ below.
Elliott Hughes391c0d82014-04-03 17:50:14 -0700636 *
637 * Similarly, aarch64 has a unified `struct stat' but its arm personality
638 * needs `struct stat64' (which also expects a 32-bit `long' but which
639 * shouldn't be packed).
Roland McGrathe6d0f712007-08-07 01:22:49 +0000640 */
641struct stat64 {
642 unsigned long long st_dev;
643 unsigned char __pad0[4];
644 unsigned int __st_ino;
645 unsigned int st_mode;
646 unsigned int st_nlink;
647 unsigned int st_uid;
648 unsigned int st_gid;
649 unsigned long long st_rdev;
650 unsigned char __pad3[4];
651 long long st_size;
652 unsigned int st_blksize;
653 unsigned long long st_blocks;
654 unsigned int st_atime;
655 unsigned int st_atime_nsec;
656 unsigned int st_mtime;
657 unsigned int st_mtime_nsec;
658 unsigned int st_ctime;
659 unsigned int st_ctime_nsec;
660 unsigned long long st_ino;
Elliott Hughes391c0d82014-04-03 17:50:14 -0700661}
662# if defined X86_64
663 __attribute__((packed))
664# define STAT64_SIZE 96
665#else
666# define STAT64_SIZE 104
667# endif
668;
Roland McGrathe6d0f712007-08-07 01:22:49 +0000669# define HAVE_STAT64 1
Roland McGrathe6d0f712007-08-07 01:22:49 +0000670#endif
671
Wichert Akkermanc7926982000-04-10 22:22:31 +0000672#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000673static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000674printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000675{
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000676#ifdef X32
677 struct stat statbuf;
678#else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000679 struct stat64 statbuf;
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000680#endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000681
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000682#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +0000683 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
684#endif
685
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000686 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200687 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000688 return;
689 }
690 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000691 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000692 return;
693 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000694
Denys Vlasenko9472a272013-02-12 11:43:46 +0100695#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000696 if (current_personality == 1) {
697 printstatsol(tcp, addr);
698 return;
699 }
700# ifdef SPARC64
701 else if (current_personality == 2) {
702 printstat_sparc64(tcp, addr);
703 return;
704 }
705# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +0100706#endif /* SPARC[64] */
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000707
Elliott Hughes391c0d82014-04-03 17:50:14 -0700708#if defined AARCH64
709 if (current_personality != 0) {
710 printstat(tcp, addr);
711 return;
712 }
713#endif
Denys Vlasenko84703742012-02-25 02:38:52 +0100714#if defined X86_64
H.J. Lu35be5812012-04-16 13:00:01 +0200715 if (current_personality != 1) {
Andreas Schwab61b74352009-10-16 11:37:13 +0200716 printstat(tcp, addr);
717 return;
718 }
719#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +0000720
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000721 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200722 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000723 return;
724 }
725
726 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +0000727 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000728 (unsigned long) major(statbuf.st_dev),
729 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +0000730 (unsigned long long) statbuf.st_ino,
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000731 sprintmode(statbuf.st_mode));
732 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
733 (unsigned long) statbuf.st_nlink,
734 (unsigned long) statbuf.st_uid,
735 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000736#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000737 tprintf("st_blksize=%lu, ",
738 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000739#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
740#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000741 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000742#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000743 }
744 else
745 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
746 switch (statbuf.st_mode & S_IFMT) {
747 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000748#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000749 tprintf("st_rdev=makedev(%lu, %lu), ",
750 (unsigned long) major(statbuf.st_rdev),
751 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000752#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000753 tprintf("st_size=makedev(%lu, %lu), ",
754 (unsigned long) major(statbuf.st_size),
755 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000756#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000757 break;
758 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +0000759 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000760 break;
761 }
762 if (!abbrev(tcp)) {
763 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
764 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000765 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000766#if HAVE_STRUCT_STAT_ST_FLAGS
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200767 tprints(", st_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000768 printflags(fileflags, statbuf.st_flags, "UF_???");
John Hughesc0fc3fd2001-03-08 16:10:40 +0000769#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000770#if HAVE_STRUCT_STAT_ST_ACLCNT
John Hughesc0fc3fd2001-03-08 16:10:40 +0000771 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
772#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000773#if HAVE_STRUCT_STAT_ST_LEVEL
John Hughesc0fc3fd2001-03-08 16:10:40 +0000774 tprintf(", st_level=%ld", statbuf.st_level);
775#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000776#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000777 tprintf(", st_fstype=%.*s",
778 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
779#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000780#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000781 tprintf(", st_gen=%u", statbuf.st_gen);
782#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200783 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000784 }
785 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200786 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000787}
Wichert Akkermanc7926982000-04-10 22:22:31 +0000788#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000789
Denys Vlasenko8435d672013-02-18 15:47:57 +0100790#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000791static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000792convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000793{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000794 newbuf->st_dev = oldbuf->st_dev;
795 newbuf->st_ino = oldbuf->st_ino;
796 newbuf->st_mode = oldbuf->st_mode;
797 newbuf->st_nlink = oldbuf->st_nlink;
798 newbuf->st_uid = oldbuf->st_uid;
799 newbuf->st_gid = oldbuf->st_gid;
800 newbuf->st_rdev = oldbuf->st_rdev;
801 newbuf->st_size = oldbuf->st_size;
802 newbuf->st_atime = oldbuf->st_atime;
803 newbuf->st_mtime = oldbuf->st_mtime;
804 newbuf->st_ctime = oldbuf->st_ctime;
805 newbuf->st_blksize = 0; /* not supported in old_stat */
806 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000807}
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000808
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000809static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000810printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000811{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000812 struct __old_kernel_stat statbuf;
813 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000814
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000815 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200816 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000817 return;
818 }
819 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000820 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000821 return;
822 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000823
Denys Vlasenko9472a272013-02-12 11:43:46 +0100824# if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000825 if (current_personality == 1) {
826 printstatsol(tcp, addr);
827 return;
828 }
Denys Vlasenko84703742012-02-25 02:38:52 +0100829# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000830
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000831 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200832 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000833 return;
834 }
835
836 convertoldstat(&statbuf, &newstatbuf);
837 realprintstat(tcp, &newstatbuf);
838}
Denys Vlasenko84703742012-02-25 02:38:52 +0100839#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000840
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000841int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000842sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000843{
844 if (entering(tcp)) {
845 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200846 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000847 } else {
848 printstat(tcp, tcp->u_arg[1]);
849 }
850 return 0;
851}
852
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000853#ifdef X32
854static void
855printstat64_x32(struct tcb *tcp, long addr)
856{
857 struct stat64 statbuf;
858
859 if (!addr) {
860 tprints("NULL");
861 return;
862 }
863 if (syserror(tcp) || !verbose(tcp)) {
864 tprintf("%#lx", addr);
865 return;
866 }
867
868 if (umove(tcp, addr, &statbuf) < 0) {
869 tprints("{...}");
870 return;
871 }
872
873 if (!abbrev(tcp)) {
874 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
875 (unsigned long) major(statbuf.st_dev),
876 (unsigned long) minor(statbuf.st_dev),
877 (unsigned long long) statbuf.st_ino,
878 sprintmode(statbuf.st_mode));
879 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
880 (unsigned long) statbuf.st_nlink,
881 (unsigned long) statbuf.st_uid,
882 (unsigned long) statbuf.st_gid);
883 tprintf("st_blksize=%lu, ",
884 (unsigned long) statbuf.st_blksize);
885 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
886 }
887 else
888 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
889 switch (statbuf.st_mode & S_IFMT) {
890 case S_IFCHR: case S_IFBLK:
891 tprintf("st_rdev=makedev(%lu, %lu), ",
892 (unsigned long) major(statbuf.st_rdev),
893 (unsigned long) minor(statbuf.st_rdev));
894 break;
895 default:
896 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
897 break;
898 }
899 if (!abbrev(tcp)) {
900 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
901 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
902 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
903 tprints("}");
904 }
905 else
906 tprints("...}");
907}
908#endif /* X32 */
909
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000910int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000911sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000912{
913#ifdef HAVE_STAT64
914 if (entering(tcp)) {
915 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200916 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000917 } else {
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000918# ifdef X32
919 printstat64_x32(tcp, tcp->u_arg[1]);
920# else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000921 printstat64(tcp, tcp->u_arg[1]);
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000922# endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000923 }
924 return 0;
925#else
926 return printargs(tcp);
927#endif
928}
929
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000930int
931sys_newfstatat(struct tcb *tcp)
932{
933 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300934 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000935 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200936 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000937 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +0200938#ifdef POWERPC64
939 if (current_personality == 0)
940 printstat(tcp, tcp->u_arg[2]);
941 else
942 printstat64(tcp, tcp->u_arg[2]);
943#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000944 printstat64(tcp, tcp->u_arg[2]);
945#else
946 printstat(tcp, tcp->u_arg[2]);
947#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200948 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +0000949 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000950 }
951 return 0;
952}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000953
Denys Vlasenko8435d672013-02-18 15:47:57 +0100954#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000955int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000956sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000957{
958 if (entering(tcp)) {
959 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200960 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000961 } else {
962 printoldstat(tcp, tcp->u_arg[1]);
963 }
964 return 0;
965}
Denys Vlasenko84703742012-02-25 02:38:52 +0100966#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000967
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000968int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000969sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000970{
Dmitry V. Levin31382132011-03-04 05:08:02 +0300971 if (entering(tcp)) {
972 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200973 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300974 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000975 printstat(tcp, tcp->u_arg[1]);
976 }
977 return 0;
978}
979
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000980int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000981sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000982{
983#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +0300984 if (entering(tcp)) {
985 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200986 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300987 } else {
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000988# ifdef X32
989 printstat64_x32(tcp, tcp->u_arg[1]);
990# else
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000991 printstat64(tcp, tcp->u_arg[1]);
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000992# endif
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000993 }
994 return 0;
995#else
996 return printargs(tcp);
997#endif
998}
999
Denys Vlasenko8435d672013-02-18 15:47:57 +01001000#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +00001001int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001002sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001003{
Dmitry V. Levin31382132011-03-04 05:08:02 +03001004 if (entering(tcp)) {
1005 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001006 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +03001007 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001008 printoldstat(tcp, tcp->u_arg[1]);
1009 }
1010 return 0;
1011}
Denys Vlasenko84703742012-02-25 02:38:52 +01001012#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +00001013
Denys Vlasenko9472a272013-02-12 11:43:46 +01001014#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001015
1016int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001017sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001018{
1019 if (entering(tcp)) {
1020 tprintf("%ld, ", tcp->u_arg[0]);
1021 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001022 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001023 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001024# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001025 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001026 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001027 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001028# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001029 printstat(tcp, tcp->u_arg[2]);
1030 }
1031 return 0;
1032}
1033
1034int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001035sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001036{
1037 if (entering(tcp))
1038 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1039 else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001040# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001041 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001042 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001043 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001044# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001045 printstat(tcp, tcp->u_arg[2]);
1046 }
1047 return 0;
1048}
1049
1050int
Denys Vlasenko1d632462009-04-14 12:51:00 +00001051sys_lxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001052{
1053 if (entering(tcp)) {
1054 tprintf("%ld, ", tcp->u_arg[0]);
1055 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001056 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001057 } else {
Denys Vlasenko84703742012-02-25 02:38:52 +01001058# ifdef _STAT64_VER
John Hughes8fe2c982001-03-06 09:45:18 +00001059 if (tcp->u_arg[0] == _STAT64_VER)
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001060 printstat64(tcp, tcp->u_arg[2]);
John Hughes8fe2c982001-03-06 09:45:18 +00001061 else
Denys Vlasenko84703742012-02-25 02:38:52 +01001062# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001063 printstat(tcp, tcp->u_arg[2]);
1064 }
1065 return 0;
1066}
1067
Denys Vlasenko9472a272013-02-12 11:43:46 +01001068#endif /* SPARC[64] */