blob: 8e1952fc253913368c756b6e10328da411e4afc4 [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
Dmitry V. Levinf19836b2014-12-30 11:18:47 +000033#undef dev_t
34#undef ino_t
35#undef mode_t
36#undef nlink_t
37#undef uid_t
38#undef gid_t
39#undef off_t
40#undef loff_t
41#define dev_t __kernel_dev_t
42#define ino_t __kernel_ino_t
43#define mode_t __kernel_mode_t
44#define nlink_t __kernel_nlink_t
45#define uid_t __kernel_uid_t
46#define gid_t __kernel_gid_t
47#define off_t __kernel_off_t
48#define loff_t __kernel_loff_t
Wichert Akkermana6013701999-07-08 14:00:58 +000049
Dmitry V. Levinf19836b2014-12-30 11:18:47 +000050#include <asm/stat.h>
Wichert Akkermana6013701999-07-08 14:00:58 +000051
Dmitry V. Levinf19836b2014-12-30 11:18:47 +000052#undef dev_t
53#undef ino_t
54#undef mode_t
55#undef nlink_t
56#undef uid_t
57#undef gid_t
58#undef off_t
59#undef loff_t
60#define dev_t dev_t
61#define ino_t ino_t
62#define mode_t mode_t
63#define nlink_t nlink_t
64#define uid_t uid_t
65#define gid_t gid_t
66#define off_t off_t
67#define loff_t loff_t
Denys Vlasenko84703742012-02-25 02:38:52 +010068
Dmitry V. Levinf19836b2014-12-30 11:18:47 +000069/* for S_IFMT */
Denys Vlasenko84703742012-02-25 02:38:52 +010070#define stat libc_stat
71#define stat64 libc_stat64
72#include <sys/stat.h>
73#undef stat
74#undef stat64
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010075/* These might be macros. */
Denys Vlasenko84703742012-02-25 02:38:52 +010076#undef st_atime
77#undef st_mtime
78#undef st_ctime
Wichert Akkermand4d8e921999-04-18 23:30:29 +000079
Dmitry V. Levinf19836b2014-12-30 11:18:47 +000080#if defined MAJOR_IN_SYSMACROS
Denys Vlasenko84703742012-02-25 02:38:52 +010081# include <sys/sysmacros.h>
Dmitry V. Levinf19836b2014-12-30 11:18:47 +000082#elif defined MAJOR_IN_MKDEV
Denys Vlasenko84703742012-02-25 02:38:52 +010083# include <sys/mkdev.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000084#endif
85
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000086/* several stats */
87
Dmitry V. Levin721de782015-01-08 02:59:04 +000088#include "printstat.h"
89
Dmitry V. Levinf19836b2014-12-30 11:18:47 +000090#undef STAT32_PERSONALITY
91#if SUPPORTED_PERSONALITIES > 1
92# if defined AARCH64 || defined X86_64 || defined X32
93struct stat32 {
94 unsigned int st_dev;
95 unsigned int st_ino;
96 unsigned short st_mode;
97 unsigned short st_nlink;
98 unsigned short st_uid;
99 unsigned short st_gid;
100 unsigned int st_rdev;
101 unsigned int st_size;
102 unsigned int st_blksize;
103 unsigned int st_blocks;
104 unsigned int st_atime;
105 unsigned int st_atime_nsec;
106 unsigned int st_mtime;
107 unsigned int st_mtime_nsec;
108 unsigned int st_ctime;
109 unsigned int st_ctime_nsec;
110 unsigned int __unused4;
111 unsigned int __unused5;
112};
113# ifdef AARCH64
114# define STAT32_PERSONALITY 0
115# else
116# define STAT32_PERSONALITY 1
117# endif
118# elif defined POWERPC64
119struct stat32 {
Andreas Schwabd69fa492010-07-12 21:39:57 +0200120 unsigned int st_dev;
121 unsigned int st_ino;
122 unsigned int st_mode;
123 unsigned short st_nlink;
124 unsigned int st_uid;
125 unsigned int st_gid;
126 unsigned int st_rdev;
127 unsigned int st_size;
128 unsigned int st_blksize;
129 unsigned int st_blocks;
130 unsigned int st_atime;
131 unsigned int st_atime_nsec;
132 unsigned int st_mtime;
133 unsigned int st_mtime_nsec;
134 unsigned int st_ctime;
135 unsigned int st_ctime_nsec;
136 unsigned int __unused4;
137 unsigned int __unused5;
138};
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000139# define STAT32_PERSONALITY 1
140# elif defined SPARC64
141struct stat32 {
142 unsigned short st_dev;
143 unsigned int st_ino;
144 unsigned short st_mode;
145 unsigned short st_nlink;
146 unsigned short st_uid;
147 unsigned short st_gid;
148 unsigned short st_rdev;
149 unsigned int st_size;
150 unsigned int st_atime;
151 unsigned int st_atime_nsec;
152 unsigned int st_mtime;
153 unsigned int st_mtime_nsec;
154 unsigned int st_ctime;
155 unsigned int st_ctime_nsec;
156 unsigned int st_blksize;
157 unsigned int st_blocks;
158 unsigned int __unused4[2];
159};
160# define STAT32_PERSONALITY 0
161# elif defined SPARC
162# /* no 64-bit personalities */
163# elif defined TILE
164# /* no 32-bit stat */
165# else
166# warning FIXME: check whether struct stat32 definition is needed for this architecture!
167# endif /* X86_64 || X32 || POWERPC64 */
168#endif /* SUPPORTED_PERSONALITIES > 1 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200169
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000170#ifdef STAT32_PERSONALITY
Dmitry V. Levin721de782015-01-08 02:59:04 +0000171# define DO_PRINTSTAT do_printstat32
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000172# define STRUCT_STAT struct stat32
Dmitry V. Levin721de782015-01-08 02:59:04 +0000173# undef HAVE_STRUCT_STAT_ST_FLAGS
174# undef HAVE_STRUCT_STAT_ST_FSTYPE
175# undef HAVE_STRUCT_STAT_ST_GEN
176# include "printstat.h"
177
Andreas Schwabd69fa492010-07-12 21:39:57 +0200178static void
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000179printstat32(struct tcb *tcp, long addr)
Andreas Schwabd69fa492010-07-12 21:39:57 +0200180{
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000181 struct stat32 statbuf;
Andreas Schwabd69fa492010-07-12 21:39:57 +0200182
183 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200184 tprints("{...}");
Andreas Schwabd69fa492010-07-12 21:39:57 +0200185 return;
186 }
187
Dmitry V. Levin721de782015-01-08 02:59:04 +0000188 do_printstat32(tcp, &statbuf);
Andreas Schwabd69fa492010-07-12 21:39:57 +0200189}
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000190#endif /* STAT32_PERSONALITY */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200191
Dmitry V. Levine6e475c2015-01-08 03:13:59 +0000192#if defined(SPARC) || defined(SPARC64)
193
194struct solstat {
195 unsigned st_dev;
196 unsigned int st_pad1[3]; /* network id */
197 unsigned st_ino;
198 unsigned st_mode;
199 unsigned st_nlink;
200 unsigned st_uid;
201 unsigned st_gid;
202 unsigned st_rdev;
203 unsigned int st_pad2[2];
204 unsigned int st_size;
205 unsigned int st_pad3; /* st_size, off_t expansion */
206 unsigned int st_atime;
207 unsigned int st_atime_nsec;
208 unsigned int st_mtime;
209 unsigned int st_mtime_nsec;
210 unsigned int st_ctime;
211 unsigned int st_ctime_nsec;
212 unsigned int st_blksize;
213 unsigned int st_blocks;
214 char st_fstype[16];
215 unsigned int st_pad4[8]; /* expansion area */
216};
217
218# define DO_PRINTSTAT do_printstat_sol
219# define STRUCT_STAT struct solstat
220# define STAT_MAJOR(x) (((x) >> 18) & 0x3fff)
221# define STAT_MINOR(x) ((x) & 0x3ffff)
222# undef HAVE_STRUCT_STAT_ST_FLAGS
223# undef HAVE_STRUCT_STAT_ST_FSTYPE
224# undef HAVE_STRUCT_STAT_ST_GEN
225# include "printstat.h"
226
227static void
228printstatsol(struct tcb *tcp, long addr)
229{
230 struct solstat statbuf;
231
232 if (umove(tcp, addr, &statbuf) < 0) {
233 tprints("{...}");
234 return;
235 }
236
237 do_printstat_sol(tcp, &statbuf);
238}
239
240#endif /* SPARC || SPARC64 */
241
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000242static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000243printstat(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000244{
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000245 struct stat statbuf;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000246
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000247 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200248 tprints("NULL");
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000249 return;
250 }
251 if (syserror(tcp) || !verbose(tcp)) {
252 tprintf("%#lx", addr);
253 return;
254 }
255
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000256#ifdef STAT32_PERSONALITY
257 if (current_personality == STAT32_PERSONALITY) {
258 printstat32(tcp, addr);
259 return;
260 }
261#endif
262
Denys Vlasenko9472a272013-02-12 11:43:46 +0100263#if defined(SPARC) || defined(SPARC64)
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000264 if (current_personality == 1) {
265 printstatsol(tcp, addr);
266 return;
267 }
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000268#endif /* SPARC || SPARC64 */
Andreas Schwabd69fa492010-07-12 21:39:57 +0200269
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000270 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200271 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000272 return;
273 }
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000274
Dmitry V. Levind01f0a82014-12-28 18:00:39 +0000275 do_printstat(tcp, &statbuf);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000276}
277
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000278SYS_FUNC(stat)
Dmitry V. Levinc6ee0ec2015-01-08 01:14:53 +0000279{
280 if (entering(tcp)) {
281 printpath(tcp, tcp->u_arg[0]);
282 tprints(", ");
283 } else {
284 printstat(tcp, tcp->u_arg[1]);
285 }
286 return 0;
287}
288
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000289SYS_FUNC(fstat)
Dmitry V. Levinc6ee0ec2015-01-08 01:14:53 +0000290{
291 if (entering(tcp)) {
292 printfd(tcp, tcp->u_arg[0]);
293 tprints(", ");
294 } else {
295 printstat(tcp, tcp->u_arg[1]);
296 }
297 return 0;
298}
299
Dmitry V. Levin7b9bc442015-01-08 04:06:06 +0000300#if defined STAT32_PERSONALITY && !defined HAVE_STRUCT_STAT64
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000301# if defined AARCH64 || defined X86_64 || defined X32
Roland McGrathe6d0f712007-08-07 01:22:49 +0000302/*
Dmitry V. Levin8d411082014-12-28 16:41:24 +0000303 * Linux x86_64 and x32 have unified `struct stat' but their i386 personality
304 * needs `struct stat64'.
305 * linux/arch/x86/include/uapi/asm/stat.h defines `struct stat64' only for i386.
Elliott Hughes391c0d82014-04-03 17:50:14 -0700306 *
307 * Similarly, aarch64 has a unified `struct stat' but its arm personality
Dmitry V. Levin8d411082014-12-28 16:41:24 +0000308 * needs `struct stat64' (unlike x86, it shouldn't be packed).
Roland McGrathe6d0f712007-08-07 01:22:49 +0000309 */
310struct stat64 {
311 unsigned long long st_dev;
312 unsigned char __pad0[4];
313 unsigned int __st_ino;
314 unsigned int st_mode;
315 unsigned int st_nlink;
316 unsigned int st_uid;
317 unsigned int st_gid;
318 unsigned long long st_rdev;
319 unsigned char __pad3[4];
320 long long st_size;
321 unsigned int st_blksize;
322 unsigned long long st_blocks;
323 unsigned int st_atime;
324 unsigned int st_atime_nsec;
325 unsigned int st_mtime;
326 unsigned int st_mtime_nsec;
327 unsigned int st_ctime;
328 unsigned int st_ctime_nsec;
329 unsigned long long st_ino;
Elliott Hughes391c0d82014-04-03 17:50:14 -0700330}
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000331# if defined X86_64 || defined X32
Dmitry V. Levin5647cf82015-03-29 22:45:03 +0000332 ATTRIBUTE_PACKED
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000333# define STAT64_SIZE 96
334# else
335# define STAT64_SIZE 104
336# endif
Elliott Hughes391c0d82014-04-03 17:50:14 -0700337;
Dmitry V. Levin7b9bc442015-01-08 04:06:06 +0000338# define HAVE_STRUCT_STAT64 1
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000339# else /* !(AARCH64 || X86_64 || X32) */
340# warning FIXME: check whether struct stat64 definition is needed for this architecture!
341# endif
Dmitry V. Levin7b9bc442015-01-08 04:06:06 +0000342#endif /* STAT32_PERSONALITY && !HAVE_STRUCT_STAT64 */
Roland McGrathe6d0f712007-08-07 01:22:49 +0000343
Dmitry V. Levin7b9bc442015-01-08 04:06:06 +0000344#ifdef HAVE_STRUCT_STAT64
Dmitry V. Levinb8ad3932014-12-28 18:56:23 +0000345
346# define DO_PRINTSTAT do_printstat64
347# define STRUCT_STAT struct stat64
348# undef HAVE_STRUCT_STAT_ST_FLAGS
349# undef HAVE_STRUCT_STAT_ST_FSTYPE
350# undef HAVE_STRUCT_STAT_ST_GEN
351# include "printstat.h"
352
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000353static void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000354printstat64(struct tcb *tcp, long addr)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000355{
356 struct stat64 statbuf;
357
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000358# ifdef STAT64_SIZE
Roland McGrathe6d0f712007-08-07 01:22:49 +0000359 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000360# endif
Roland McGrathe6d0f712007-08-07 01:22:49 +0000361
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000362 if (!addr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200363 tprints("NULL");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000364 return;
365 }
366 if (syserror(tcp) || !verbose(tcp)) {
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000367 tprintf("%#lx", addr);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000368 return;
369 }
Denys Vlasenko4e718b52009-04-20 18:30:13 +0000370
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000371# ifdef STAT32_PERSONALITY
372 if (current_personality != STAT32_PERSONALITY) {
Elliott Hughes391c0d82014-04-03 17:50:14 -0700373 printstat(tcp, addr);
374 return;
375 }
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000376# endif /* STAT32_PERSONALITY */
Dmitry V. Levinff896f72009-10-21 13:43:57 +0000377
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000378 if (umove(tcp, addr, &statbuf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200379 tprints("{...}");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000380 return;
381 }
382
Dmitry V. Levinb8ad3932014-12-28 18:56:23 +0000383 do_printstat64(tcp, &statbuf);
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000384}
385
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000386SYS_FUNC(stat64)
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000387{
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000388 if (entering(tcp)) {
389 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200390 tprints(", ");
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000391 } else {
392 printstat64(tcp, tcp->u_arg[1]);
393 }
394 return 0;
Ulrich Drepper7f02c4d1999-12-24 08:01:34 +0000395}
396
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000397SYS_FUNC(fstat64)
Dmitry V. Levinc6ee0ec2015-01-08 01:14:53 +0000398{
Dmitry V. Levinc6ee0ec2015-01-08 01:14:53 +0000399 if (entering(tcp)) {
400 printfd(tcp, tcp->u_arg[0]);
401 tprints(", ");
402 } else {
403 printstat64(tcp, tcp->u_arg[1]);
404 }
405 return 0;
Dmitry V. Levinc6ee0ec2015-01-08 01:14:53 +0000406}
407
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000408#else
409
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000410SYS_FUNC(stat64)
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000411{
412 return sys_stat(tcp);
413}
414
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000415SYS_FUNC(fstat64)
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000416{
417 return sys_fstat(tcp);
418}
419
Dmitry V. Levin7b9bc442015-01-08 04:06:06 +0000420#endif /* HAVE_STRUCT_STAT64 */
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000421
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000422SYS_FUNC(newfstatat)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000423{
424 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300425 print_dirfd(tcp, tcp->u_arg[0]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000426 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200427 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000428 } else {
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000429#if defined STAT32_PERSONALITY
430 if (current_personality == STAT32_PERSONALITY)
Andreas Schwabd69fa492010-07-12 21:39:57 +0200431 printstat64(tcp, tcp->u_arg[2]);
Dmitry V. Levinf19836b2014-12-30 11:18:47 +0000432 else
433 printstat(tcp, tcp->u_arg[2]);
Dmitry V. Levin7b9bc442015-01-08 04:06:06 +0000434#elif defined HAVE_STRUCT_STAT64
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000435 printstat64(tcp, tcp->u_arg[2]);
436#else
437 printstat(tcp, tcp->u_arg[2]);
Dmitry V. Levin7b9bc442015-01-08 04:06:06 +0000438#endif /* STAT32_PERSONALITY || HAVE_STRUCT_STAT64 */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200439 tprints(", ");
Dmitry V. Levin7989ad42012-03-13 23:26:01 +0000440 printflags(at_flags, tcp->u_arg[3], "AT_???");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000441 }
442 return 0;
443}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000444
Denys Vlasenko8435d672013-02-18 15:47:57 +0100445#if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
Dmitry V. Levin1fb1c132014-12-28 19:10:58 +0000446
447static void
448convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
449{
450 memset(newbuf, 0, sizeof(*newbuf));
451 newbuf->st_dev = oldbuf->st_dev;
452 newbuf->st_ino = oldbuf->st_ino;
453 newbuf->st_mode = oldbuf->st_mode;
454 newbuf->st_nlink = oldbuf->st_nlink;
455 newbuf->st_uid = oldbuf->st_uid;
456 newbuf->st_gid = oldbuf->st_gid;
457 newbuf->st_rdev = oldbuf->st_rdev;
458 newbuf->st_size = oldbuf->st_size;
459 newbuf->st_atime = oldbuf->st_atime;
460 newbuf->st_mtime = oldbuf->st_mtime;
461 newbuf->st_ctime = oldbuf->st_ctime;
462}
463
464static void
465printoldstat(struct tcb *tcp, long addr)
466{
467 struct __old_kernel_stat statbuf;
468 struct stat newstatbuf;
469
470 if (!addr) {
471 tprints("NULL");
472 return;
473 }
474 if (syserror(tcp) || !verbose(tcp)) {
475 tprintf("%#lx", addr);
476 return;
477 }
478
479# if defined(SPARC) || defined(SPARC64)
480 if (current_personality == 1) {
481 printstatsol(tcp, addr);
482 return;
483 }
484# endif
485
486 if (umove(tcp, addr, &statbuf) < 0) {
487 tprints("{...}");
488 return;
489 }
490
491 convertoldstat(&statbuf, &newstatbuf);
492 do_printstat(tcp, &newstatbuf);
493}
494
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000495SYS_FUNC(oldstat)
Dmitry V. Levin1fb1c132014-12-28 19:10:58 +0000496{
497 if (entering(tcp)) {
498 printpath(tcp, tcp->u_arg[0]);
499 tprints(", ");
500 } else {
501 printoldstat(tcp, tcp->u_arg[1]);
502 }
503 return 0;
504}
505
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000506SYS_FUNC(oldfstat)
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000507{
Dmitry V. Levin31382132011-03-04 05:08:02 +0300508 if (entering(tcp)) {
509 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200510 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300511 } else {
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000512 printoldstat(tcp, tcp->u_arg[1]);
513 }
514 return 0;
515}
Dmitry V. Levin1fb1c132014-12-28 19:10:58 +0000516
517#endif /* HAVE_STRUCT___OLD_KERNEL_STAT */
Wichert Akkerman328c5e71999-04-16 00:21:26 +0000518
Denys Vlasenko9472a272013-02-12 11:43:46 +0100519#if defined(SPARC) || defined(SPARC64)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000521SYS_FUNC(xstat)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522{
523 if (entering(tcp)) {
524 tprintf("%ld, ", tcp->u_arg[0]);
525 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200526 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000527 } else {
528 printstat(tcp, tcp->u_arg[2]);
529 }
530 return 0;
531}
532
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000533SYS_FUNC(fxstat)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000534{
Dmitry V. Levine00a9572014-12-29 03:15:42 +0000535 if (entering(tcp)) {
536 tprintf("%ld, ", tcp->u_arg[0]);
537 printfd(tcp, tcp->u_arg[1]);
538 tprints(", ");
539 } else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000540 printstat(tcp, tcp->u_arg[2]);
541 }
542 return 0;
543}
544
Dmitry V. Levin964d80a2014-12-06 03:53:16 +0000545#endif /* SPARC || SPARC64 */