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
100 # if defined AARCH64 || defined X86_64 || defined X32
104 unsigned short st_mode;
105 unsigned short st_nlink;
106 unsigned short st_uid;
107 unsigned short st_gid;
108 unsigned int st_rdev;
109 unsigned int st_size;
110 unsigned int st_blksize;
111 unsigned int st_blocks;
112 unsigned int st_atime;
113 unsigned int st_atime_nsec;
114 unsigned int st_mtime;
115 unsigned int st_mtime_nsec;
116 unsigned int st_ctime;
117 unsigned int st_ctime_nsec;
118 unsigned int __unused4;
119 unsigned int __unused5;
122 # define STAT32_PERSONALITY 0
124 # define STAT32_PERSONALITY 1
126 # elif defined POWERPC64
130 unsigned int st_mode;
131 unsigned short st_nlink;
134 unsigned int st_rdev;
135 unsigned int st_size;
136 unsigned int st_blksize;
137 unsigned int st_blocks;
138 unsigned int st_atime;
139 unsigned int st_atime_nsec;
140 unsigned int st_mtime;
141 unsigned int st_mtime_nsec;
142 unsigned int st_ctime;
143 unsigned int st_ctime_nsec;
144 unsigned int __unused4;
145 unsigned int __unused5;
147 # define STAT32_PERSONALITY 1
148 # elif defined SPARC64
150 unsigned short st_dev;
152 unsigned short st_mode;
153 unsigned short st_nlink;
154 unsigned short st_uid;
155 unsigned short st_gid;
156 unsigned short st_rdev;
157 unsigned int st_size;
158 unsigned int st_atime;
159 unsigned int st_atime_nsec;
160 unsigned int st_mtime;
161 unsigned int st_mtime_nsec;
162 unsigned int st_ctime;
163 unsigned int st_ctime_nsec;
164 unsigned int st_blksize;
165 unsigned int st_blocks;
166 unsigned int __unused4[2];
168 # define STAT32_PERSONALITY 0
170 # /* no 64-bit personalities */
172 # /* no 32-bit stat */
174 # warning FIXME: check whether struct stat32 definition is needed for this architecture!
175 # endif /* X86_64 || X32 || POWERPC64 */
176 #endif /* SUPPORTED_PERSONALITIES > 1 */
178 #ifdef STAT32_PERSONALITY
179 # define DO_PRINTSTAT do_printstat32
180 # define STRUCT_STAT struct stat32
181 # undef HAVE_STRUCT_STAT_ST_FLAGS
182 # undef HAVE_STRUCT_STAT_ST_FSTYPE
183 # undef HAVE_STRUCT_STAT_ST_GEN
184 # include "printstat.h"
185 #endif /* STAT32_PERSONALITY */
187 #if defined(SPARC) || defined(SPARC64)
191 unsigned int st_pad1[3]; /* network id */
198 unsigned int st_pad2[2];
199 unsigned int st_size;
200 unsigned int st_pad3; /* st_size, off_t expansion */
201 unsigned int st_atime;
202 unsigned int st_atime_nsec;
203 unsigned int st_mtime;
204 unsigned int st_mtime_nsec;
205 unsigned int st_ctime;
206 unsigned int st_ctime_nsec;
207 unsigned int st_blksize;
208 unsigned int st_blocks;
210 unsigned int st_pad4[8]; /* expansion area */
213 # define DO_PRINTSTAT do_printstat_sol
214 # define STRUCT_STAT struct solstat
215 # define STAT_MAJOR(x) (((x) >> 18) & 0x3fff)
216 # define STAT_MINOR(x) ((x) & 0x3ffff)
217 # undef HAVE_STRUCT_STAT_ST_FLAGS
218 # undef HAVE_STRUCT_STAT_ST_FSTYPE
219 # undef HAVE_STRUCT_STAT_ST_GEN
220 # include "printstat.h"
221 #endif /* SPARC || SPARC64 */
224 printstat(struct tcb *tcp, long addr)
228 #ifdef STAT32_PERSONALITY
229 if (current_personality == STAT32_PERSONALITY) {
230 struct stat32 statbuf;
232 if (!umove_or_printaddr(tcp, addr, &statbuf))
233 do_printstat32(tcp, &statbuf);
238 #if defined(SPARC) || defined(SPARC64)
239 if (current_personality == 1) {
240 struct solstat statbuf;
242 if (!umove_or_printaddr(tcp, addr, &statbuf))
243 do_printstat_sol(tcp, &statbuf);
246 #endif /* SPARC || SPARC64 */
248 if (!umove_or_printaddr(tcp, addr, &statbuf))
249 do_printstat(tcp, &statbuf);
255 printpath(tcp, tcp->u_arg[0]);
258 printstat(tcp, tcp->u_arg[1]);
266 printfd(tcp, tcp->u_arg[0]);
269 printstat(tcp, tcp->u_arg[1]);
274 #if defined STAT32_PERSONALITY && !defined HAVE_STRUCT_STAT64
275 # if defined AARCH64 || defined X86_64 || defined X32
277 * Linux x86_64 and x32 have unified `struct stat' but their i386 personality
278 * needs `struct stat64'.
279 * linux/arch/x86/include/uapi/asm/stat.h defines `struct stat64' only for i386.
281 * Similarly, aarch64 has a unified `struct stat' but its arm personality
282 * needs `struct stat64' (unlike x86, it shouldn't be packed).
285 unsigned long long st_dev;
286 unsigned char __pad0[4];
287 unsigned int __st_ino;
288 unsigned int st_mode;
289 unsigned int st_nlink;
292 unsigned long long st_rdev;
293 unsigned char __pad3[4];
295 unsigned int st_blksize;
296 unsigned long long st_blocks;
297 unsigned int st_atime;
298 unsigned int st_atime_nsec;
299 unsigned int st_mtime;
300 unsigned int st_mtime_nsec;
301 unsigned int st_ctime;
302 unsigned int st_ctime_nsec;
303 unsigned long long st_ino;
305 # if defined X86_64 || defined X32
307 # define STAT64_SIZE 96
309 # define STAT64_SIZE 104
312 # define HAVE_STRUCT_STAT64 1
313 # else /* !(AARCH64 || X86_64 || X32) */
314 # warning FIXME: check whether struct stat64 definition is needed for this architecture!
316 #endif /* STAT32_PERSONALITY && !HAVE_STRUCT_STAT64 */
318 #ifdef HAVE_STRUCT_STAT64
320 # define DO_PRINTSTAT do_printstat64
321 # define STRUCT_STAT struct stat64
322 # undef HAVE_STRUCT_STAT_ST_FLAGS
323 # undef HAVE_STRUCT_STAT_ST_FSTYPE
324 # undef HAVE_STRUCT_STAT_ST_GEN
325 # include "printstat.h"
328 printstat64(struct tcb *tcp, long addr)
330 struct stat64 statbuf;
333 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
336 # ifdef STAT32_PERSONALITY
337 if (current_personality != STAT32_PERSONALITY) {
338 printstat(tcp, addr);
341 # endif /* STAT32_PERSONALITY */
343 if (!umove_or_printaddr(tcp, addr, &statbuf))
344 do_printstat64(tcp, &statbuf);
350 printpath(tcp, tcp->u_arg[0]);
353 printstat64(tcp, tcp->u_arg[1]);
361 printfd(tcp, tcp->u_arg[0]);
364 printstat64(tcp, tcp->u_arg[1]);
373 return sys_stat(tcp);
378 return sys_fstat(tcp);
381 #endif /* HAVE_STRUCT_STAT64 */
386 print_dirfd(tcp, tcp->u_arg[0]);
387 printpath(tcp, tcp->u_arg[1]);
390 #if defined STAT32_PERSONALITY
391 if (current_personality == STAT32_PERSONALITY)
392 printstat64(tcp, tcp->u_arg[2]);
394 printstat(tcp, tcp->u_arg[2]);
395 #elif defined HAVE_STRUCT_STAT64
396 printstat64(tcp, tcp->u_arg[2]);
398 printstat(tcp, tcp->u_arg[2]);
399 #endif /* STAT32_PERSONALITY || HAVE_STRUCT_STAT64 */
401 printflags(at_flags, tcp->u_arg[3], "AT_???");
406 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
409 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
411 memset(newbuf, 0, sizeof(*newbuf));
412 newbuf->st_dev = oldbuf->st_dev;
413 newbuf->st_ino = oldbuf->st_ino;
414 newbuf->st_mode = oldbuf->st_mode;
415 newbuf->st_nlink = oldbuf->st_nlink;
416 newbuf->st_uid = oldbuf->st_uid;
417 newbuf->st_gid = oldbuf->st_gid;
418 newbuf->st_rdev = oldbuf->st_rdev;
419 newbuf->st_size = oldbuf->st_size;
420 newbuf->st_atime = oldbuf->st_atime;
421 newbuf->st_mtime = oldbuf->st_mtime;
422 newbuf->st_ctime = oldbuf->st_ctime;
426 printoldstat(struct tcb *tcp, long addr)
428 struct __old_kernel_stat statbuf;
429 struct stat newstatbuf;
431 # if defined(SPARC) || defined(SPARC64)
432 if (current_personality == 1) {
433 struct solstat statbuf;
435 if (!umove_or_printaddr(tcp, addr, &statbuf))
436 do_printstat_sol(tcp, &statbuf);
441 if (!umove_or_printaddr(tcp, addr, &statbuf)) {
442 convertoldstat(&statbuf, &newstatbuf);
443 do_printstat(tcp, &newstatbuf);
450 printpath(tcp, tcp->u_arg[0]);
453 printoldstat(tcp, tcp->u_arg[1]);
461 printfd(tcp, tcp->u_arg[0]);
464 printoldstat(tcp, tcp->u_arg[1]);
469 #endif /* HAVE_STRUCT___OLD_KERNEL_STAT */
471 #if defined(SPARC) || defined(SPARC64)
476 tprintf("%ld, ", tcp->u_arg[0]);
477 printpath(tcp, tcp->u_arg[1]);
480 printstat(tcp, tcp->u_arg[2]);
488 tprintf("%ld, ", tcp->u_arg[0]);
489 printfd(tcp, tcp->u_arg[1]);
492 printstat(tcp, tcp->u_arg[2]);
497 #endif /* SPARC || SPARC64 */