blob: cac3cb363197f512ba14910e9182f6492cab383a [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
Denys Vlasenko9472a272013-02-12 11:43:46 +0100132#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000133typedef struct {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000134 int tv_sec;
135 int tv_nsec;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000136} timestruct_t;
137
138struct solstat {
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000139 unsigned st_dev;
140 int st_pad1[3]; /* network id */
141 unsigned st_ino;
142 unsigned st_mode;
143 unsigned st_nlink;
144 unsigned st_uid;
145 unsigned st_gid;
146 unsigned st_rdev;
147 int st_pad2[2];
148 int st_size;
149 int st_pad3; /* st_size, off_t expansion */
150 timestruct_t st_atime;
151 timestruct_t st_mtime;
152 timestruct_t st_ctime;
153 int st_blksize;
154 int st_blocks;
155 char st_fstype[16];
156 int st_pad4[8]; /* expansion area */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000157};
158
159static void
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000160printstatsol(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000161{
162 struct solstat statbuf;
163
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000164 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200165 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000166 return;
167 }
168 if (!abbrev(tcp)) {
169 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
170 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
171 (unsigned long) (statbuf.st_dev & 0x3ffff),
172 (unsigned long) statbuf.st_ino,
173 sprintmode(statbuf.st_mode));
174 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
175 (unsigned long) statbuf.st_nlink,
176 (unsigned long) statbuf.st_uid,
177 (unsigned long) statbuf.st_gid);
178 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
179 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
180 }
181 else
182 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
183 switch (statbuf.st_mode & S_IFMT) {
184 case S_IFCHR: case S_IFBLK:
185 tprintf("st_rdev=makedev(%lu, %lu), ",
186 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
187 (unsigned long) (statbuf.st_rdev & 0x3ffff));
188 break;
189 default:
190 tprintf("st_size=%u, ", statbuf.st_size);
191 break;
192 }
193 if (!abbrev(tcp)) {
Dmitry V. Levinb838b1e2008-04-19 23:47:47 +0000194 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
195 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
196 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000197 }
198 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200199 tprints("...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000200}
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000201
Denys Vlasenko9472a272013-02-12 11:43:46 +0100202# if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000203static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000204printstat_sparc64(struct tcb *tcp, long addr)
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000205{
206 struct stat_sparc64 statbuf;
207
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000208 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200209 tprints("{...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000210 return;
211 }
212
213 if (!abbrev(tcp)) {
214 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
215 (unsigned long) major(statbuf.st_dev),
216 (unsigned long) minor(statbuf.st_dev),
217 (unsigned long) statbuf.st_ino,
218 sprintmode(statbuf.st_mode));
219 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
220 (unsigned long) statbuf.st_nlink,
221 (unsigned long) statbuf.st_uid,
222 (unsigned long) statbuf.st_gid);
223 tprintf("st_blksize=%lu, ",
224 (unsigned long) statbuf.st_blksize);
225 tprintf("st_blocks=%lu, ",
226 (unsigned long) statbuf.st_blocks);
227 }
228 else
229 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
230 switch (statbuf.st_mode & S_IFMT) {
231 case S_IFCHR: case S_IFBLK:
232 tprintf("st_rdev=makedev(%lu, %lu), ",
233 (unsigned long) major(statbuf.st_rdev),
234 (unsigned long) minor(statbuf.st_rdev));
235 break;
236 default:
237 tprintf("st_size=%lu, ", statbuf.st_size);
238 break;
239 }
240 if (!abbrev(tcp)) {
241 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
242 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100243 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000244 }
245 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200246 tprints("...}");
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000247}
Denys Vlasenko9472a272013-02-12 11:43:46 +0100248# endif /* SPARC64 */
249#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000250
Denys Vlasenko84703742012-02-25 02:38:52 +0100251#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200252struct stat_powerpc32 {
253 unsigned int st_dev;
254 unsigned int st_ino;
255 unsigned int st_mode;
256 unsigned short st_nlink;
257 unsigned int st_uid;
258 unsigned int st_gid;
259 unsigned int st_rdev;
260 unsigned int st_size;
261 unsigned int st_blksize;
262 unsigned int st_blocks;
263 unsigned int st_atime;
264 unsigned int st_atime_nsec;
265 unsigned int st_mtime;
266 unsigned int st_mtime_nsec;
267 unsigned int st_ctime;
268 unsigned int st_ctime_nsec;
269 unsigned int __unused4;
270 unsigned int __unused5;
271};
272
273static void
274printstat_powerpc32(struct tcb *tcp, long addr)
275{
276 struct stat_powerpc32 statbuf;
277
278 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200279 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200280 return;
281 }
282
283 if (!abbrev(tcp)) {
284 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
285 major(statbuf.st_dev), minor(statbuf.st_dev),
286 statbuf.st_ino,
287 sprintmode(statbuf.st_mode));
288 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
289 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
290 tprintf("st_blksize=%u, ", statbuf.st_blksize);
291 tprintf("st_blocks=%u, ", statbuf.st_blocks);
292 }
293 else
294 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
295 switch (statbuf.st_mode & S_IFMT) {
296 case S_IFCHR: case S_IFBLK:
297 tprintf("st_rdev=makedev(%lu, %lu), ",
298 (unsigned long) major(statbuf.st_rdev),
299 (unsigned long) minor(statbuf.st_rdev));
300 break;
301 default:
302 tprintf("st_size=%u, ", statbuf.st_size);
303 break;
304 }
305 if (!abbrev(tcp)) {
306 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
307 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
Denys Vlasenko1945ccc2012-02-27 14:37:48 +0100308 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
Andreas Schwabd69fa492010-07-12 21:39:57 +0200309 }
310 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200311 tprints("...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200312}
Denys Vlasenko84703742012-02-25 02:38:52 +0100313#endif /* POWERPC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200314
Dmitry V. Levinab21a942014-12-28 18:15:25 +0000315#include "printstat.h"
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000316
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000317static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000318printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000319{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000320 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000321
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000322 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200323 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000324 return;
325 }
326 if (syserror(tcp) || !verbose(tcp)) {
327 tprintf("%#lx", addr);
328 return;
329 }
330
Denys Vlasenko9472a272013-02-12 11:43:46 +0100331#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000332 if (current_personality == 1) {
333 printstatsol(tcp, addr);
334 return;
335 }
Dmitry V. Levin553d8a22014-12-28 21:41:20 +0300336# ifdef SPARC64
Roland McGrath6d1a65c2004-07-12 07:44:08 +0000337 else if (current_personality == 2) {
338 printstat_sparc64(tcp, addr);
339 return;
340 }
Dmitry V. Levin553d8a22014-12-28 21:41:20 +0300341# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +0100342#endif /* SPARC[64] */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000343
Denys Vlasenko84703742012-02-25 02:38:52 +0100344#if defined POWERPC64
Andreas Schwabd69fa492010-07-12 21:39:57 +0200345 if (current_personality == 1) {
346 printstat_powerpc32(tcp, addr);
347 return;
348 }
349#endif
350
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000351 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200352 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000353 return;
354 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000355
Dmitry V. Levind01f0a82014-12-28 18:00:39 +0000356 do_printstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000357}
358
Dmitry V. Levin8d411082014-12-28 16:41:24 +0000359#if !defined HAVE_STAT64 && (defined AARCH64 || defined X86_64 || defined X32)
Roland McGrathe6d0f712007-08-07 01:22:49 +0000360/*
Dmitry V. Levin8d411082014-12-28 16:41:24 +0000361 * Linux x86_64 and x32 have unified `struct stat' but their i386 personality
362 * needs `struct stat64'.
363 * linux/arch/x86/include/uapi/asm/stat.h defines `struct stat64' only for i386.
Roland McGrathe6d0f712007-08-07 01:22:49 +0000364 * __GNUC__ is needed for the required __attribute__ below.
Elliott Hughes391c0d82014-04-03 17:50:14 -0700365 *
366 * Similarly, aarch64 has a unified `struct stat' but its arm personality
Dmitry V. Levin8d411082014-12-28 16:41:24 +0000367 * needs `struct stat64' (unlike x86, it shouldn't be packed).
Roland McGrathe6d0f712007-08-07 01:22:49 +0000368 */
369struct stat64 {
370 unsigned long long st_dev;
371 unsigned char __pad0[4];
372 unsigned int __st_ino;
373 unsigned int st_mode;
374 unsigned int st_nlink;
375 unsigned int st_uid;
376 unsigned int st_gid;
377 unsigned long long st_rdev;
378 unsigned char __pad3[4];
379 long long st_size;
380 unsigned int st_blksize;
381 unsigned long long st_blocks;
382 unsigned int st_atime;
383 unsigned int st_atime_nsec;
384 unsigned int st_mtime;
385 unsigned int st_mtime_nsec;
386 unsigned int st_ctime;
387 unsigned int st_ctime_nsec;
388 unsigned long long st_ino;
Elliott Hughes391c0d82014-04-03 17:50:14 -0700389}
Dmitry V. Levin8d411082014-12-28 16:41:24 +0000390# if defined X86_64 || defined X32
Elliott Hughes391c0d82014-04-03 17:50:14 -0700391 __attribute__((packed))
392# define STAT64_SIZE 96
393#else
394# define STAT64_SIZE 104
395# endif
396;
Roland McGrathe6d0f712007-08-07 01:22:49 +0000397# define HAVE_STAT64 1
Dmitry V. Levin8d411082014-12-28 16:41:24 +0000398#endif /* AARCH64 || X86_64 || X32 */
Roland McGrathe6d0f712007-08-07 01:22:49 +0000399
Wichert Akkermanc7926982000-04-10 22:22:31 +0000400#ifdef HAVE_STAT64
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000401static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000402printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000403{
404 struct stat64 statbuf;
405
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000406#ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +0000407 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
408#endif
409
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000410 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200411 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000412 return;
413 }
414 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000415 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000416 return;
417 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000418
Denys Vlasenko9472a272013-02-12 11:43:46 +0100419#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000420 if (current_personality == 1) {
421 printstatsol(tcp, addr);
422 return;
423 }
424# ifdef SPARC64
425 else if (current_personality == 2) {
426 printstat_sparc64(tcp, addr);
427 return;
428 }
429# endif
Denys Vlasenko9472a272013-02-12 11:43:46 +0100430#endif /* SPARC[64] */
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000431
Elliott Hughes391c0d82014-04-03 17:50:14 -0700432#if defined AARCH64
433 if (current_personality != 0) {
434 printstat(tcp, addr);
435 return;
436 }
437#endif
Dmitry V. Levin553d8a22014-12-28 21:41:20 +0300438#if defined X86_64 || defined X32
H.J. Lu35be5812012-04-16 13:00:01 +0200439 if (current_personality != 1) {
Andreas Schwab61b74352009-10-16 11:37:13 +0200440 printstat(tcp, addr);
441 return;
442 }
443#endif
Dmitry V. Levinff896f72009-10-21 13:43:57 +0000444
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000445 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200446 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000447 return;
448 }
449
450 if (!abbrev(tcp)) {
Wichert Akkermand077c452000-08-10 18:16:15 +0000451 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000452 (unsigned long) major(statbuf.st_dev),
453 (unsigned long) minor(statbuf.st_dev),
Wichert Akkermand077c452000-08-10 18:16:15 +0000454 (unsigned long long) statbuf.st_ino,
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000455 sprintmode(statbuf.st_mode));
456 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
457 (unsigned long) statbuf.st_nlink,
458 (unsigned long) statbuf.st_uid,
459 (unsigned long) statbuf.st_gid);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000460#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000461 tprintf("st_blksize=%lu, ",
462 (unsigned long) statbuf.st_blksize);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000463#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
464#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000465 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000466#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000467 }
468 else
469 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
470 switch (statbuf.st_mode & S_IFMT) {
471 case S_IFCHR: case S_IFBLK:
Roland McGrath6d2b3492002-12-30 00:51:30 +0000472#ifdef HAVE_STRUCT_STAT_ST_RDEV
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000473 tprintf("st_rdev=makedev(%lu, %lu), ",
474 (unsigned long) major(statbuf.st_rdev),
475 (unsigned long) minor(statbuf.st_rdev));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000476#else /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000477 tprintf("st_size=makedev(%lu, %lu), ",
478 (unsigned long) major(statbuf.st_size),
479 (unsigned long) minor(statbuf.st_size));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000480#endif /* !HAVE_STRUCT_STAT_ST_RDEV */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000481 break;
482 default:
Roland McGrathc7bd4d32007-08-07 01:05:19 +0000483 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000484 break;
485 }
486 if (!abbrev(tcp)) {
487 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
488 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
John Hughesc0fc3fd2001-03-08 16:10:40 +0000489 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
Roland McGrath6d2b3492002-12-30 00:51:30 +0000490#if HAVE_STRUCT_STAT_ST_FLAGS
Dmitry V. Levin2928afe2014-12-28 17:44:13 +0000491 tprintf(", st_flags=%u", statbuf->st_flags);
John Hughesc0fc3fd2001-03-08 16:10:40 +0000492#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000493#if HAVE_STRUCT_STAT_ST_FSTYPE
John Hughesc0fc3fd2001-03-08 16:10:40 +0000494 tprintf(", st_fstype=%.*s",
495 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
496#endif
Roland McGrath6d2b3492002-12-30 00:51:30 +0000497#if HAVE_STRUCT_STAT_ST_GEN
John Hughesc0fc3fd2001-03-08 16:10:40 +0000498 tprintf(", st_gen=%u", statbuf.st_gen);
499#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200500 tprints("}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000501 }
502 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200503 tprints("...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000504}
Wichert Akkermanc7926982000-04-10 22:22:31 +0000505#endif /* HAVE_STAT64 */
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000506
Denys Vlasenko8435d672013-02-18 15:47:57 +0100507#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000508static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000509convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000510{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000511 newbuf->st_dev = oldbuf->st_dev;
512 newbuf->st_ino = oldbuf->st_ino;
513 newbuf->st_mode = oldbuf->st_mode;
514 newbuf->st_nlink = oldbuf->st_nlink;
515 newbuf->st_uid = oldbuf->st_uid;
516 newbuf->st_gid = oldbuf->st_gid;
517 newbuf->st_rdev = oldbuf->st_rdev;
518 newbuf->st_size = oldbuf->st_size;
519 newbuf->st_atime = oldbuf->st_atime;
520 newbuf->st_mtime = oldbuf->st_mtime;
521 newbuf->st_ctime = oldbuf->st_ctime;
522 newbuf->st_blksize = 0; /* not supported in old_stat */
523 newbuf->st_blocks = 0; /* not supported in old_stat */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000524}
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000525
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000526static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000527printoldstat(struct tcb *tcp, long addr)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000528{
Wichert Akkerman25d0c4f1999-04-18 19:35:42 +0000529 struct __old_kernel_stat statbuf;
530 struct stat newstatbuf;
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000531
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000532 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200533 tprints("NULL");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000534 return;
535 }
536 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000537 tprintf("%#lx", addr);
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000538 return;
539 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000540
Denys Vlasenko9472a272013-02-12 11:43:46 +0100541# if defined(SPARC) || defined(SPARC64)
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000542 if (current_personality == 1) {
543 printstatsol(tcp, addr);
544 return;
545 }
Denys Vlasenko84703742012-02-25 02:38:52 +0100546# endif
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000547
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000548 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200549 tprints("{...}");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000550 return;
551 }
552
553 convertoldstat(&statbuf, &newstatbuf);
Dmitry V. Levind01f0a82014-12-28 18:00:39 +0000554 do_printstat(tcp, &newstatbuf);
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000555}
Denys Vlasenko84703742012-02-25 02:38:52 +0100556#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000557
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000559sys_stat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000560{
561 if (entering(tcp)) {
562 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200563 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564 } else {
565 printstat(tcp, tcp->u_arg[1]);
566 }
567 return 0;
568}
569
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000570int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000571sys_stat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000572{
573#ifdef HAVE_STAT64
574 if (entering(tcp)) {
575 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200576 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000577 } else {
578 printstat64(tcp, tcp->u_arg[1]);
579 }
580 return 0;
581#else
582 return printargs(tcp);
583#endif
584}
585
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000586int
587sys_newfstatat(struct tcb *tcp)
588{
589 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300590 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000591 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200592 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000593 } else {
Andreas Schwabd69fa492010-07-12 21:39:57 +0200594#ifdef POWERPC64
595 if (current_personality == 0)
596 printstat(tcp, tcp->u_arg[2]);
597 else
598 printstat64(tcp, tcp->u_arg[2]);
599#elif defined HAVE_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000600 printstat64(tcp, tcp->u_arg[2]);
601#else
602 printstat(tcp, tcp->u_arg[2]);
603#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200604 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +0000605 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000606 }
607 return 0;
608}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000609
Denys Vlasenko8435d672013-02-18 15:47:57 +0100610#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000611int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000612sys_oldstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000613{
614 if (entering(tcp)) {
615 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200616 tprints(", ");
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000617 } else {
618 printoldstat(tcp, tcp->u_arg[1]);
619 }
620 return 0;
621}
Denys Vlasenko84703742012-02-25 02:38:52 +0100622#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000623
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000624int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000625sys_fstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000626{
Dmitry V. Levin31382132011-03-04 05:08:02 +0300627 if (entering(tcp)) {
628 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200629 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300630 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000631 printstat(tcp, tcp->u_arg[1]);
632 }
633 return 0;
634}
635
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000636int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000637sys_fstat64(struct tcb *tcp)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000638{
639#ifdef HAVE_STAT64
Dmitry V. Levin31382132011-03-04 05:08:02 +0300640 if (entering(tcp)) {
641 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200642 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300643 } else {
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000644 printstat64(tcp, tcp->u_arg[1]);
645 }
646 return 0;
647#else
648 return printargs(tcp);
649#endif
650}
651
Denys Vlasenko8435d672013-02-18 15:47:57 +0100652#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000653int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000654sys_oldfstat(struct tcb *tcp)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000655{
Dmitry V. Levin31382132011-03-04 05:08:02 +0300656 if (entering(tcp)) {
657 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200658 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300659 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000660 printoldstat(tcp, tcp->u_arg[1]);
661 }
662 return 0;
663}
Denys Vlasenko84703742012-02-25 02:38:52 +0100664#endif
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000665
Denys Vlasenko9472a272013-02-12 11:43:46 +0100666#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000667
668int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000669sys_xstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000670{
671 if (entering(tcp)) {
672 tprintf("%ld, ", tcp->u_arg[0]);
673 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200674 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000675 } else {
676 printstat(tcp, tcp->u_arg[2]);
677 }
678 return 0;
679}
680
681int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000682sys_fxstat(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000683{
Dmitry V. Levine00a9572014-12-29 03:15:42 +0000684 if (entering(tcp)) {
685 tprintf("%ld, ", tcp->u_arg[0]);
686 printfd(tcp, tcp->u_arg[1]);
687 tprints(", ");
688 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000689 printstat(tcp, tcp->u_arg[2]);
690 }
691 return 0;
692}
693
Dmitry V. Levin964d80a2014-12-06 03:53:16 +0000694#endif /* SPARC || SPARC64 */