blob: 7b5b31022c834075f52e19793475bb385a5e24ea [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
Dmitry V. Levin8d411082014-12-28 16:41:24 +000074#else /* !SPARC && !SPARC64 */
Denys Vlasenko84703742012-02-25 02:38:52 +010075# undef dev_t
76# undef ino_t
77# undef mode_t
78# undef nlink_t
79# undef uid_t
80# undef gid_t
81# undef off_t
82# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +010083# define dev_t __kernel_dev_t
84# define ino_t __kernel_ino_t
85# define mode_t __kernel_mode_t
86# define nlink_t __kernel_nlink_t
87# define uid_t __kernel_uid_t
88# define gid_t __kernel_gid_t
89# define off_t __kernel_off_t
90# define loff_t __kernel_loff_t
Wichert Akkermana6013701999-07-08 14:00:58 +000091
Denys Vlasenko84703742012-02-25 02:38:52 +010092# include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +000093
Denys Vlasenko84703742012-02-25 02:38:52 +010094# undef dev_t
95# undef ino_t
96# undef mode_t
97# undef nlink_t
98# undef uid_t
99# undef gid_t
100# undef off_t
101# undef loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +0100102# define dev_t dev_t
103# define ino_t ino_t
104# define mode_t mode_t
105# define nlink_t nlink_t
106# define uid_t uid_t
107# define gid_t gid_t
108# define off_t off_t
109# define loff_t loff_t
110#endif
111
Denys Vlasenko84703742012-02-25 02:38:52 +0100112#define stat libc_stat
113#define stat64 libc_stat64
114#include <sys/stat.h>
115#undef stat
116#undef stat64
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +0100117/* These might be macros. */
Denys Vlasenko84703742012-02-25 02:38:52 +0100118#undef st_atime
119#undef st_mtime
120#undef st_ctime
Wichert Akkermand4d8e921999-04-18 23:30:29 +0000121
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000122#ifdef MAJOR_IN_SYSMACROS
Denys Vlasenko84703742012-02-25 02:38:52 +0100123# include <sys/sysmacros.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000124#endif
125
126#ifdef MAJOR_IN_MKDEV
Denys Vlasenko84703742012-02-25 02:38:52 +0100127# include <sys/mkdev.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000128#endif
129
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000130/* several stats */
131
Dmitry V. Levin721de782015-01-08 02:59:04 +0000132#include "printstat.h"
133
Dmitry V. Levine6e475c2015-01-08 03:13:59 +0000134#ifdef SPARC64
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000135static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000136printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000137{
138 struct stat_sparc64 statbuf;
139
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000140 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200141 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000142 return;
143 }
144
145 if (!abbrev(tcp)) {
146 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
147 (unsigned long) major(statbuf.st_dev),
148 (unsigned long) minor(statbuf.st_dev),
149 (unsigned long) statbuf.st_ino,
150 sprintmode(statbuf.st_mode));
151 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
152 (unsigned long) statbuf.st_nlink,
153 (unsigned long) statbuf.st_uid,
154 (unsigned long) statbuf.st_gid);
155 tprintf("st_blksize=%lu, ",
156 (unsigned long) statbuf.st_blksize);
157 tprintf("st_blocks=%lu, ",
158 (unsigned long) statbuf.st_blocks);
159 }
160 else
161 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
162 switch (statbuf.st_mode & S_IFMT) {
163 case S_IFCHR: case S_IFBLK:
164 tprintf("st_rdev=makedev(%lu, %lu), ",
165 (unsigned long) major(statbuf.st_rdev),
166 (unsigned long) minor(statbuf.st_rdev));
167 break;
168 default:
169 tprintf("st_size=%lu, ", statbuf.st_size);
170 break;
171 }
172 if (!abbrev(tcp)) {
173 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
174 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100175 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000176 }
177 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200178 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000179}
Dmitry V. Levine6e475c2015-01-08 03:13:59 +0000180#endif /* SPARC64 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000181
Denys Vlasenko84703742012-02-25 02:38:52 +0100182#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200183struct stat_powerpc32 {
184 unsigned int st_dev;
185 unsigned int st_ino;
186 unsigned int st_mode;
187 unsigned short st_nlink;
188 unsigned int st_uid;
189 unsigned int st_gid;
190 unsigned int st_rdev;
191 unsigned int st_size;
192 unsigned int st_blksize;
193 unsigned int st_blocks;
194 unsigned int st_atime;
195 unsigned int st_atime_nsec;
196 unsigned int st_mtime;
197 unsigned int st_mtime_nsec;
198 unsigned int st_ctime;
199 unsigned int st_ctime_nsec;
200 unsigned int __unused4;
201 unsigned int __unused5;
202};
203
Dmitry V. Levin721de782015-01-08 02:59:04 +0000204# define DO_PRINTSTAT do_printstat32
205# define STRUCT_STAT struct stat_powerpc32
206# undef HAVE_STRUCT_STAT_ST_FLAGS
207# undef HAVE_STRUCT_STAT_ST_FSTYPE
208# undef HAVE_STRUCT_STAT_ST_GEN
209# include "printstat.h"
210
Andreas Schwabd69fa492010-07-12 21:39:57 +0200211static void
212printstat_powerpc32(struct tcb *tcp, long addr)
213{
214 struct stat_powerpc32 statbuf;
215
216 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200217 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200218 return;
219 }
220
Dmitry V. Levin721de782015-01-08 02:59:04 +0000221 do_printstat32(tcp, &statbuf);
Andreas Schwabd69fa492010-07-12 21:39:57 +0200222}
Denys Vlasenko84703742012-02-25 02:38:52 +0100223#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200224
Dmitry V. Levine6e475c2015-01-08 03:13:59 +0000225#if defined(SPARC) || defined(SPARC64)
226
227struct solstat {
228 unsigned st_dev;
229 unsigned int st_pad1[3]; /* network id */
230 unsigned st_ino;
231 unsigned st_mode;
232 unsigned st_nlink;
233 unsigned st_uid;
234 unsigned st_gid;
235 unsigned st_rdev;
236 unsigned int st_pad2[2];
237 unsigned int st_size;
238 unsigned int st_pad3; /* st_size, off_t expansion */
239 unsigned int st_atime;
240 unsigned int st_atime_nsec;
241 unsigned int st_mtime;
242 unsigned int st_mtime_nsec;
243 unsigned int st_ctime;
244 unsigned int st_ctime_nsec;
245 unsigned int st_blksize;
246 unsigned int st_blocks;
247 char st_fstype[16];
248 unsigned int st_pad4[8]; /* expansion area */
249};
250
251# define DO_PRINTSTAT do_printstat_sol
252# define STRUCT_STAT struct solstat
253# define STAT_MAJOR(x) (((x) >> 18) & 0x3fff)
254# define STAT_MINOR(x) ((x) & 0x3ffff)
255# undef HAVE_STRUCT_STAT_ST_FLAGS
256# undef HAVE_STRUCT_STAT_ST_FSTYPE
257# undef HAVE_STRUCT_STAT_ST_GEN
258# include "printstat.h"
259
260static void
261printstatsol(struct tcb *tcp, long addr)
262{
263 struct solstat statbuf;
264
265 if (umove(tcp, addr, &statbuf) < 0) {
266 tprints("{...}");
267 return;
268 }
269
270 do_printstat_sol(tcp, &statbuf);
271}
272
273#endif /* SPARC || SPARC64 */
274
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000275static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000276printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000277{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000278 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000279
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000280 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200281 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000282 return;
283 }
284 if (syserror(tcp) || !verbose(tcp)) {
285 tprintf("%#lx", addr);
286 return;
287 }
288
Denys Vlasenko9472a272013-02-12 11:43:46 +0100289#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000290 if (current_personality == 1) {
291 printstatsol(tcp, addr);
292 return;
293 }
Dmitry V. Levin553d8a22014-12-28 21:41:20 +0300294# ifdef SPARC64
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000295 else if (current_personality == 2) {
296 printstat_sparc64(tcp, addr);
297 return;
298 }
Dmitry V. Levin553d8a22014-12-28 21:41:20 +0300299# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +0100300#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000301
Denys Vlasenko84703742012-02-25 02:38:52 +0100302#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200303 if (current_personality == 1) {
304 printstat_powerpc32(tcp, addr);
305 return;
306 }
307#endif
308
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000309 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200310 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000311 return;
312 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000313
Dmitry V. Levind01f0a82014-12-28 18:00:39 +0000314 do_printstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000315}
316
Dmitry V. Levinc6ee0ec2015-01-08 01:14:53 +0000317int
318sys_stat(struct tcb *tcp)
319{
320 if (entering(tcp)) {
321 printpath(tcp, tcp->u_arg[0]);
322 tprints(", ");
323 } else {
324 printstat(tcp, tcp->u_arg[1]);
325 }
326 return 0;
327}
328
329int
330sys_fstat(struct tcb *tcp)
331{
332 if (entering(tcp)) {
333 printfd(tcp, tcp->u_arg[0]);
334 tprints(", ");
335 } else {
336 printstat(tcp, tcp->u_arg[1]);
337 }
338 return 0;
339}
340
Dmitry V. Levin8d411082014-12-28 16:41:24 +0000341#if !defined HAVE_STAT64 && (defined AARCH64 || defined X86_64 || defined X32)
Roland McGrathe6d0f712007-08-07 01:22:49 +0000342/*
Dmitry V. Levin8d411082014-12-28 16:41:24 +0000343 * Linux x86_64 and x32 have unified `struct stat' but their i386 personality
344 * needs `struct stat64'.
345 * linux/arch/x86/include/uapi/asm/stat.h defines `struct stat64' only for i386.
Roland McGrathe6d0f712007-08-07 01:22:49 +0000346 * __GNUC__ is needed for the required __attribute__ below.
Elliott Hughes391c0d82014-04-03 17:50:14 -0700347 *
348 * Similarly, aarch64 has a unified `struct stat' but its arm personality
Dmitry V. Levin8d411082014-12-28 16:41:24 +0000349 * needs `struct stat64' (unlike x86, it shouldn't be packed).
Roland McGrathe6d0f712007-08-07 01:22:49 +0000350 */
351struct stat64 {
352 unsigned long long st_dev;
353 unsigned char __pad0[4];
354 unsigned int __st_ino;
355 unsigned int st_mode;
356 unsigned int st_nlink;
357 unsigned int st_uid;
358 unsigned int st_gid;
359 unsigned long long st_rdev;
360 unsigned char __pad3[4];
361 long long st_size;
362 unsigned int st_blksize;
363 unsigned long long st_blocks;
364 unsigned int st_atime;
365 unsigned int st_atime_nsec;
366 unsigned int st_mtime;
367 unsigned int st_mtime_nsec;
368 unsigned int st_ctime;
369 unsigned int st_ctime_nsec;
370 unsigned long long st_ino;
Elliott Hughes391c0d82014-04-03 17:50:14 -0700371}
Dmitry V. Levin8d411082014-12-28 16:41:24 +0000372# if defined X86_64 || defined X32
Elliott Hughes391c0d82014-04-03 17:50:14 -0700373 __attribute__((packed))
374# define STAT64_SIZE 96
375#else
376# define STAT64_SIZE 104
377# endif
378;
Roland McGrathe6d0f712007-08-07 01:22:49 +0000379# define HAVE_STAT64 1
Dmitry V. Levin8d411082014-12-28 16:41:24 +0000380#endif /* AARCH64 || X86_64 || X32 */
Roland McGrathe6d0f712007-08-07 01:22:49 +0000381
Wichert Akkermanc7926982000-04-10 22:22:31 +0000382#ifdef HAVE_STAT64
Dmitry V. Levinb8ad3932014-12-28 18:56:23 +0000383
384# define DO_PRINTSTAT do_printstat64
385# define STRUCT_STAT struct stat64
386# undef HAVE_STRUCT_STAT_ST_FLAGS
387# undef HAVE_STRUCT_STAT_ST_FSTYPE
388# undef HAVE_STRUCT_STAT_ST_GEN
389# include "printstat.h"
390
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000391static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000392printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000393{
394 struct stat64 statbuf;
395
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000396#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +0000397 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
398#endif
399
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000400 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200401 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000402 return;
403 }
404 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000405 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000406 return;
407 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000408
Denys Vlasenko9472a272013-02-12 11:43:46 +0100409#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000410 if (current_personality == 1) {
411 printstatsol(tcp, addr);
412 return;
413 }
414# ifdef SPARC64
415 else if (current_personality == 2) {
416 printstat_sparc64(tcp, addr);
417 return;
418 }
419# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +0100420#endif /* SPARC[64] */
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000421
Elliott Hughes391c0d82014-04-03 17:50:14 -0700422#if defined AARCH64
423 if (current_personality != 0) {
424 printstat(tcp, addr);
425 return;
426 }
427#endif
Dmitry V. Levin553d8a22014-12-28 21:41:20 +0300428#if defined X86_64 || defined X32
H.J. Lu35be5812012-04-16 13:00:01 +0200429 if (current_personality != 1) {
Andreas Schwab61b74352009-10-16 11:37:13 +0200430 printstat(tcp, addr);
431 return;
432 }
433#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +0000434
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000435 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200436 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000437 return;
438 }
439
Dmitry V. Levinb8ad3932014-12-28 18:56:23 +0000440 do_printstat64(tcp, &statbuf);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000441}
Wichert Akkermanc7926982000-04-10 22:22:31 +0000442#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000443
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000444int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000445sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000446{
447#ifdef HAVE_STAT64
448 if (entering(tcp)) {
449 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200450 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000451 } else {
452 printstat64(tcp, tcp->u_arg[1]);
453 }
454 return 0;
455#else
456 return printargs(tcp);
457#endif
458}
459
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000460int
Dmitry V. Levinc6ee0ec2015-01-08 01:14:53 +0000461sys_fstat64(struct tcb *tcp)
462{
463#ifdef HAVE_STAT64
464 if (entering(tcp)) {
465 printfd(tcp, tcp->u_arg[0]);
466 tprints(", ");
467 } else {
468 printstat64(tcp, tcp->u_arg[1]);
469 }
470 return 0;
471#else
472 return printargs(tcp);
473#endif
474}
475
476int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000477sys_newfstatat(struct tcb *tcp)
478{
479 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300480 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000481 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200482 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000483 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +0200484#ifdef POWERPC64
485 if (current_personality == 0)
486 printstat(tcp, tcp->u_arg[2]);
487 else
488 printstat64(tcp, tcp->u_arg[2]);
489#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000490 printstat64(tcp, tcp->u_arg[2]);
491#else
492 printstat(tcp, tcp->u_arg[2]);
493#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200494 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +0000495 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000496 }
497 return 0;
498}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000499
Denys Vlasenko8435d672013-02-18 15:47:57 +0100500#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Dmitry V. Levin1fb1c132014-12-28 19:10:58 +0000501
502static void
503convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
504{
505 memset(newbuf, 0, sizeof(*newbuf));
506 newbuf->st_dev = oldbuf->st_dev;
507 newbuf->st_ino = oldbuf->st_ino;
508 newbuf->st_mode = oldbuf->st_mode;
509 newbuf->st_nlink = oldbuf->st_nlink;
510 newbuf->st_uid = oldbuf->st_uid;
511 newbuf->st_gid = oldbuf->st_gid;
512 newbuf->st_rdev = oldbuf->st_rdev;
513 newbuf->st_size = oldbuf->st_size;
514 newbuf->st_atime = oldbuf->st_atime;
515 newbuf->st_mtime = oldbuf->st_mtime;
516 newbuf->st_ctime = oldbuf->st_ctime;
517}
518
519static void
520printoldstat(struct tcb *tcp, long addr)
521{
522 struct __old_kernel_stat statbuf;
523 struct stat newstatbuf;
524
525 if (!addr) {
526 tprints("NULL");
527 return;
528 }
529 if (syserror(tcp) || !verbose(tcp)) {
530 tprintf("%#lx", addr);
531 return;
532 }
533
534# if defined(SPARC) || defined(SPARC64)
535 if (current_personality == 1) {
536 printstatsol(tcp, addr);
537 return;
538 }
539# endif
540
541 if (umove(tcp, addr, &statbuf) < 0) {
542 tprints("{...}");
543 return;
544 }
545
546 convertoldstat(&statbuf, &newstatbuf);
547 do_printstat(tcp, &newstatbuf);
548}
549
550int
551sys_oldstat(struct tcb *tcp)
552{
553 if (entering(tcp)) {
554 printpath(tcp, tcp->u_arg[0]);
555 tprints(", ");
556 } else {
557 printoldstat(tcp, tcp->u_arg[1]);
558 }
559 return 0;
560}
561
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000562int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000563sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000564{
Dmitry V. Levin31382132011-03-04 05:08:02 +0300565 if (entering(tcp)) {
566 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200567 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300568 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000569 printoldstat(tcp, tcp->u_arg[1]);
570 }
571 return 0;
572}
Dmitry V. Levin1fb1c132014-12-28 19:10:58 +0000573
574#endif /* HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000575
Denys Vlasenko9472a272013-02-12 11:43:46 +0100576#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000577
578int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000579sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000580{
581 if (entering(tcp)) {
582 tprintf("%ld, ", tcp->u_arg[0]);
583 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200584 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000585 } else {
586 printstat(tcp, tcp->u_arg[2]);
587 }
588 return 0;
589}
590
591int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000592sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000593{
Dmitry V. Levine00a9572014-12-29 03:15:42 +0000594 if (entering(tcp)) {
595 tprintf("%ld, ", tcp->u_arg[0]);
596 printfd(tcp, tcp->u_arg[1]);
597 tprints(", ");
598 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000599 printstat(tcp, tcp->u_arg[2]);
600 }
601 return 0;
602}
603
Dmitry V. Levin964d80a2014-12-06 03:53:16 +0000604#endif /* SPARC || SPARC64 */