Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 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 Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 5 | * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 6 | * 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 Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 29 | */ |
| 30 | |
| 31 | #include "defs.h" |
Roland McGrath | c531e57 | 2008-08-01 01:13:10 +0000 | [diff] [blame] | 32 | |
Denys Vlasenko | 9472a27 | 2013-02-12 11:43:46 +0100 | [diff] [blame] | 33 | #if defined(SPARC) || defined(SPARC64) |
Wichert Akkerman | dacfb6e | 1999-06-03 14:21:07 +0000 | [diff] [blame] | 34 | struct stat { |
| 35 | unsigned short st_dev; |
| 36 | unsigned int st_ino; |
| 37 | unsigned short st_mode; |
| 38 | short st_nlink; |
| 39 | unsigned short st_uid; |
| 40 | unsigned short st_gid; |
| 41 | unsigned short st_rdev; |
| 42 | unsigned int st_size; |
| 43 | int st_atime; |
| 44 | unsigned int __unused1; |
| 45 | int st_mtime; |
| 46 | unsigned int __unused2; |
| 47 | int st_ctime; |
| 48 | unsigned int __unused3; |
| 49 | int st_blksize; |
| 50 | int st_blocks; |
| 51 | unsigned int __unused4[2]; |
| 52 | }; |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 53 | # if defined(SPARC64) |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 54 | struct stat_sparc64 { |
| 55 | unsigned int st_dev; |
| 56 | unsigned long st_ino; |
| 57 | unsigned int st_mode; |
| 58 | unsigned int st_nlink; |
| 59 | unsigned int st_uid; |
| 60 | unsigned int st_gid; |
| 61 | unsigned int st_rdev; |
| 62 | long st_size; |
| 63 | long st_atime; |
| 64 | long st_mtime; |
| 65 | long st_ctime; |
| 66 | long st_blksize; |
| 67 | long st_blocks; |
| 68 | unsigned long __unused4[2]; |
| 69 | }; |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 70 | # endif /* SPARC64 */ |
| 71 | # define stat kernel_stat |
| 72 | # include <asm/stat.h> |
| 73 | # undef stat |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 74 | #elif defined(X32) |
| 75 | struct stat { |
| 76 | unsigned long long st_dev; |
| 77 | unsigned long long st_ino; |
| 78 | unsigned long long st_nlink; |
| 79 | |
| 80 | unsigned int st_mode; |
| 81 | unsigned int st_uid; |
| 82 | unsigned int st_gid; |
| 83 | unsigned int __pad0; |
| 84 | unsigned long long st_rdev; |
| 85 | long long st_size; |
| 86 | long long st_blksize; |
| 87 | long long st_blocks; |
| 88 | |
| 89 | unsigned long long st_atime; |
| 90 | unsigned long long st_atime_nsec; |
| 91 | unsigned long long st_mtime; |
| 92 | unsigned long long st_mtime_nsec; |
| 93 | unsigned long long st_ctime; |
| 94 | unsigned long long st_ctime_nsec; |
| 95 | long long __unused[3]; |
| 96 | }; |
H.J. Lu | 085e428 | 2012-04-17 11:05:04 -0700 | [diff] [blame] | 97 | |
| 98 | struct stat64 { |
| 99 | unsigned long long st_dev; |
| 100 | unsigned char __pad0[4]; |
| 101 | unsigned long __st_ino; |
| 102 | unsigned int st_mode; |
| 103 | unsigned int st_nlink; |
| 104 | unsigned long st_uid; |
| 105 | unsigned long st_gid; |
| 106 | unsigned long long st_rdev; |
| 107 | unsigned char __pad3[4]; |
| 108 | long long st_size; |
| 109 | unsigned long st_blksize; |
| 110 | unsigned long long st_blocks; |
| 111 | unsigned long st_atime; |
| 112 | unsigned long st_atime_nsec; |
| 113 | unsigned long st_mtime; |
| 114 | unsigned int st_mtime_nsec; |
| 115 | unsigned long st_ctime; |
| 116 | unsigned long st_ctime_nsec; |
| 117 | unsigned long long st_ino; |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 118 | } __attribute__((packed)); |
| 119 | # define HAVE_STAT64 1 |
Dmitry V. Levin | bd2e28a | 2013-05-01 15:14:25 +0000 | [diff] [blame] | 120 | |
| 121 | struct __old_kernel_stat { |
| 122 | unsigned short st_dev; |
| 123 | unsigned short st_ino; |
| 124 | unsigned short st_mode; |
| 125 | unsigned short st_nlink; |
| 126 | unsigned short st_uid; |
| 127 | unsigned short st_gid; |
| 128 | unsigned short st_rdev; |
| 129 | unsigned int st_size; |
| 130 | unsigned int st_atime; |
| 131 | unsigned int st_mtime; |
| 132 | unsigned int st_ctime; |
| 133 | }; |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 134 | #else |
| 135 | # undef dev_t |
| 136 | # undef ino_t |
| 137 | # undef mode_t |
| 138 | # undef nlink_t |
| 139 | # undef uid_t |
| 140 | # undef gid_t |
| 141 | # undef off_t |
| 142 | # undef loff_t |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 143 | # define dev_t __kernel_dev_t |
| 144 | # define ino_t __kernel_ino_t |
| 145 | # define mode_t __kernel_mode_t |
| 146 | # define nlink_t __kernel_nlink_t |
| 147 | # define uid_t __kernel_uid_t |
| 148 | # define gid_t __kernel_gid_t |
| 149 | # define off_t __kernel_off_t |
| 150 | # define loff_t __kernel_loff_t |
Wichert Akkerman | a601370 | 1999-07-08 14:00:58 +0000 | [diff] [blame] | 151 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 152 | # include <asm/stat.h> |
Wichert Akkerman | a601370 | 1999-07-08 14:00:58 +0000 | [diff] [blame] | 153 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 154 | # undef dev_t |
| 155 | # undef ino_t |
| 156 | # undef mode_t |
| 157 | # undef nlink_t |
| 158 | # undef uid_t |
| 159 | # undef gid_t |
| 160 | # undef off_t |
| 161 | # undef loff_t |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 162 | # define dev_t dev_t |
| 163 | # define ino_t ino_t |
| 164 | # define mode_t mode_t |
| 165 | # define nlink_t nlink_t |
| 166 | # define uid_t uid_t |
| 167 | # define gid_t gid_t |
| 168 | # define off_t off_t |
| 169 | # define loff_t loff_t |
| 170 | #endif |
| 171 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 172 | #define stat libc_stat |
| 173 | #define stat64 libc_stat64 |
| 174 | #include <sys/stat.h> |
| 175 | #undef stat |
| 176 | #undef stat64 |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 177 | /* These might be macros. */ |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 178 | #undef st_atime |
| 179 | #undef st_mtime |
| 180 | #undef st_ctime |
Wichert Akkerman | d4d8e92 | 1999-04-18 23:30:29 +0000 | [diff] [blame] | 181 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 182 | #ifdef MAJOR_IN_SYSMACROS |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 183 | # include <sys/sysmacros.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 184 | #endif |
| 185 | |
| 186 | #ifdef MAJOR_IN_MKDEV |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 187 | # include <sys/mkdev.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 188 | #endif |
| 189 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 190 | /* several stats */ |
| 191 | |
Denys Vlasenko | 9472a27 | 2013-02-12 11:43:46 +0100 | [diff] [blame] | 192 | #if defined(SPARC) || defined(SPARC64) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 193 | typedef struct { |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 194 | int tv_sec; |
| 195 | int tv_nsec; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 196 | } timestruct_t; |
| 197 | |
| 198 | struct solstat { |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 199 | unsigned st_dev; |
| 200 | int st_pad1[3]; /* network id */ |
| 201 | unsigned st_ino; |
| 202 | unsigned st_mode; |
| 203 | unsigned st_nlink; |
| 204 | unsigned st_uid; |
| 205 | unsigned st_gid; |
| 206 | unsigned st_rdev; |
| 207 | int st_pad2[2]; |
| 208 | int st_size; |
| 209 | int st_pad3; /* st_size, off_t expansion */ |
| 210 | timestruct_t st_atime; |
| 211 | timestruct_t st_mtime; |
| 212 | timestruct_t st_ctime; |
| 213 | int st_blksize; |
| 214 | int st_blocks; |
| 215 | char st_fstype[16]; |
| 216 | int st_pad4[8]; /* expansion area */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 217 | }; |
| 218 | |
| 219 | static void |
Dmitry V. Levin | b838b1e | 2008-04-19 23:47:47 +0000 | [diff] [blame] | 220 | printstatsol(struct tcb *tcp, long addr) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 221 | { |
| 222 | struct solstat statbuf; |
| 223 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 224 | if (umove(tcp, addr, &statbuf) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 225 | tprints("{...}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 226 | return; |
| 227 | } |
| 228 | if (!abbrev(tcp)) { |
| 229 | tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ", |
| 230 | (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff), |
| 231 | (unsigned long) (statbuf.st_dev & 0x3ffff), |
| 232 | (unsigned long) statbuf.st_ino, |
| 233 | sprintmode(statbuf.st_mode)); |
| 234 | tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ", |
| 235 | (unsigned long) statbuf.st_nlink, |
| 236 | (unsigned long) statbuf.st_uid, |
| 237 | (unsigned long) statbuf.st_gid); |
| 238 | tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize); |
| 239 | tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks); |
| 240 | } |
| 241 | else |
| 242 | tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode)); |
| 243 | switch (statbuf.st_mode & S_IFMT) { |
| 244 | case S_IFCHR: case S_IFBLK: |
| 245 | tprintf("st_rdev=makedev(%lu, %lu), ", |
| 246 | (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff), |
| 247 | (unsigned long) (statbuf.st_rdev & 0x3ffff)); |
| 248 | break; |
| 249 | default: |
| 250 | tprintf("st_size=%u, ", statbuf.st_size); |
| 251 | break; |
| 252 | } |
| 253 | if (!abbrev(tcp)) { |
Dmitry V. Levin | b838b1e | 2008-04-19 23:47:47 +0000 | [diff] [blame] | 254 | tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec)); |
| 255 | tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec)); |
| 256 | tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 257 | } |
| 258 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 259 | tprints("...}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 260 | } |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 261 | |
Denys Vlasenko | 9472a27 | 2013-02-12 11:43:46 +0100 | [diff] [blame] | 262 | # if defined(SPARC64) |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 263 | static void |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 264 | printstat_sparc64(struct tcb *tcp, long addr) |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 265 | { |
| 266 | struct stat_sparc64 statbuf; |
| 267 | |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 268 | if (umove(tcp, addr, &statbuf) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 269 | tprints("{...}"); |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 270 | return; |
| 271 | } |
| 272 | |
| 273 | if (!abbrev(tcp)) { |
| 274 | tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ", |
| 275 | (unsigned long) major(statbuf.st_dev), |
| 276 | (unsigned long) minor(statbuf.st_dev), |
| 277 | (unsigned long) statbuf.st_ino, |
| 278 | sprintmode(statbuf.st_mode)); |
| 279 | tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ", |
| 280 | (unsigned long) statbuf.st_nlink, |
| 281 | (unsigned long) statbuf.st_uid, |
| 282 | (unsigned long) statbuf.st_gid); |
| 283 | tprintf("st_blksize=%lu, ", |
| 284 | (unsigned long) statbuf.st_blksize); |
| 285 | tprintf("st_blocks=%lu, ", |
| 286 | (unsigned long) statbuf.st_blocks); |
| 287 | } |
| 288 | else |
| 289 | tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode)); |
| 290 | switch (statbuf.st_mode & S_IFMT) { |
| 291 | case S_IFCHR: case S_IFBLK: |
| 292 | tprintf("st_rdev=makedev(%lu, %lu), ", |
| 293 | (unsigned long) major(statbuf.st_rdev), |
| 294 | (unsigned long) minor(statbuf.st_rdev)); |
| 295 | break; |
| 296 | default: |
| 297 | tprintf("st_size=%lu, ", statbuf.st_size); |
| 298 | break; |
| 299 | } |
| 300 | if (!abbrev(tcp)) { |
| 301 | tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime)); |
| 302 | tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime)); |
Denys Vlasenko | 1945ccc | 2012-02-27 14:37:48 +0100 | [diff] [blame] | 303 | tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime)); |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 304 | } |
| 305 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 306 | tprints("...}"); |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 307 | } |
Denys Vlasenko | 9472a27 | 2013-02-12 11:43:46 +0100 | [diff] [blame] | 308 | # endif /* SPARC64 */ |
| 309 | #endif /* SPARC[64] */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 310 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 311 | #if defined POWERPC64 |
Andreas Schwab | d69fa49 | 2010-07-12 21:39:57 +0200 | [diff] [blame] | 312 | struct stat_powerpc32 { |
| 313 | unsigned int st_dev; |
| 314 | unsigned int st_ino; |
| 315 | unsigned int st_mode; |
| 316 | unsigned short st_nlink; |
| 317 | unsigned int st_uid; |
| 318 | unsigned int st_gid; |
| 319 | unsigned int st_rdev; |
| 320 | unsigned int st_size; |
| 321 | unsigned int st_blksize; |
| 322 | unsigned int 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 int __unused4; |
| 330 | unsigned int __unused5; |
| 331 | }; |
| 332 | |
| 333 | static void |
| 334 | printstat_powerpc32(struct tcb *tcp, long addr) |
| 335 | { |
| 336 | struct stat_powerpc32 statbuf; |
| 337 | |
| 338 | if (umove(tcp, addr, &statbuf) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 339 | tprints("{...}"); |
Andreas Schwab | d69fa49 | 2010-07-12 21:39:57 +0200 | [diff] [blame] | 340 | return; |
| 341 | } |
| 342 | |
| 343 | if (!abbrev(tcp)) { |
| 344 | tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ", |
| 345 | major(statbuf.st_dev), minor(statbuf.st_dev), |
| 346 | statbuf.st_ino, |
| 347 | sprintmode(statbuf.st_mode)); |
| 348 | tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ", |
| 349 | statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid); |
| 350 | tprintf("st_blksize=%u, ", statbuf.st_blksize); |
| 351 | tprintf("st_blocks=%u, ", statbuf.st_blocks); |
| 352 | } |
| 353 | else |
| 354 | tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode)); |
| 355 | switch (statbuf.st_mode & S_IFMT) { |
| 356 | case S_IFCHR: case S_IFBLK: |
| 357 | tprintf("st_rdev=makedev(%lu, %lu), ", |
| 358 | (unsigned long) major(statbuf.st_rdev), |
| 359 | (unsigned long) minor(statbuf.st_rdev)); |
| 360 | break; |
| 361 | default: |
| 362 | tprintf("st_size=%u, ", statbuf.st_size); |
| 363 | break; |
| 364 | } |
| 365 | if (!abbrev(tcp)) { |
| 366 | tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime)); |
| 367 | tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime)); |
Denys Vlasenko | 1945ccc | 2012-02-27 14:37:48 +0100 | [diff] [blame] | 368 | tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime)); |
Andreas Schwab | d69fa49 | 2010-07-12 21:39:57 +0200 | [diff] [blame] | 369 | } |
| 370 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 371 | tprints("...}"); |
Andreas Schwab | d69fa49 | 2010-07-12 21:39:57 +0200 | [diff] [blame] | 372 | } |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 373 | #endif /* POWERPC64 */ |
Andreas Schwab | d69fa49 | 2010-07-12 21:39:57 +0200 | [diff] [blame] | 374 | |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 375 | static void |
Dmitry V. Levin | d01f0a8 | 2014-12-28 18:00:39 +0000 | [diff] [blame^] | 376 | do_printstat(struct tcb *tcp, struct stat *statbuf) |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 377 | { |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 378 | if (!abbrev(tcp)) { |
Dmitry V. Levin | d01f0a8 | 2014-12-28 18:00:39 +0000 | [diff] [blame^] | 379 | tprintf("{st_dev=makedev(%u, %u), st_ino=%llu, st_mode=%s, ", |
| 380 | (unsigned int) major(statbuf->st_dev), |
| 381 | (unsigned int) minor(statbuf->st_dev), |
| 382 | (unsigned long long) statbuf->st_ino, |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 383 | sprintmode(statbuf->st_mode)); |
Dmitry V. Levin | d01f0a8 | 2014-12-28 18:00:39 +0000 | [diff] [blame^] | 384 | tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ", |
| 385 | (unsigned int) statbuf->st_nlink, |
| 386 | (unsigned int) statbuf->st_uid, |
| 387 | (unsigned int) statbuf->st_gid); |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 388 | #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE |
Dmitry V. Levin | d01f0a8 | 2014-12-28 18:00:39 +0000 | [diff] [blame^] | 389 | tprintf("st_blksize=%u, ", (unsigned int) statbuf->st_blksize); |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 390 | #endif |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 391 | #ifdef HAVE_STRUCT_STAT_ST_BLOCKS |
Dmitry V. Levin | d01f0a8 | 2014-12-28 18:00:39 +0000 | [diff] [blame^] | 392 | tprintf("st_blocks=%llu, ", |
| 393 | (unsigned long long) statbuf->st_blocks); |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 394 | #endif |
| 395 | } |
| 396 | else |
| 397 | tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode)); |
| 398 | switch (statbuf->st_mode & S_IFMT) { |
| 399 | case S_IFCHR: case S_IFBLK: |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 400 | #ifdef HAVE_STRUCT_STAT_ST_RDEV |
Dmitry V. Levin | d01f0a8 | 2014-12-28 18:00:39 +0000 | [diff] [blame^] | 401 | tprintf("st_rdev=makedev(%u, %u), ", |
| 402 | (unsigned int) major(statbuf->st_rdev), |
| 403 | (unsigned int) minor(statbuf->st_rdev)); |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 404 | #else /* !HAVE_STRUCT_STAT_ST_RDEV */ |
Dmitry V. Levin | d01f0a8 | 2014-12-28 18:00:39 +0000 | [diff] [blame^] | 405 | tprintf("st_size=makedev(%u, %u), ", |
| 406 | (unsigned int) major(statbuf->st_size), |
| 407 | (unsigned int) minor(statbuf->st_size)); |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 408 | #endif /* !HAVE_STRUCT_STAT_ST_RDEV */ |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 409 | break; |
| 410 | default: |
Dmitry V. Levin | d01f0a8 | 2014-12-28 18:00:39 +0000 | [diff] [blame^] | 411 | tprintf("st_size=%llu, ", |
| 412 | (unsigned long long) statbuf->st_size); |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 413 | break; |
| 414 | } |
| 415 | if (!abbrev(tcp)) { |
| 416 | tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime)); |
| 417 | tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime)); |
| 418 | tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime)); |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 419 | #if HAVE_STRUCT_STAT_ST_FLAGS |
Dmitry V. Levin | d01f0a8 | 2014-12-28 18:00:39 +0000 | [diff] [blame^] | 420 | tprintf(", st_flags=%u", (unsigned int) statbuf->st_flags); |
John Hughes | c0fc3fd | 2001-03-08 16:10:40 +0000 | [diff] [blame] | 421 | #endif |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 422 | #if HAVE_STRUCT_STAT_ST_FSTYPE |
John Hughes | c0fc3fd | 2001-03-08 16:10:40 +0000 | [diff] [blame] | 423 | tprintf(", st_fstype=%.*s", |
| 424 | (int) sizeof statbuf->st_fstype, statbuf->st_fstype); |
| 425 | #endif |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 426 | #if HAVE_STRUCT_STAT_ST_GEN |
Dmitry V. Levin | d01f0a8 | 2014-12-28 18:00:39 +0000 | [diff] [blame^] | 427 | tprintf(", st_gen=%u", (unsigned int) statbuf->st_gen); |
John Hughes | c0fc3fd | 2001-03-08 16:10:40 +0000 | [diff] [blame] | 428 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 429 | tprints("}"); |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 430 | } |
| 431 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 432 | tprints("...}"); |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 433 | } |
| 434 | |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 435 | #ifndef X32 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 436 | static void |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 437 | printstat(struct tcb *tcp, long addr) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 438 | { |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 439 | struct stat statbuf; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 440 | |
Denys Vlasenko | 4e718b5 | 2009-04-20 18:30:13 +0000 | [diff] [blame] | 441 | if (!addr) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 442 | tprints("NULL"); |
Denys Vlasenko | 4e718b5 | 2009-04-20 18:30:13 +0000 | [diff] [blame] | 443 | return; |
| 444 | } |
| 445 | if (syserror(tcp) || !verbose(tcp)) { |
| 446 | tprintf("%#lx", addr); |
| 447 | return; |
| 448 | } |
| 449 | |
Denys Vlasenko | 9472a27 | 2013-02-12 11:43:46 +0100 | [diff] [blame] | 450 | #if defined(SPARC) || defined(SPARC64) |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 451 | if (current_personality == 1) { |
| 452 | printstatsol(tcp, addr); |
| 453 | return; |
| 454 | } |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 455 | #ifdef SPARC64 |
| 456 | else if (current_personality == 2) { |
| 457 | printstat_sparc64(tcp, addr); |
| 458 | return; |
| 459 | } |
| 460 | #endif |
Denys Vlasenko | 9472a27 | 2013-02-12 11:43:46 +0100 | [diff] [blame] | 461 | #endif /* SPARC[64] */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 462 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 463 | #if defined POWERPC64 |
Andreas Schwab | d69fa49 | 2010-07-12 21:39:57 +0200 | [diff] [blame] | 464 | if (current_personality == 1) { |
| 465 | printstat_powerpc32(tcp, addr); |
| 466 | return; |
| 467 | } |
| 468 | #endif |
| 469 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 470 | if (umove(tcp, addr, &statbuf) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 471 | tprints("{...}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 472 | return; |
| 473 | } |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 474 | |
Dmitry V. Levin | d01f0a8 | 2014-12-28 18:00:39 +0000 | [diff] [blame^] | 475 | do_printstat(tcp, &statbuf); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 476 | } |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 477 | #else /* X32 */ |
| 478 | # define printstat printstat64 |
| 479 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 480 | |
Elliott Hughes | 391c0d8 | 2014-04-03 17:50:14 -0700 | [diff] [blame] | 481 | #if !defined HAVE_STAT64 && (defined AARCH64 || defined X86_64) |
Roland McGrath | e6d0f71 | 2007-08-07 01:22:49 +0000 | [diff] [blame] | 482 | /* |
| 483 | * Linux x86_64 has unified `struct stat' but its i386 biarch needs |
| 484 | * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'. |
| 485 | * <linux/include/asm-x86_64/ia32.h> is not in the public includes set. |
| 486 | * __GNUC__ is needed for the required __attribute__ below. |
Elliott Hughes | 391c0d8 | 2014-04-03 17:50:14 -0700 | [diff] [blame] | 487 | * |
| 488 | * Similarly, aarch64 has a unified `struct stat' but its arm personality |
| 489 | * needs `struct stat64' (which also expects a 32-bit `long' but which |
| 490 | * shouldn't be packed). |
Roland McGrath | e6d0f71 | 2007-08-07 01:22:49 +0000 | [diff] [blame] | 491 | */ |
| 492 | struct stat64 { |
| 493 | unsigned long long st_dev; |
| 494 | unsigned char __pad0[4]; |
| 495 | unsigned int __st_ino; |
| 496 | unsigned int st_mode; |
| 497 | unsigned int st_nlink; |
| 498 | unsigned int st_uid; |
| 499 | unsigned int st_gid; |
| 500 | unsigned long long st_rdev; |
| 501 | unsigned char __pad3[4]; |
| 502 | long long st_size; |
| 503 | unsigned int st_blksize; |
| 504 | unsigned long long st_blocks; |
| 505 | unsigned int st_atime; |
| 506 | unsigned int st_atime_nsec; |
| 507 | unsigned int st_mtime; |
| 508 | unsigned int st_mtime_nsec; |
| 509 | unsigned int st_ctime; |
| 510 | unsigned int st_ctime_nsec; |
| 511 | unsigned long long st_ino; |
Elliott Hughes | 391c0d8 | 2014-04-03 17:50:14 -0700 | [diff] [blame] | 512 | } |
| 513 | # if defined X86_64 |
| 514 | __attribute__((packed)) |
| 515 | # define STAT64_SIZE 96 |
| 516 | #else |
| 517 | # define STAT64_SIZE 104 |
| 518 | # endif |
| 519 | ; |
Roland McGrath | e6d0f71 | 2007-08-07 01:22:49 +0000 | [diff] [blame] | 520 | # define HAVE_STAT64 1 |
Roland McGrath | e6d0f71 | 2007-08-07 01:22:49 +0000 | [diff] [blame] | 521 | #endif |
| 522 | |
Wichert Akkerman | c792698 | 2000-04-10 22:22:31 +0000 | [diff] [blame] | 523 | #ifdef HAVE_STAT64 |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 524 | static void |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 525 | printstat64(struct tcb *tcp, long addr) |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 526 | { |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 527 | #ifdef X32 |
| 528 | struct stat statbuf; |
| 529 | #else |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 530 | struct stat64 statbuf; |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 531 | #endif |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 532 | |
Denys Vlasenko | 4e718b5 | 2009-04-20 18:30:13 +0000 | [diff] [blame] | 533 | #ifdef STAT64_SIZE |
Roland McGrath | e6d0f71 | 2007-08-07 01:22:49 +0000 | [diff] [blame] | 534 | (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]); |
| 535 | #endif |
| 536 | |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 537 | if (!addr) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 538 | tprints("NULL"); |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 539 | return; |
| 540 | } |
| 541 | if (syserror(tcp) || !verbose(tcp)) { |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 542 | tprintf("%#lx", addr); |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 543 | return; |
| 544 | } |
Denys Vlasenko | 4e718b5 | 2009-04-20 18:30:13 +0000 | [diff] [blame] | 545 | |
Denys Vlasenko | 9472a27 | 2013-02-12 11:43:46 +0100 | [diff] [blame] | 546 | #if defined(SPARC) || defined(SPARC64) |
Denys Vlasenko | 4e718b5 | 2009-04-20 18:30:13 +0000 | [diff] [blame] | 547 | if (current_personality == 1) { |
| 548 | printstatsol(tcp, addr); |
| 549 | return; |
| 550 | } |
| 551 | # ifdef SPARC64 |
| 552 | else if (current_personality == 2) { |
| 553 | printstat_sparc64(tcp, addr); |
| 554 | return; |
| 555 | } |
| 556 | # endif |
Denys Vlasenko | 9472a27 | 2013-02-12 11:43:46 +0100 | [diff] [blame] | 557 | #endif /* SPARC[64] */ |
Denys Vlasenko | 4e718b5 | 2009-04-20 18:30:13 +0000 | [diff] [blame] | 558 | |
Elliott Hughes | 391c0d8 | 2014-04-03 17:50:14 -0700 | [diff] [blame] | 559 | #if defined AARCH64 |
| 560 | if (current_personality != 0) { |
| 561 | printstat(tcp, addr); |
| 562 | return; |
| 563 | } |
| 564 | #endif |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 565 | #if defined X86_64 |
H.J. Lu | 35be581 | 2012-04-16 13:00:01 +0200 | [diff] [blame] | 566 | if (current_personality != 1) { |
Andreas Schwab | 61b7435 | 2009-10-16 11:37:13 +0200 | [diff] [blame] | 567 | printstat(tcp, addr); |
| 568 | return; |
| 569 | } |
| 570 | #endif |
Dmitry V. Levin | ff896f7 | 2009-10-21 13:43:57 +0000 | [diff] [blame] | 571 | |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 572 | if (umove(tcp, addr, &statbuf) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 573 | tprints("{...}"); |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 574 | return; |
| 575 | } |
| 576 | |
| 577 | if (!abbrev(tcp)) { |
Wichert Akkerman | d077c45 | 2000-08-10 18:16:15 +0000 | [diff] [blame] | 578 | tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ", |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 579 | (unsigned long) major(statbuf.st_dev), |
| 580 | (unsigned long) minor(statbuf.st_dev), |
Wichert Akkerman | d077c45 | 2000-08-10 18:16:15 +0000 | [diff] [blame] | 581 | (unsigned long long) statbuf.st_ino, |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 582 | sprintmode(statbuf.st_mode)); |
| 583 | tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ", |
| 584 | (unsigned long) statbuf.st_nlink, |
| 585 | (unsigned long) statbuf.st_uid, |
| 586 | (unsigned long) statbuf.st_gid); |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 587 | #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 588 | tprintf("st_blksize=%lu, ", |
| 589 | (unsigned long) statbuf.st_blksize); |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 590 | #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */ |
| 591 | #ifdef HAVE_STRUCT_STAT_ST_BLOCKS |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 592 | tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks); |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 593 | #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */ |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 594 | } |
| 595 | else |
| 596 | tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode)); |
| 597 | switch (statbuf.st_mode & S_IFMT) { |
| 598 | case S_IFCHR: case S_IFBLK: |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 599 | #ifdef HAVE_STRUCT_STAT_ST_RDEV |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 600 | tprintf("st_rdev=makedev(%lu, %lu), ", |
| 601 | (unsigned long) major(statbuf.st_rdev), |
| 602 | (unsigned long) minor(statbuf.st_rdev)); |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 603 | #else /* !HAVE_STRUCT_STAT_ST_RDEV */ |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 604 | tprintf("st_size=makedev(%lu, %lu), ", |
| 605 | (unsigned long) major(statbuf.st_size), |
| 606 | (unsigned long) minor(statbuf.st_size)); |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 607 | #endif /* !HAVE_STRUCT_STAT_ST_RDEV */ |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 608 | break; |
| 609 | default: |
Roland McGrath | c7bd4d3 | 2007-08-07 01:05:19 +0000 | [diff] [blame] | 610 | tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size); |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 611 | break; |
| 612 | } |
| 613 | if (!abbrev(tcp)) { |
| 614 | tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime)); |
| 615 | tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime)); |
John Hughes | c0fc3fd | 2001-03-08 16:10:40 +0000 | [diff] [blame] | 616 | tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime)); |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 617 | #if HAVE_STRUCT_STAT_ST_FLAGS |
Dmitry V. Levin | 2928afe | 2014-12-28 17:44:13 +0000 | [diff] [blame] | 618 | tprintf(", st_flags=%u", statbuf->st_flags); |
John Hughes | c0fc3fd | 2001-03-08 16:10:40 +0000 | [diff] [blame] | 619 | #endif |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 620 | #if HAVE_STRUCT_STAT_ST_FSTYPE |
John Hughes | c0fc3fd | 2001-03-08 16:10:40 +0000 | [diff] [blame] | 621 | tprintf(", st_fstype=%.*s", |
| 622 | (int) sizeof statbuf.st_fstype, statbuf.st_fstype); |
| 623 | #endif |
Roland McGrath | 6d2b349 | 2002-12-30 00:51:30 +0000 | [diff] [blame] | 624 | #if HAVE_STRUCT_STAT_ST_GEN |
John Hughes | c0fc3fd | 2001-03-08 16:10:40 +0000 | [diff] [blame] | 625 | tprintf(", st_gen=%u", statbuf.st_gen); |
| 626 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 627 | tprints("}"); |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 628 | } |
| 629 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 630 | tprints("...}"); |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 631 | } |
Wichert Akkerman | c792698 | 2000-04-10 22:22:31 +0000 | [diff] [blame] | 632 | #endif /* HAVE_STAT64 */ |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 633 | |
Denys Vlasenko | 8435d67 | 2013-02-18 15:47:57 +0100 | [diff] [blame] | 634 | #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 635 | static void |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 636 | convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf) |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 637 | { |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 638 | newbuf->st_dev = oldbuf->st_dev; |
| 639 | newbuf->st_ino = oldbuf->st_ino; |
| 640 | newbuf->st_mode = oldbuf->st_mode; |
| 641 | newbuf->st_nlink = oldbuf->st_nlink; |
| 642 | newbuf->st_uid = oldbuf->st_uid; |
| 643 | newbuf->st_gid = oldbuf->st_gid; |
| 644 | newbuf->st_rdev = oldbuf->st_rdev; |
| 645 | newbuf->st_size = oldbuf->st_size; |
| 646 | newbuf->st_atime = oldbuf->st_atime; |
| 647 | newbuf->st_mtime = oldbuf->st_mtime; |
| 648 | newbuf->st_ctime = oldbuf->st_ctime; |
| 649 | newbuf->st_blksize = 0; /* not supported in old_stat */ |
| 650 | newbuf->st_blocks = 0; /* not supported in old_stat */ |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 651 | } |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 652 | |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 653 | static void |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 654 | printoldstat(struct tcb *tcp, long addr) |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 655 | { |
Wichert Akkerman | 25d0c4f | 1999-04-18 19:35:42 +0000 | [diff] [blame] | 656 | struct __old_kernel_stat statbuf; |
| 657 | struct stat newstatbuf; |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 658 | |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 659 | if (!addr) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 660 | tprints("NULL"); |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 661 | return; |
| 662 | } |
| 663 | if (syserror(tcp) || !verbose(tcp)) { |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 664 | tprintf("%#lx", addr); |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 665 | return; |
| 666 | } |
Denys Vlasenko | 4e718b5 | 2009-04-20 18:30:13 +0000 | [diff] [blame] | 667 | |
Denys Vlasenko | 9472a27 | 2013-02-12 11:43:46 +0100 | [diff] [blame] | 668 | # if defined(SPARC) || defined(SPARC64) |
Denys Vlasenko | 4e718b5 | 2009-04-20 18:30:13 +0000 | [diff] [blame] | 669 | if (current_personality == 1) { |
| 670 | printstatsol(tcp, addr); |
| 671 | return; |
| 672 | } |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 673 | # endif |
Denys Vlasenko | 4e718b5 | 2009-04-20 18:30:13 +0000 | [diff] [blame] | 674 | |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 675 | if (umove(tcp, addr, &statbuf) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 676 | tprints("{...}"); |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 677 | return; |
| 678 | } |
| 679 | |
| 680 | convertoldstat(&statbuf, &newstatbuf); |
Dmitry V. Levin | d01f0a8 | 2014-12-28 18:00:39 +0000 | [diff] [blame^] | 681 | do_printstat(tcp, &newstatbuf); |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 682 | } |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 683 | #endif |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 684 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 685 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 686 | sys_stat(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 687 | { |
| 688 | if (entering(tcp)) { |
| 689 | printpath(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 690 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 691 | } else { |
| 692 | printstat(tcp, tcp->u_arg[1]); |
| 693 | } |
| 694 | return 0; |
| 695 | } |
| 696 | |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 697 | #ifdef X32 |
| 698 | static void |
| 699 | printstat64_x32(struct tcb *tcp, long addr) |
| 700 | { |
| 701 | struct stat64 statbuf; |
| 702 | |
| 703 | if (!addr) { |
| 704 | tprints("NULL"); |
| 705 | return; |
| 706 | } |
| 707 | if (syserror(tcp) || !verbose(tcp)) { |
| 708 | tprintf("%#lx", addr); |
| 709 | return; |
| 710 | } |
| 711 | |
| 712 | if (umove(tcp, addr, &statbuf) < 0) { |
| 713 | tprints("{...}"); |
| 714 | return; |
| 715 | } |
| 716 | |
| 717 | if (!abbrev(tcp)) { |
| 718 | tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ", |
| 719 | (unsigned long) major(statbuf.st_dev), |
| 720 | (unsigned long) minor(statbuf.st_dev), |
| 721 | (unsigned long long) statbuf.st_ino, |
| 722 | sprintmode(statbuf.st_mode)); |
| 723 | tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ", |
| 724 | (unsigned long) statbuf.st_nlink, |
| 725 | (unsigned long) statbuf.st_uid, |
| 726 | (unsigned long) statbuf.st_gid); |
| 727 | tprintf("st_blksize=%lu, ", |
| 728 | (unsigned long) statbuf.st_blksize); |
| 729 | tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks); |
| 730 | } |
| 731 | else |
| 732 | tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode)); |
| 733 | switch (statbuf.st_mode & S_IFMT) { |
| 734 | case S_IFCHR: case S_IFBLK: |
| 735 | tprintf("st_rdev=makedev(%lu, %lu), ", |
| 736 | (unsigned long) major(statbuf.st_rdev), |
| 737 | (unsigned long) minor(statbuf.st_rdev)); |
| 738 | break; |
| 739 | default: |
| 740 | tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size); |
| 741 | break; |
| 742 | } |
| 743 | if (!abbrev(tcp)) { |
| 744 | tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime)); |
| 745 | tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime)); |
| 746 | tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime)); |
| 747 | tprints("}"); |
| 748 | } |
| 749 | else |
| 750 | tprints("...}"); |
| 751 | } |
| 752 | #endif /* X32 */ |
| 753 | |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 754 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 755 | sys_stat64(struct tcb *tcp) |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 756 | { |
| 757 | #ifdef HAVE_STAT64 |
| 758 | if (entering(tcp)) { |
| 759 | printpath(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 760 | tprints(", "); |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 761 | } else { |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 762 | # ifdef X32 |
| 763 | printstat64_x32(tcp, tcp->u_arg[1]); |
| 764 | # else |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 765 | printstat64(tcp, tcp->u_arg[1]); |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 766 | # endif |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 767 | } |
| 768 | return 0; |
| 769 | #else |
| 770 | return printargs(tcp); |
| 771 | #endif |
| 772 | } |
| 773 | |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 774 | int |
| 775 | sys_newfstatat(struct tcb *tcp) |
| 776 | { |
| 777 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 778 | print_dirfd(tcp, tcp->u_arg[0]); |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 779 | printpath(tcp, tcp->u_arg[1]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 780 | tprints(", "); |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 781 | } else { |
Andreas Schwab | d69fa49 | 2010-07-12 21:39:57 +0200 | [diff] [blame] | 782 | #ifdef POWERPC64 |
| 783 | if (current_personality == 0) |
| 784 | printstat(tcp, tcp->u_arg[2]); |
| 785 | else |
| 786 | printstat64(tcp, tcp->u_arg[2]); |
| 787 | #elif defined HAVE_STAT64 |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 788 | printstat64(tcp, tcp->u_arg[2]); |
| 789 | #else |
| 790 | printstat(tcp, tcp->u_arg[2]); |
| 791 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 792 | tprints(", "); |
Dmitry V. Levin | 7989ad4 | 2012-03-13 23:26:01 +0000 | [diff] [blame] | 793 | printflags(at_flags, tcp->u_arg[3], "AT_???"); |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 794 | } |
| 795 | return 0; |
| 796 | } |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 797 | |
Denys Vlasenko | 8435d67 | 2013-02-18 15:47:57 +0100 | [diff] [blame] | 798 | #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 799 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 800 | sys_oldstat(struct tcb *tcp) |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 801 | { |
| 802 | if (entering(tcp)) { |
| 803 | printpath(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 804 | tprints(", "); |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 805 | } else { |
| 806 | printoldstat(tcp, tcp->u_arg[1]); |
| 807 | } |
| 808 | return 0; |
| 809 | } |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 810 | #endif |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 811 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 812 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 813 | sys_fstat(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 814 | { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 815 | if (entering(tcp)) { |
| 816 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 817 | tprints(", "); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 818 | } else { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 819 | printstat(tcp, tcp->u_arg[1]); |
| 820 | } |
| 821 | return 0; |
| 822 | } |
| 823 | |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 824 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 825 | sys_fstat64(struct tcb *tcp) |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 826 | { |
| 827 | #ifdef HAVE_STAT64 |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 828 | if (entering(tcp)) { |
| 829 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 830 | tprints(", "); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 831 | } else { |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 832 | # ifdef X32 |
| 833 | printstat64_x32(tcp, tcp->u_arg[1]); |
| 834 | # else |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 835 | printstat64(tcp, tcp->u_arg[1]); |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 836 | # endif |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 837 | } |
| 838 | return 0; |
| 839 | #else |
| 840 | return printargs(tcp); |
| 841 | #endif |
| 842 | } |
| 843 | |
Denys Vlasenko | 8435d67 | 2013-02-18 15:47:57 +0100 | [diff] [blame] | 844 | #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) |
Ulrich Drepper | 7f02c4d | 1999-12-24 08:01:34 +0000 | [diff] [blame] | 845 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 846 | sys_oldfstat(struct tcb *tcp) |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 847 | { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 848 | if (entering(tcp)) { |
| 849 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 850 | tprints(", "); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 851 | } else { |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 852 | printoldstat(tcp, tcp->u_arg[1]); |
| 853 | } |
| 854 | return 0; |
| 855 | } |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 856 | #endif |
Wichert Akkerman | 328c5e7 | 1999-04-16 00:21:26 +0000 | [diff] [blame] | 857 | |
Denys Vlasenko | 9472a27 | 2013-02-12 11:43:46 +0100 | [diff] [blame] | 858 | #if defined(SPARC) || defined(SPARC64) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 859 | |
| 860 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 861 | sys_xstat(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 862 | { |
| 863 | if (entering(tcp)) { |
| 864 | tprintf("%ld, ", tcp->u_arg[0]); |
| 865 | printpath(tcp, tcp->u_arg[1]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 866 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 867 | } else { |
| 868 | printstat(tcp, tcp->u_arg[2]); |
| 869 | } |
| 870 | return 0; |
| 871 | } |
| 872 | |
| 873 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 874 | sys_fxstat(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 875 | { |
Dmitry V. Levin | e00a957 | 2014-12-29 03:15:42 +0000 | [diff] [blame] | 876 | if (entering(tcp)) { |
| 877 | tprintf("%ld, ", tcp->u_arg[0]); |
| 878 | printfd(tcp, tcp->u_arg[1]); |
| 879 | tprints(", "); |
| 880 | } else { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 881 | printstat(tcp, tcp->u_arg[2]); |
| 882 | } |
| 883 | return 0; |
| 884 | } |
| 885 | |
Dmitry V. Levin | 964d80a | 2014-12-06 03:53:16 +0000 | [diff] [blame] | 886 | #endif /* SPARC || SPARC64 */ |