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>
5 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
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
63 #define nlink_t nlink_t
70 #define stat libc_stat
71 #define stat64 libc_stat64
75 /* These might be macros. */
80 #if defined MAJOR_IN_SYSMACROS
81 # include <sys/sysmacros.h>
82 #elif defined MAJOR_IN_MKDEV
83 # include <sys/mkdev.h>
88 #include "printstat.h"
90 #undef STAT32_PERSONALITY
91 #if SUPPORTED_PERSONALITIES > 1
92 # if defined AARCH64 || defined X86_64 || defined X32
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;
114 # define STAT32_PERSONALITY 0
116 # define STAT32_PERSONALITY 1
118 # elif defined POWERPC64
122 unsigned int st_mode;
123 unsigned short st_nlink;
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;
139 # define STAT32_PERSONALITY 1
140 # elif defined SPARC64
142 unsigned short st_dev;
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];
160 # define STAT32_PERSONALITY 0
162 # /* no 64-bit personalities */
164 # /* no 32-bit stat */
166 # warning FIXME: check whether struct stat32 definition is needed for this architecture!
167 # endif /* X86_64 || X32 || POWERPC64 */
168 #endif /* SUPPORTED_PERSONALITIES > 1 */
170 #ifdef STAT32_PERSONALITY
171 # define DO_PRINTSTAT do_printstat32
172 # define STRUCT_STAT struct stat32
173 # undef HAVE_STRUCT_STAT_ST_FLAGS
174 # undef HAVE_STRUCT_STAT_ST_FSTYPE
175 # undef HAVE_STRUCT_STAT_ST_GEN
176 # include "printstat.h"
179 printstat32(struct tcb *tcp, long addr)
181 struct stat32 statbuf;
183 if (umove(tcp, addr, &statbuf) < 0) {
188 do_printstat32(tcp, &statbuf);
190 #endif /* STAT32_PERSONALITY */
192 #if defined(SPARC) || defined(SPARC64)
196 unsigned int st_pad1[3]; /* network id */
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;
215 unsigned int st_pad4[8]; /* expansion area */
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"
228 printstatsol(struct tcb *tcp, long addr)
230 struct solstat statbuf;
232 if (umove(tcp, addr, &statbuf) < 0) {
237 do_printstat_sol(tcp, &statbuf);
240 #endif /* SPARC || SPARC64 */
243 printstat(struct tcb *tcp, long addr)
251 if (syserror(tcp) || !verbose(tcp)) {
252 tprintf("%#lx", addr);
256 #ifdef STAT32_PERSONALITY
257 if (current_personality == STAT32_PERSONALITY) {
258 printstat32(tcp, addr);
263 #if defined(SPARC) || defined(SPARC64)
264 if (current_personality == 1) {
265 printstatsol(tcp, addr);
268 #endif /* SPARC || SPARC64 */
270 if (umove(tcp, addr, &statbuf) < 0) {
275 do_printstat(tcp, &statbuf);
279 sys_stat(struct tcb *tcp)
282 printpath(tcp, tcp->u_arg[0]);
285 printstat(tcp, tcp->u_arg[1]);
291 sys_fstat(struct tcb *tcp)
294 printfd(tcp, tcp->u_arg[0]);
297 printstat(tcp, tcp->u_arg[1]);
302 #if defined STAT32_PERSONALITY && !defined HAVE_STRUCT_STAT64
303 # if defined AARCH64 || defined X86_64 || defined X32
305 * Linux x86_64 and x32 have unified `struct stat' but their i386 personality
306 * needs `struct stat64'.
307 * linux/arch/x86/include/uapi/asm/stat.h defines `struct stat64' only for i386.
308 * __GNUC__ is needed for the required __attribute__ below.
310 * Similarly, aarch64 has a unified `struct stat' but its arm personality
311 * needs `struct stat64' (unlike x86, it shouldn't be packed).
314 unsigned long long st_dev;
315 unsigned char __pad0[4];
316 unsigned int __st_ino;
317 unsigned int st_mode;
318 unsigned int st_nlink;
321 unsigned long long st_rdev;
322 unsigned char __pad3[4];
324 unsigned int st_blksize;
325 unsigned long long st_blocks;
326 unsigned int st_atime;
327 unsigned int st_atime_nsec;
328 unsigned int st_mtime;
329 unsigned int st_mtime_nsec;
330 unsigned int st_ctime;
331 unsigned int st_ctime_nsec;
332 unsigned long long st_ino;
334 # if defined X86_64 || defined X32
335 __attribute__((packed))
336 # define STAT64_SIZE 96
338 # define STAT64_SIZE 104
341 # define HAVE_STRUCT_STAT64 1
342 # else /* !(AARCH64 || X86_64 || X32) */
343 # warning FIXME: check whether struct stat64 definition is needed for this architecture!
345 #endif /* STAT32_PERSONALITY && !HAVE_STRUCT_STAT64 */
347 #ifdef HAVE_STRUCT_STAT64
349 # define DO_PRINTSTAT do_printstat64
350 # define STRUCT_STAT struct stat64
351 # undef HAVE_STRUCT_STAT_ST_FLAGS
352 # undef HAVE_STRUCT_STAT_ST_FSTYPE
353 # undef HAVE_STRUCT_STAT_ST_GEN
354 # include "printstat.h"
357 printstat64(struct tcb *tcp, long addr)
359 struct stat64 statbuf;
362 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
369 if (syserror(tcp) || !verbose(tcp)) {
370 tprintf("%#lx", addr);
374 # ifdef STAT32_PERSONALITY
375 if (current_personality != STAT32_PERSONALITY) {
376 printstat(tcp, addr);
379 # endif /* STAT32_PERSONALITY */
381 if (umove(tcp, addr, &statbuf) < 0) {
386 do_printstat64(tcp, &statbuf);
390 sys_stat64(struct tcb *tcp)
393 printpath(tcp, tcp->u_arg[0]);
396 printstat64(tcp, tcp->u_arg[1]);
402 sys_fstat64(struct tcb *tcp)
405 printfd(tcp, tcp->u_arg[0]);
408 printstat64(tcp, tcp->u_arg[1]);
416 sys_stat64(struct tcb *tcp)
418 return sys_stat(tcp);
422 sys_fstat64(struct tcb *tcp)
424 return sys_fstat(tcp);
427 #endif /* HAVE_STRUCT_STAT64 */
430 sys_newfstatat(struct tcb *tcp)
433 print_dirfd(tcp, tcp->u_arg[0]);
434 printpath(tcp, tcp->u_arg[1]);
437 #if defined STAT32_PERSONALITY
438 if (current_personality == STAT32_PERSONALITY)
439 printstat64(tcp, tcp->u_arg[2]);
441 printstat(tcp, tcp->u_arg[2]);
442 #elif defined HAVE_STRUCT_STAT64
443 printstat64(tcp, tcp->u_arg[2]);
445 printstat(tcp, tcp->u_arg[2]);
446 #endif /* STAT32_PERSONALITY || HAVE_STRUCT_STAT64 */
448 printflags(at_flags, tcp->u_arg[3], "AT_???");
453 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
456 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
458 memset(newbuf, 0, sizeof(*newbuf));
459 newbuf->st_dev = oldbuf->st_dev;
460 newbuf->st_ino = oldbuf->st_ino;
461 newbuf->st_mode = oldbuf->st_mode;
462 newbuf->st_nlink = oldbuf->st_nlink;
463 newbuf->st_uid = oldbuf->st_uid;
464 newbuf->st_gid = oldbuf->st_gid;
465 newbuf->st_rdev = oldbuf->st_rdev;
466 newbuf->st_size = oldbuf->st_size;
467 newbuf->st_atime = oldbuf->st_atime;
468 newbuf->st_mtime = oldbuf->st_mtime;
469 newbuf->st_ctime = oldbuf->st_ctime;
473 printoldstat(struct tcb *tcp, long addr)
475 struct __old_kernel_stat statbuf;
476 struct stat newstatbuf;
482 if (syserror(tcp) || !verbose(tcp)) {
483 tprintf("%#lx", addr);
487 # if defined(SPARC) || defined(SPARC64)
488 if (current_personality == 1) {
489 printstatsol(tcp, addr);
494 if (umove(tcp, addr, &statbuf) < 0) {
499 convertoldstat(&statbuf, &newstatbuf);
500 do_printstat(tcp, &newstatbuf);
504 sys_oldstat(struct tcb *tcp)
507 printpath(tcp, tcp->u_arg[0]);
510 printoldstat(tcp, tcp->u_arg[1]);
516 sys_oldfstat(struct tcb *tcp)
519 printfd(tcp, tcp->u_arg[0]);
522 printoldstat(tcp, tcp->u_arg[1]);
527 #endif /* HAVE_STRUCT___OLD_KERNEL_STAT */
529 #if defined(SPARC) || defined(SPARC64)
532 sys_xstat(struct tcb *tcp)
535 tprintf("%ld, ", tcp->u_arg[0]);
536 printpath(tcp, tcp->u_arg[1]);
539 printstat(tcp, tcp->u_arg[2]);
545 sys_fxstat(struct tcb *tcp)
548 tprintf("%ld, ", tcp->u_arg[0]);
549 printfd(tcp, tcp->u_arg[1]);
552 printstat(tcp, tcp->u_arg[2]);
557 #endif /* SPARC || SPARC64 */