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.
33 #if defined(SPARC) || defined(SPARC64)
35 unsigned short st_dev;
37 unsigned short st_mode;
39 unsigned short st_uid;
40 unsigned short st_gid;
41 unsigned short st_rdev;
44 unsigned int __unused1;
46 unsigned int __unused2;
48 unsigned int __unused3;
51 unsigned int __unused4[2];
58 unsigned int st_nlink;
68 unsigned long __unused4[2];
71 # define stat kernel_stat
72 # include <asm/stat.h>
74 #else /* !SPARC && !SPARC64 */
83 # 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
92 # include <asm/stat.h>
104 # define mode_t mode_t
105 # define nlink_t nlink_t
109 # define loff_t loff_t
112 #define stat libc_stat
113 #define stat64 libc_stat64
114 #include <sys/stat.h>
117 /* These might be macros. */
122 #ifdef MAJOR_IN_SYSMACROS
123 # include <sys/sysmacros.h>
126 #ifdef MAJOR_IN_MKDEV
127 # include <sys/mkdev.h>
132 #if defined(SPARC) || defined(SPARC64)
140 int st_pad1[3]; /* network id */
149 int st_pad3; /* st_size, off_t expansion */
150 timestruct_t st_atime;
151 timestruct_t st_mtime;
152 timestruct_t st_ctime;
156 int st_pad4[8]; /* expansion area */
160 printstatsol(struct tcb *tcp, long addr)
162 struct solstat statbuf;
164 if (umove(tcp, addr, &statbuf) < 0) {
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);
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));
190 tprintf("st_size=%u, ", statbuf.st_size);
194 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));
202 # if defined(SPARC64)
204 printstat_sparc64(struct tcb *tcp, long addr)
206 struct stat_sparc64 statbuf;
208 if (umove(tcp, addr, &statbuf) < 0) {
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);
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));
237 tprintf("st_size=%lu, ", statbuf.st_size);
241 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
242 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
243 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
248 # endif /* SPARC64 */
249 #endif /* SPARC[64] */
251 #if defined POWERPC64
252 struct stat_powerpc32 {
255 unsigned int st_mode;
256 unsigned short st_nlink;
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;
274 printstat_powerpc32(struct tcb *tcp, long addr)
276 struct stat_powerpc32 statbuf;
278 if (umove(tcp, addr, &statbuf) < 0) {
284 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
285 major(statbuf.st_dev), minor(statbuf.st_dev),
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);
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));
302 tprintf("st_size=%u, ", statbuf.st_size);
306 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
307 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
308 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
313 #endif /* POWERPC64 */
315 #include "printstat.h"
318 printstat(struct tcb *tcp, long addr)
326 if (syserror(tcp) || !verbose(tcp)) {
327 tprintf("%#lx", addr);
331 #if defined(SPARC) || defined(SPARC64)
332 if (current_personality == 1) {
333 printstatsol(tcp, addr);
337 else if (current_personality == 2) {
338 printstat_sparc64(tcp, addr);
342 #endif /* SPARC[64] */
344 #if defined POWERPC64
345 if (current_personality == 1) {
346 printstat_powerpc32(tcp, addr);
351 if (umove(tcp, addr, &statbuf) < 0) {
356 do_printstat(tcp, &statbuf);
359 #if !defined HAVE_STAT64 && (defined AARCH64 || defined X86_64 || defined X32)
361 * 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.
364 * __GNUC__ is needed for the required __attribute__ below.
366 * Similarly, aarch64 has a unified `struct stat' but its arm personality
367 * needs `struct stat64' (unlike x86, it shouldn't be packed).
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;
377 unsigned long long st_rdev;
378 unsigned char __pad3[4];
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;
390 # if defined X86_64 || defined X32
391 __attribute__((packed))
392 # define STAT64_SIZE 96
394 # define STAT64_SIZE 104
397 # define HAVE_STAT64 1
398 #endif /* AARCH64 || X86_64 || X32 */
402 # define DO_PRINTSTAT do_printstat64
403 # define STRUCT_STAT struct stat64
404 # undef HAVE_STRUCT_STAT_ST_FLAGS
405 # undef HAVE_STRUCT_STAT_ST_FSTYPE
406 # undef HAVE_STRUCT_STAT_ST_GEN
407 # include "printstat.h"
410 printstat64(struct tcb *tcp, long addr)
412 struct stat64 statbuf;
415 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
422 if (syserror(tcp) || !verbose(tcp)) {
423 tprintf("%#lx", addr);
427 #if defined(SPARC) || defined(SPARC64)
428 if (current_personality == 1) {
429 printstatsol(tcp, addr);
433 else if (current_personality == 2) {
434 printstat_sparc64(tcp, addr);
438 #endif /* SPARC[64] */
441 if (current_personality != 0) {
442 printstat(tcp, addr);
446 #if defined X86_64 || defined X32
447 if (current_personality != 1) {
448 printstat(tcp, addr);
453 if (umove(tcp, addr, &statbuf) < 0) {
458 do_printstat64(tcp, &statbuf);
460 #endif /* HAVE_STAT64 */
462 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
464 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
466 newbuf->st_dev = oldbuf->st_dev;
467 newbuf->st_ino = oldbuf->st_ino;
468 newbuf->st_mode = oldbuf->st_mode;
469 newbuf->st_nlink = oldbuf->st_nlink;
470 newbuf->st_uid = oldbuf->st_uid;
471 newbuf->st_gid = oldbuf->st_gid;
472 newbuf->st_rdev = oldbuf->st_rdev;
473 newbuf->st_size = oldbuf->st_size;
474 newbuf->st_atime = oldbuf->st_atime;
475 newbuf->st_mtime = oldbuf->st_mtime;
476 newbuf->st_ctime = oldbuf->st_ctime;
477 newbuf->st_blksize = 0; /* not supported in old_stat */
478 newbuf->st_blocks = 0; /* not supported in old_stat */
482 printoldstat(struct tcb *tcp, long addr)
484 struct __old_kernel_stat statbuf;
485 struct stat newstatbuf;
491 if (syserror(tcp) || !verbose(tcp)) {
492 tprintf("%#lx", addr);
496 # if defined(SPARC) || defined(SPARC64)
497 if (current_personality == 1) {
498 printstatsol(tcp, addr);
503 if (umove(tcp, addr, &statbuf) < 0) {
508 convertoldstat(&statbuf, &newstatbuf);
509 do_printstat(tcp, &newstatbuf);
514 sys_stat(struct tcb *tcp)
517 printpath(tcp, tcp->u_arg[0]);
520 printstat(tcp, tcp->u_arg[1]);
526 sys_stat64(struct tcb *tcp)
530 printpath(tcp, tcp->u_arg[0]);
533 printstat64(tcp, tcp->u_arg[1]);
537 return printargs(tcp);
542 sys_newfstatat(struct tcb *tcp)
545 print_dirfd(tcp, tcp->u_arg[0]);
546 printpath(tcp, tcp->u_arg[1]);
550 if (current_personality == 0)
551 printstat(tcp, tcp->u_arg[2]);
553 printstat64(tcp, tcp->u_arg[2]);
554 #elif defined HAVE_STAT64
555 printstat64(tcp, tcp->u_arg[2]);
557 printstat(tcp, tcp->u_arg[2]);
560 printflags(at_flags, tcp->u_arg[3], "AT_???");
565 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
567 sys_oldstat(struct tcb *tcp)
570 printpath(tcp, tcp->u_arg[0]);
573 printoldstat(tcp, tcp->u_arg[1]);
580 sys_fstat(struct tcb *tcp)
583 printfd(tcp, tcp->u_arg[0]);
586 printstat(tcp, tcp->u_arg[1]);
592 sys_fstat64(struct tcb *tcp)
596 printfd(tcp, tcp->u_arg[0]);
599 printstat64(tcp, tcp->u_arg[1]);
603 return printargs(tcp);
607 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
609 sys_oldfstat(struct tcb *tcp)
612 printfd(tcp, tcp->u_arg[0]);
615 printoldstat(tcp, tcp->u_arg[1]);
621 #if defined(SPARC) || defined(SPARC64)
624 sys_xstat(struct tcb *tcp)
627 tprintf("%ld, ", tcp->u_arg[0]);
628 printpath(tcp, tcp->u_arg[1]);
631 printstat(tcp, tcp->u_arg[2]);
637 sys_fxstat(struct tcb *tcp)
640 tprintf("%ld, ", tcp->u_arg[0]);
641 printfd(tcp, tcp->u_arg[1]);
644 printstat(tcp, tcp->u_arg[2]);
649 #endif /* SPARC || SPARC64 */