blob: 20a481d46ca7044886c083183f1a77593bd077ee [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
Denys Vlasenko9472a272013-02-12 11:43:46 +0100134#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000135typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000136 int tv_sec;
137 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000138} timestruct_t;
139
140struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000141 unsigned st_dev;
142 int st_pad1[3]; /* network id */
143 unsigned st_ino;
144 unsigned st_mode;
145 unsigned st_nlink;
146 unsigned st_uid;
147 unsigned st_gid;
148 unsigned st_rdev;
149 int st_pad2[2];
150 int st_size;
151 int st_pad3; /* st_size, off_t expansion */
152 timestruct_t st_atime;
153 timestruct_t st_mtime;
154 timestruct_t st_ctime;
155 int st_blksize;
156 int st_blocks;
157 char st_fstype[16];
158 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000159};
160
161static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000162printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000163{
164 struct solstat statbuf;
165
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000166 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200167 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000168 return;
169 }
170 if (!abbrev(tcp)) {
171 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
172 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
173 (unsigned long) (statbuf.st_dev & 0x3ffff),
174 (unsigned long) statbuf.st_ino,
175 sprintmode(statbuf.st_mode));
176 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
177 (unsigned long) statbuf.st_nlink,
178 (unsigned long) statbuf.st_uid,
179 (unsigned long) statbuf.st_gid);
180 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
181 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
182 }
183 else
184 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
185 switch (statbuf.st_mode & S_IFMT) {
186 case S_IFCHR: case S_IFBLK:
187 tprintf("st_rdev=makedev(%lu, %lu), ",
188 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
189 (unsigned long) (statbuf.st_rdev & 0x3ffff));
190 break;
191 default:
192 tprintf("st_size=%u, ", statbuf.st_size);
193 break;
194 }
195 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000196 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
197 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
198 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000199 }
200 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200201 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000202}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000203
Denys Vlasenko9472a272013-02-12 11:43:46 +0100204# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000205static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000206printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000207{
208 struct stat_sparc64 statbuf;
209
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000210 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200211 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000212 return;
213 }
214
215 if (!abbrev(tcp)) {
216 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
217 (unsigned long) major(statbuf.st_dev),
218 (unsigned long) minor(statbuf.st_dev),
219 (unsigned long) statbuf.st_ino,
220 sprintmode(statbuf.st_mode));
221 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
222 (unsigned long) statbuf.st_nlink,
223 (unsigned long) statbuf.st_uid,
224 (unsigned long) statbuf.st_gid);
225 tprintf("st_blksize=%lu, ",
226 (unsigned long) statbuf.st_blksize);
227 tprintf("st_blocks=%lu, ",
228 (unsigned long) statbuf.st_blocks);
229 }
230 else
231 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
232 switch (statbuf.st_mode & S_IFMT) {
233 case S_IFCHR: case S_IFBLK:
234 tprintf("st_rdev=makedev(%lu, %lu), ",
235 (unsigned long) major(statbuf.st_rdev),
236 (unsigned long) minor(statbuf.st_rdev));
237 break;
238 default:
239 tprintf("st_size=%lu, ", statbuf.st_size);
240 break;
241 }
242 if (!abbrev(tcp)) {
243 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
244 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100245 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000246 }
247 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200248 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000249}
Denys Vlasenko9472a272013-02-12 11:43:46 +0100250# endif /* SPARC64 */
251#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000252
Denys Vlasenko84703742012-02-25 02:38:52 +0100253#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200254struct stat_powerpc32 {
255 unsigned int st_dev;
256 unsigned int st_ino;
257 unsigned int st_mode;
258 unsigned short st_nlink;
259 unsigned int st_uid;
260 unsigned int st_gid;
261 unsigned int st_rdev;
262 unsigned int st_size;
263 unsigned int st_blksize;
264 unsigned int st_blocks;
265 unsigned int st_atime;
266 unsigned int st_atime_nsec;
267 unsigned int st_mtime;
268 unsigned int st_mtime_nsec;
269 unsigned int st_ctime;
270 unsigned int st_ctime_nsec;
271 unsigned int __unused4;
272 unsigned int __unused5;
273};
274
Dmitry V. Levin721de782015-01-08 02:59:04 +0000275# define DO_PRINTSTAT do_printstat32
276# define STRUCT_STAT struct stat_powerpc32
277# undef HAVE_STRUCT_STAT_ST_FLAGS
278# undef HAVE_STRUCT_STAT_ST_FSTYPE
279# undef HAVE_STRUCT_STAT_ST_GEN
280# include "printstat.h"
281
Andreas Schwabd69fa492010-07-12 21:39:57 +0200282static void
283printstat_powerpc32(struct tcb *tcp, long addr)
284{
285 struct stat_powerpc32 statbuf;
286
287 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200288 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200289 return;
290 }
291
Dmitry V. Levin721de782015-01-08 02:59:04 +0000292 do_printstat32(tcp, &statbuf);
Andreas Schwabd69fa492010-07-12 21:39:57 +0200293}
Denys Vlasenko84703742012-02-25 02:38:52 +0100294#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200295
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000296static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000297printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000298{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000299 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000300
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000301 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200302 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000303 return;
304 }
305 if (syserror(tcp) || !verbose(tcp)) {
306 tprintf("%#lx", addr);
307 return;
308 }
309
Denys Vlasenko9472a272013-02-12 11:43:46 +0100310#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000311 if (current_personality == 1) {
312 printstatsol(tcp, addr);
313 return;
314 }
Dmitry V. Levin553d8a22014-12-28 21:41:20 +0300315# ifdef SPARC64
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000316 else if (current_personality == 2) {
317 printstat_sparc64(tcp, addr);
318 return;
319 }
Dmitry V. Levin553d8a22014-12-28 21:41:20 +0300320# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +0100321#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000322
Denys Vlasenko84703742012-02-25 02:38:52 +0100323#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200324 if (current_personality == 1) {
325 printstat_powerpc32(tcp, addr);
326 return;
327 }
328#endif
329
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000330 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200331 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000332 return;
333 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000334
Dmitry V. Levind01f0a82014-12-28 18:00:39 +0000335 do_printstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000336}
337
Dmitry V. Levinc6ee0ec2015-01-08 01:14:53 +0000338int
339sys_stat(struct tcb *tcp)
340{
341 if (entering(tcp)) {
342 printpath(tcp, tcp->u_arg[0]);
343 tprints(", ");
344 } else {
345 printstat(tcp, tcp->u_arg[1]);
346 }
347 return 0;
348}
349
350int
351sys_fstat(struct tcb *tcp)
352{
353 if (entering(tcp)) {
354 printfd(tcp, tcp->u_arg[0]);
355 tprints(", ");
356 } else {
357 printstat(tcp, tcp->u_arg[1]);
358 }
359 return 0;
360}
361
Dmitry V. Levin8d411082014-12-28 16:41:24 +0000362#if !defined HAVE_STAT64 && (defined AARCH64 || defined X86_64 || defined X32)
Roland McGrathe6d0f712007-08-07 01:22:49 +0000363/*
Dmitry V. Levin8d411082014-12-28 16:41:24 +0000364 * Linux x86_64 and x32 have unified `struct stat' but their i386 personality
365 * needs `struct stat64'.
366 * linux/arch/x86/include/uapi/asm/stat.h defines `struct stat64' only for i386.
Roland McGrathe6d0f712007-08-07 01:22:49 +0000367 * __GNUC__ is needed for the required __attribute__ below.
Elliott Hughes391c0d82014-04-03 17:50:14 -0700368 *
369 * Similarly, aarch64 has a unified `struct stat' but its arm personality
Dmitry V. Levin8d411082014-12-28 16:41:24 +0000370 * needs `struct stat64' (unlike x86, it shouldn't be packed).
Roland McGrathe6d0f712007-08-07 01:22:49 +0000371 */
372struct stat64 {
373 unsigned long long st_dev;
374 unsigned char __pad0[4];
375 unsigned int __st_ino;
376 unsigned int st_mode;
377 unsigned int st_nlink;
378 unsigned int st_uid;
379 unsigned int st_gid;
380 unsigned long long st_rdev;
381 unsigned char __pad3[4];
382 long long st_size;
383 unsigned int st_blksize;
384 unsigned long long st_blocks;
385 unsigned int st_atime;
386 unsigned int st_atime_nsec;
387 unsigned int st_mtime;
388 unsigned int st_mtime_nsec;
389 unsigned int st_ctime;
390 unsigned int st_ctime_nsec;
391 unsigned long long st_ino;
Elliott Hughes391c0d82014-04-03 17:50:14 -0700392}
Dmitry V. Levin8d411082014-12-28 16:41:24 +0000393# if defined X86_64 || defined X32
Elliott Hughes391c0d82014-04-03 17:50:14 -0700394 __attribute__((packed))
395# define STAT64_SIZE 96
396#else
397# define STAT64_SIZE 104
398# endif
399;
Roland McGrathe6d0f712007-08-07 01:22:49 +0000400# define HAVE_STAT64 1
Dmitry V. Levin8d411082014-12-28 16:41:24 +0000401#endif /* AARCH64 || X86_64 || X32 */
Roland McGrathe6d0f712007-08-07 01:22:49 +0000402
Wichert Akkermanc7926982000-04-10 22:22:31 +0000403#ifdef HAVE_STAT64
Dmitry V. Levinb8ad3932014-12-28 18:56:23 +0000404
405# define DO_PRINTSTAT do_printstat64
406# define STRUCT_STAT struct stat64
407# undef HAVE_STRUCT_STAT_ST_FLAGS
408# undef HAVE_STRUCT_STAT_ST_FSTYPE
409# undef HAVE_STRUCT_STAT_ST_GEN
410# include "printstat.h"
411
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000412static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000413printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000414{
415 struct stat64 statbuf;
416
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000417#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +0000418 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
419#endif
420
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000421 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200422 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000423 return;
424 }
425 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000426 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000427 return;
428 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000429
Denys Vlasenko9472a272013-02-12 11:43:46 +0100430#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000431 if (current_personality == 1) {
432 printstatsol(tcp, addr);
433 return;
434 }
435# ifdef SPARC64
436 else if (current_personality == 2) {
437 printstat_sparc64(tcp, addr);
438 return;
439 }
440# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +0100441#endif /* SPARC[64] */
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000442
Elliott Hughes391c0d82014-04-03 17:50:14 -0700443#if defined AARCH64
444 if (current_personality != 0) {
445 printstat(tcp, addr);
446 return;
447 }
448#endif
Dmitry V. Levin553d8a22014-12-28 21:41:20 +0300449#if defined X86_64 || defined X32
H.J. Lu35be5812012-04-16 13:00:01 +0200450 if (current_personality != 1) {
Andreas Schwab61b74352009-10-16 11:37:13 +0200451 printstat(tcp, addr);
452 return;
453 }
454#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +0000455
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000456 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200457 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000458 return;
459 }
460
Dmitry V. Levinb8ad3932014-12-28 18:56:23 +0000461 do_printstat64(tcp, &statbuf);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000462}
Wichert Akkermanc7926982000-04-10 22:22:31 +0000463#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000464
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000465int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000466sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000467{
468#ifdef HAVE_STAT64
469 if (entering(tcp)) {
470 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200471 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000472 } else {
473 printstat64(tcp, tcp->u_arg[1]);
474 }
475 return 0;
476#else
477 return printargs(tcp);
478#endif
479}
480
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000481int
Dmitry V. Levinc6ee0ec2015-01-08 01:14:53 +0000482sys_fstat64(struct tcb *tcp)
483{
484#ifdef HAVE_STAT64
485 if (entering(tcp)) {
486 printfd(tcp, tcp->u_arg[0]);
487 tprints(", ");
488 } else {
489 printstat64(tcp, tcp->u_arg[1]);
490 }
491 return 0;
492#else
493 return printargs(tcp);
494#endif
495}
496
497int
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000498sys_newfstatat(struct tcb *tcp)
499{
500 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300501 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000502 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200503 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000504 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +0200505#ifdef POWERPC64
506 if (current_personality == 0)
507 printstat(tcp, tcp->u_arg[2]);
508 else
509 printstat64(tcp, tcp->u_arg[2]);
510#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000511 printstat64(tcp, tcp->u_arg[2]);
512#else
513 printstat(tcp, tcp->u_arg[2]);
514#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200515 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +0000516 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000517 }
518 return 0;
519}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000520
Denys Vlasenko8435d672013-02-18 15:47:57 +0100521#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Dmitry V. Levin1fb1c132014-12-28 19:10:58 +0000522
523static void
524convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
525{
526 memset(newbuf, 0, sizeof(*newbuf));
527 newbuf->st_dev = oldbuf->st_dev;
528 newbuf->st_ino = oldbuf->st_ino;
529 newbuf->st_mode = oldbuf->st_mode;
530 newbuf->st_nlink = oldbuf->st_nlink;
531 newbuf->st_uid = oldbuf->st_uid;
532 newbuf->st_gid = oldbuf->st_gid;
533 newbuf->st_rdev = oldbuf->st_rdev;
534 newbuf->st_size = oldbuf->st_size;
535 newbuf->st_atime = oldbuf->st_atime;
536 newbuf->st_mtime = oldbuf->st_mtime;
537 newbuf->st_ctime = oldbuf->st_ctime;
538}
539
540static void
541printoldstat(struct tcb *tcp, long addr)
542{
543 struct __old_kernel_stat statbuf;
544 struct stat newstatbuf;
545
546 if (!addr) {
547 tprints("NULL");
548 return;
549 }
550 if (syserror(tcp) || !verbose(tcp)) {
551 tprintf("%#lx", addr);
552 return;
553 }
554
555# if defined(SPARC) || defined(SPARC64)
556 if (current_personality == 1) {
557 printstatsol(tcp, addr);
558 return;
559 }
560# endif
561
562 if (umove(tcp, addr, &statbuf) < 0) {
563 tprints("{...}");
564 return;
565 }
566
567 convertoldstat(&statbuf, &newstatbuf);
568 do_printstat(tcp, &newstatbuf);
569}
570
571int
572sys_oldstat(struct tcb *tcp)
573{
574 if (entering(tcp)) {
575 printpath(tcp, tcp->u_arg[0]);
576 tprints(", ");
577 } else {
578 printoldstat(tcp, tcp->u_arg[1]);
579 }
580 return 0;
581}
582
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000583int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000584sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000585{
Dmitry V. Levin31382132011-03-04 05:08:02 +0300586 if (entering(tcp)) {
587 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200588 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300589 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000590 printoldstat(tcp, tcp->u_arg[1]);
591 }
592 return 0;
593}
Dmitry V. Levin1fb1c132014-12-28 19:10:58 +0000594
595#endif /* HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000596
Denys Vlasenko9472a272013-02-12 11:43:46 +0100597#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000598
599int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000600sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000601{
602 if (entering(tcp)) {
603 tprintf("%ld, ", tcp->u_arg[0]);
604 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200605 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000606 } else {
607 printstat(tcp, tcp->u_arg[2]);
608 }
609 return 0;
610}
611
612int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000613sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000614{
Dmitry V. Levine00a9572014-12-29 03:15:42 +0000615 if (entering(tcp)) {
616 tprintf("%ld, ", tcp->u_arg[0]);
617 printfd(tcp, tcp->u_arg[1]);
618 tprints(", ");
619 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000620 printstat(tcp, tcp->u_arg[2]);
621 }
622 return 0;
623}
624
Dmitry V. Levin964d80a2014-12-06 03:53:16 +0000625#endif /* SPARC || SPARC64 */