Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1999-2003 Ulrich Drepper <drepper@redhat.com> |
| 3 | * Copyright (c) 2004 David S. Miller <davem@nuts.davemloft.net> |
| 4 | * Copyright (c) 2003-2005 Roland McGrath <roland@redhat.com> |
| 5 | * Copyright (c) 2007 Jan Kratochvil <jan.kratochvil@redhat.com> |
| 6 | * Copyright (c) 2009 Denys Vlasenko <dvlasenk@redhat.com> |
| 7 | * Copyright (c) 2009-2010 Andreas Schwab <schwab@linux-m68k.org> |
| 8 | * Copyright (c) 2012 H.J. Lu <hongjiu.lu@intel.com> |
| 9 | * Copyright (c) 2005-2015 Dmitry V. Levin <ldv@altlinux.org> |
| 10 | * All rights reserved. |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * 1. Redistributions of source code must retain the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer. |
| 17 | * 2. Redistributions in binary form must reproduce the above copyright |
| 18 | * notice, this list of conditions and the following disclaimer in the |
| 19 | * documentation and/or other materials provided with the distribution. |
| 20 | * 3. The name of the author may not be used to endorse or promote products |
| 21 | * derived from this software without specific prior written permission. |
| 22 | * |
| 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | */ |
| 34 | |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 35 | #ifndef DO_PRINTSTAT |
| 36 | # define DO_PRINTSTAT do_printstat |
| 37 | #endif |
| 38 | |
| 39 | #ifndef STRUCT_STAT |
| 40 | # define STRUCT_STAT struct stat |
| 41 | #endif |
| 42 | |
Dmitry V. Levin | e6e475c | 2015-01-08 03:13:59 +0000 | [diff] [blame] | 43 | #ifndef STAT_MAJOR |
| 44 | # define STAT_MAJOR(x) major(x) |
| 45 | #endif |
| 46 | |
| 47 | #ifndef STAT_MINOR |
| 48 | # define STAT_MINOR(x) minor(x) |
| 49 | #endif |
| 50 | |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 51 | static void |
| 52 | DO_PRINTSTAT(struct tcb *tcp, const STRUCT_STAT *statbuf) |
| 53 | { |
| 54 | if (!abbrev(tcp)) { |
| 55 | tprintf("{st_dev=makedev(%u, %u), st_ino=%llu, st_mode=%s, ", |
Dmitry V. Levin | e6e475c | 2015-01-08 03:13:59 +0000 | [diff] [blame] | 56 | (unsigned int) STAT_MAJOR(statbuf->st_dev), |
| 57 | (unsigned int) STAT_MINOR(statbuf->st_dev), |
Dmitry V. Levin | 84a979c | 2016-05-26 10:12:17 +0000 | [diff] [blame] | 58 | widen_to_ull(statbuf->st_ino), |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 59 | sprintmode(statbuf->st_mode)); |
| 60 | tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ", |
| 61 | (unsigned int) statbuf->st_nlink, |
| 62 | (unsigned int) statbuf->st_uid, |
| 63 | (unsigned int) statbuf->st_gid); |
| 64 | #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE |
| 65 | tprintf("st_blksize=%u, ", (unsigned int) statbuf->st_blksize); |
| 66 | #endif |
| 67 | #ifdef HAVE_STRUCT_STAT_ST_BLOCKS |
Dmitry V. Levin | 84a979c | 2016-05-26 10:12:17 +0000 | [diff] [blame] | 68 | tprintf("st_blocks=%llu, ", widen_to_ull(statbuf->st_blocks)); |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 69 | #endif |
| 70 | } else { |
| 71 | tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode)); |
| 72 | } |
| 73 | |
| 74 | switch (statbuf->st_mode & S_IFMT) { |
| 75 | case S_IFCHR: case S_IFBLK: |
| 76 | #ifdef HAVE_STRUCT_STAT_ST_RDEV |
| 77 | tprintf("st_rdev=makedev(%u, %u), ", |
Dmitry V. Levin | e6e475c | 2015-01-08 03:13:59 +0000 | [diff] [blame] | 78 | (unsigned int) STAT_MAJOR(statbuf->st_rdev), |
| 79 | (unsigned int) STAT_MINOR(statbuf->st_rdev)); |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 80 | #else /* !HAVE_STRUCT_STAT_ST_RDEV */ |
| 81 | tprintf("st_size=makedev(%u, %u), ", |
Dmitry V. Levin | e6e475c | 2015-01-08 03:13:59 +0000 | [diff] [blame] | 82 | (unsigned int) STAT_MAJOR(statbuf->st_size), |
| 83 | (unsigned int) STAT_MINOR(statbuf->st_size)); |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 84 | #endif /* !HAVE_STRUCT_STAT_ST_RDEV */ |
| 85 | break; |
| 86 | default: |
Dmitry V. Levin | 84a979c | 2016-05-26 10:12:17 +0000 | [diff] [blame] | 87 | tprintf("st_size=%llu, ", widen_to_ull(statbuf->st_size)); |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 88 | break; |
| 89 | } |
| 90 | |
| 91 | if (!abbrev(tcp)) { |
Dmitry V. Levin | bce1ff5 | 2015-03-12 16:59:01 +0000 | [diff] [blame] | 92 | const bool cast = sizeof(statbuf->st_atime) == sizeof(int); |
| 93 | |
Dmitry V. Levin | 525eed3 | 2015-08-08 12:12:13 +0000 | [diff] [blame] | 94 | tprints("st_atime="); |
| 95 | tprints(sprinttime(cast ? (time_t) (int) statbuf->st_atime: |
Dmitry V. Levin | bce1ff5 | 2015-03-12 16:59:01 +0000 | [diff] [blame] | 96 | (time_t) statbuf->st_atime)); |
Dmitry V. Levin | 525eed3 | 2015-08-08 12:12:13 +0000 | [diff] [blame] | 97 | #ifdef HAVE_STRUCT_STAT_ST_ATIME_NSEC |
| 98 | if (statbuf->st_atime_nsec) |
| 99 | tprintf(".%09lu", (unsigned long) statbuf->st_atime_nsec); |
| 100 | #endif |
| 101 | tprints(", st_mtime="); |
| 102 | tprints(sprinttime(cast ? (time_t) (int) statbuf->st_mtime: |
Dmitry V. Levin | bce1ff5 | 2015-03-12 16:59:01 +0000 | [diff] [blame] | 103 | (time_t) statbuf->st_mtime)); |
Dmitry V. Levin | 525eed3 | 2015-08-08 12:12:13 +0000 | [diff] [blame] | 104 | #ifdef HAVE_STRUCT_STAT_ST_MTIME_NSEC |
| 105 | if (statbuf->st_mtime_nsec) |
| 106 | tprintf(".%09lu", (unsigned long) statbuf->st_mtime_nsec); |
| 107 | #endif |
| 108 | tprints(", st_ctime="); |
| 109 | tprints(sprinttime(cast ? (time_t) (int) statbuf->st_ctime: |
Dmitry V. Levin | bce1ff5 | 2015-03-12 16:59:01 +0000 | [diff] [blame] | 110 | (time_t) statbuf->st_ctime)); |
Dmitry V. Levin | 525eed3 | 2015-08-08 12:12:13 +0000 | [diff] [blame] | 111 | #ifdef HAVE_STRUCT_STAT_ST_CTIME_NSEC |
| 112 | if (statbuf->st_ctime_nsec) |
| 113 | tprintf(".%09lu", (unsigned long) statbuf->st_ctime_nsec); |
| 114 | #endif |
Dmitry V. Levin | d93c4e8 | 2015-06-17 20:09:13 +0000 | [diff] [blame] | 115 | #ifdef HAVE_STRUCT_STAT_ST_FLAGS |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 116 | tprintf(", st_flags=%u", (unsigned int) statbuf->st_flags); |
| 117 | #endif |
Dmitry V. Levin | d93c4e8 | 2015-06-17 20:09:13 +0000 | [diff] [blame] | 118 | #ifdef HAVE_STRUCT_STAT_ST_FSTYPE |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 119 | tprintf(", st_fstype=%.*s", |
| 120 | (int) sizeof statbuf->st_fstype, statbuf->st_fstype); |
| 121 | #endif |
Dmitry V. Levin | d93c4e8 | 2015-06-17 20:09:13 +0000 | [diff] [blame] | 122 | #ifdef HAVE_STRUCT_STAT_ST_GEN |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 123 | tprintf(", st_gen=%u", (unsigned int) statbuf->st_gen); |
| 124 | #endif |
| 125 | tprints("}"); |
| 126 | } else { |
| 127 | tprints("...}"); |
| 128 | } |
| 129 | } |
| 130 | |
Dmitry V. Levin | e6e475c | 2015-01-08 03:13:59 +0000 | [diff] [blame] | 131 | #undef STAT_MINOR |
| 132 | #undef STAT_MAJOR |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 133 | #undef STRUCT_STAT |
| 134 | #undef DO_PRINTSTAT |