Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 1 | #ifndef DO_PRINTSTAT |
| 2 | # define DO_PRINTSTAT do_printstat |
| 3 | #endif |
| 4 | |
| 5 | #ifndef STRUCT_STAT |
| 6 | # define STRUCT_STAT struct stat |
| 7 | #endif |
| 8 | |
Dmitry V. Levin | e6e475c | 2015-01-08 03:13:59 +0000 | [diff] [blame] | 9 | #ifndef STAT_MAJOR |
| 10 | # define STAT_MAJOR(x) major(x) |
| 11 | #endif |
| 12 | |
| 13 | #ifndef STAT_MINOR |
| 14 | # define STAT_MINOR(x) minor(x) |
| 15 | #endif |
| 16 | |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 17 | static void |
| 18 | DO_PRINTSTAT(struct tcb *tcp, const STRUCT_STAT *statbuf) |
| 19 | { |
| 20 | if (!abbrev(tcp)) { |
| 21 | 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] | 22 | (unsigned int) STAT_MAJOR(statbuf->st_dev), |
| 23 | (unsigned int) STAT_MINOR(statbuf->st_dev), |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 24 | (unsigned long long) statbuf->st_ino, |
| 25 | sprintmode(statbuf->st_mode)); |
| 26 | tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ", |
| 27 | (unsigned int) statbuf->st_nlink, |
| 28 | (unsigned int) statbuf->st_uid, |
| 29 | (unsigned int) statbuf->st_gid); |
| 30 | #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE |
| 31 | tprintf("st_blksize=%u, ", (unsigned int) statbuf->st_blksize); |
| 32 | #endif |
| 33 | #ifdef HAVE_STRUCT_STAT_ST_BLOCKS |
| 34 | tprintf("st_blocks=%llu, ", |
| 35 | (unsigned long long) statbuf->st_blocks); |
| 36 | #endif |
| 37 | } else { |
| 38 | tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode)); |
| 39 | } |
| 40 | |
| 41 | switch (statbuf->st_mode & S_IFMT) { |
| 42 | case S_IFCHR: case S_IFBLK: |
| 43 | #ifdef HAVE_STRUCT_STAT_ST_RDEV |
| 44 | tprintf("st_rdev=makedev(%u, %u), ", |
Dmitry V. Levin | e6e475c | 2015-01-08 03:13:59 +0000 | [diff] [blame] | 45 | (unsigned int) STAT_MAJOR(statbuf->st_rdev), |
| 46 | (unsigned int) STAT_MINOR(statbuf->st_rdev)); |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 47 | #else /* !HAVE_STRUCT_STAT_ST_RDEV */ |
| 48 | tprintf("st_size=makedev(%u, %u), ", |
Dmitry V. Levin | e6e475c | 2015-01-08 03:13:59 +0000 | [diff] [blame] | 49 | (unsigned int) STAT_MAJOR(statbuf->st_size), |
| 50 | (unsigned int) STAT_MINOR(statbuf->st_size)); |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 51 | #endif /* !HAVE_STRUCT_STAT_ST_RDEV */ |
| 52 | break; |
| 53 | default: |
| 54 | tprintf("st_size=%llu, ", |
| 55 | (unsigned long long) statbuf->st_size); |
| 56 | break; |
| 57 | } |
| 58 | |
| 59 | if (!abbrev(tcp)) { |
Dmitry V. Levin | bce1ff5 | 2015-03-12 16:59:01 +0000 | [diff] [blame] | 60 | const bool cast = sizeof(statbuf->st_atime) == sizeof(int); |
| 61 | |
Dmitry V. Levin | 525eed3 | 2015-08-08 12:12:13 +0000 | [diff] [blame] | 62 | tprints("st_atime="); |
| 63 | tprints(sprinttime(cast ? (time_t) (int) statbuf->st_atime: |
Dmitry V. Levin | bce1ff5 | 2015-03-12 16:59:01 +0000 | [diff] [blame] | 64 | (time_t) statbuf->st_atime)); |
Dmitry V. Levin | 525eed3 | 2015-08-08 12:12:13 +0000 | [diff] [blame] | 65 | #ifdef HAVE_STRUCT_STAT_ST_ATIME_NSEC |
| 66 | if (statbuf->st_atime_nsec) |
| 67 | tprintf(".%09lu", (unsigned long) statbuf->st_atime_nsec); |
| 68 | #endif |
| 69 | tprints(", st_mtime="); |
| 70 | tprints(sprinttime(cast ? (time_t) (int) statbuf->st_mtime: |
Dmitry V. Levin | bce1ff5 | 2015-03-12 16:59:01 +0000 | [diff] [blame] | 71 | (time_t) statbuf->st_mtime)); |
Dmitry V. Levin | 525eed3 | 2015-08-08 12:12:13 +0000 | [diff] [blame] | 72 | #ifdef HAVE_STRUCT_STAT_ST_MTIME_NSEC |
| 73 | if (statbuf->st_mtime_nsec) |
| 74 | tprintf(".%09lu", (unsigned long) statbuf->st_mtime_nsec); |
| 75 | #endif |
| 76 | tprints(", st_ctime="); |
| 77 | tprints(sprinttime(cast ? (time_t) (int) statbuf->st_ctime: |
Dmitry V. Levin | bce1ff5 | 2015-03-12 16:59:01 +0000 | [diff] [blame] | 78 | (time_t) statbuf->st_ctime)); |
Dmitry V. Levin | 525eed3 | 2015-08-08 12:12:13 +0000 | [diff] [blame] | 79 | #ifdef HAVE_STRUCT_STAT_ST_CTIME_NSEC |
| 80 | if (statbuf->st_ctime_nsec) |
| 81 | tprintf(".%09lu", (unsigned long) statbuf->st_ctime_nsec); |
| 82 | #endif |
Dmitry V. Levin | d93c4e8 | 2015-06-17 20:09:13 +0000 | [diff] [blame] | 83 | #ifdef HAVE_STRUCT_STAT_ST_FLAGS |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 84 | tprintf(", st_flags=%u", (unsigned int) statbuf->st_flags); |
| 85 | #endif |
Dmitry V. Levin | d93c4e8 | 2015-06-17 20:09:13 +0000 | [diff] [blame] | 86 | #ifdef HAVE_STRUCT_STAT_ST_FSTYPE |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 87 | tprintf(", st_fstype=%.*s", |
| 88 | (int) sizeof statbuf->st_fstype, statbuf->st_fstype); |
| 89 | #endif |
Dmitry V. Levin | d93c4e8 | 2015-06-17 20:09:13 +0000 | [diff] [blame] | 90 | #ifdef HAVE_STRUCT_STAT_ST_GEN |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 91 | tprintf(", st_gen=%u", (unsigned int) statbuf->st_gen); |
| 92 | #endif |
| 93 | tprints("}"); |
| 94 | } else { |
| 95 | tprints("...}"); |
| 96 | } |
| 97 | } |
| 98 | |
Dmitry V. Levin | e6e475c | 2015-01-08 03:13:59 +0000 | [diff] [blame] | 99 | #undef STAT_MINOR |
| 100 | #undef STAT_MAJOR |
Dmitry V. Levin | ab21a94 | 2014-12-28 18:15:25 +0000 | [diff] [blame] | 101 | #undef STRUCT_STAT |
| 102 | #undef DO_PRINTSTAT |