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 /* all locally defined structures provide these fields */
91 #undef HAVE_STRUCT_STAT_ST_ATIME_NSEC
92 #define HAVE_STRUCT_STAT_ST_ATIME_NSEC 1
93 #undef HAVE_STRUCT_STAT_ST_CTIME_NSEC
94 #define HAVE_STRUCT_STAT_ST_CTIME_NSEC 1
95 #undef HAVE_STRUCT_STAT_ST_MTIME_NSEC
96 #define HAVE_STRUCT_STAT_ST_MTIME_NSEC 1
98 #undef STAT32_PERSONALITY
99 #if SUPPORTED_PERSONALITIES > 1
103 #ifdef STAT32_PERSONALITY
104 # define DO_PRINTSTAT do_printstat32
105 # define STRUCT_STAT struct stat32
106 # undef HAVE_STRUCT_STAT_ST_FLAGS
107 # undef HAVE_STRUCT_STAT_ST_FSTYPE
108 # undef HAVE_STRUCT_STAT_ST_GEN
109 # include "printstat.h"
110 #endif /* STAT32_PERSONALITY */
113 printstat(struct tcb *tcp, long addr)
117 #ifdef STAT32_PERSONALITY
118 if (current_personality == STAT32_PERSONALITY) {
119 struct stat32 statbuf;
121 if (!umove_or_printaddr(tcp, addr, &statbuf))
122 do_printstat32(tcp, &statbuf);
127 if (!umove_or_printaddr(tcp, addr, &statbuf))
128 do_printstat(tcp, &statbuf);
134 printpath(tcp, tcp->u_arg[0]);
137 printstat(tcp, tcp->u_arg[1]);
145 printfd(tcp, tcp->u_arg[0]);
148 printstat(tcp, tcp->u_arg[1]);
153 #if defined STAT32_PERSONALITY && !defined HAVE_STRUCT_STAT64
154 # if defined AARCH64 || defined X86_64 || defined X32
156 * Linux x86_64 and x32 have unified `struct stat' but their i386 personality
157 * needs `struct stat64'.
158 * linux/arch/x86/include/uapi/asm/stat.h defines `struct stat64' only for i386.
160 * Similarly, aarch64 has a unified `struct stat' but its arm personality
161 * needs `struct stat64' (unlike x86, it shouldn't be packed).
164 unsigned long long st_dev;
165 unsigned char __pad0[4];
166 unsigned int __st_ino;
167 unsigned int st_mode;
168 unsigned int st_nlink;
171 unsigned long long st_rdev;
172 unsigned char __pad3[4];
174 unsigned int st_blksize;
175 unsigned long long st_blocks;
176 unsigned int st_atime;
177 unsigned int st_atime_nsec;
178 unsigned int st_mtime;
179 unsigned int st_mtime_nsec;
180 unsigned int st_ctime;
181 unsigned int st_ctime_nsec;
182 unsigned long long st_ino;
184 # if defined X86_64 || defined X32
186 # define STAT64_SIZE 96
188 # define STAT64_SIZE 104
191 # define HAVE_STRUCT_STAT64 1
192 # else /* !(AARCH64 || X86_64 || X32) */
193 # warning FIXME: check whether struct stat64 definition is needed for this architecture!
195 #endif /* STAT32_PERSONALITY && !HAVE_STRUCT_STAT64 */
197 #ifdef HAVE_STRUCT_STAT64
199 # define DO_PRINTSTAT do_printstat64
200 # define STRUCT_STAT struct stat64
201 # undef HAVE_STRUCT_STAT_ST_FLAGS
202 # undef HAVE_STRUCT_STAT_ST_FSTYPE
203 # undef HAVE_STRUCT_STAT_ST_GEN
204 # include "printstat.h"
207 printstat64(struct tcb *tcp, long addr)
209 struct stat64 statbuf;
212 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
215 # ifdef STAT32_PERSONALITY
216 if (current_personality != STAT32_PERSONALITY) {
217 printstat(tcp, addr);
220 # endif /* STAT32_PERSONALITY */
222 if (!umove_or_printaddr(tcp, addr, &statbuf))
223 do_printstat64(tcp, &statbuf);
229 printpath(tcp, tcp->u_arg[0]);
232 printstat64(tcp, tcp->u_arg[1]);
240 printfd(tcp, tcp->u_arg[0]);
243 printstat64(tcp, tcp->u_arg[1]);
252 return sys_stat(tcp);
257 return sys_fstat(tcp);
260 #endif /* HAVE_STRUCT_STAT64 */
265 print_dirfd(tcp, tcp->u_arg[0]);
266 printpath(tcp, tcp->u_arg[1]);
269 #if defined STAT32_PERSONALITY
270 if (current_personality == STAT32_PERSONALITY)
271 printstat64(tcp, tcp->u_arg[2]);
273 printstat(tcp, tcp->u_arg[2]);
274 #elif defined HAVE_STRUCT_STAT64
275 printstat64(tcp, tcp->u_arg[2]);
277 printstat(tcp, tcp->u_arg[2]);
278 #endif /* STAT32_PERSONALITY || HAVE_STRUCT_STAT64 */
280 printflags(at_flags, tcp->u_arg[3], "AT_???");
285 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
288 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
290 memset(newbuf, 0, sizeof(*newbuf));
291 newbuf->st_dev = oldbuf->st_dev;
292 newbuf->st_ino = oldbuf->st_ino;
293 newbuf->st_mode = oldbuf->st_mode;
294 newbuf->st_nlink = oldbuf->st_nlink;
295 newbuf->st_uid = oldbuf->st_uid;
296 newbuf->st_gid = oldbuf->st_gid;
297 newbuf->st_rdev = oldbuf->st_rdev;
298 newbuf->st_size = oldbuf->st_size;
299 newbuf->st_atime = oldbuf->st_atime;
300 newbuf->st_mtime = oldbuf->st_mtime;
301 newbuf->st_ctime = oldbuf->st_ctime;
305 printoldstat(struct tcb *tcp, long addr)
307 struct __old_kernel_stat statbuf;
308 struct stat newstatbuf;
310 if (!umove_or_printaddr(tcp, addr, &statbuf)) {
311 convertoldstat(&statbuf, &newstatbuf);
312 do_printstat(tcp, &newstatbuf);
319 printpath(tcp, tcp->u_arg[0]);
322 printoldstat(tcp, tcp->u_arg[1]);
330 printfd(tcp, tcp->u_arg[0]);
333 printoldstat(tcp, tcp->u_arg[1]);
338 #endif /* HAVE_STRUCT___OLD_KERNEL_STAT */
340 #if defined(SPARC) || defined(SPARC64)
345 tprintf("%ld, ", tcp->u_arg[0]);
346 printpath(tcp, tcp->u_arg[1]);
349 printstat(tcp, tcp->u_arg[2]);
357 tprintf("%ld, ", tcp->u_arg[0]);
358 printfd(tcp, tcp->u_arg[1]);
361 printstat(tcp, tcp->u_arg[2]);
366 #endif /* SPARC || SPARC64 */