blob: f7c4238066c6aa0203f86a223601b3bd189ac666 [file] [log] [blame]
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00001/*
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. Levinab21a942014-12-28 18:15:25 +000035#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. Levine6e475c2015-01-08 03:13:59 +000043#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. Levinab21a942014-12-28 18:15:25 +000051static void
52DO_PRINTSTAT(struct tcb *tcp, const STRUCT_STAT *statbuf)
53{
Dmitry V. Levin8d374382016-08-03 14:05:39 +000054 tprints("{");
Dmitry V. Levinab21a942014-12-28 18:15:25 +000055 if (!abbrev(tcp)) {
Dmitry V. Levin8d374382016-08-03 14:05:39 +000056 tprintf("st_dev=makedev(%u, %u), st_ino=%llu, st_mode=",
Dmitry V. Levine6e475c2015-01-08 03:13:59 +000057 (unsigned int) STAT_MAJOR(statbuf->st_dev),
58 (unsigned int) STAT_MINOR(statbuf->st_dev),
Dmitry V. Levin8d374382016-08-03 14:05:39 +000059 widen_to_ull(statbuf->st_ino));
60 print_symbolic_mode_t(statbuf->st_mode);
61 tprintf(", st_nlink=%u, st_uid=%u, st_gid=%u",
Dmitry V. Levinab21a942014-12-28 18:15:25 +000062 (unsigned int) statbuf->st_nlink,
63 (unsigned int) statbuf->st_uid,
64 (unsigned int) statbuf->st_gid);
Dmitry V. Levin8d374382016-08-03 14:05:39 +000065 tprintf(", st_blksize=%u", (unsigned int) statbuf->st_blksize);
Dmitry V. Levin8d374382016-08-03 14:05:39 +000066 tprintf(", st_blocks=%llu", widen_to_ull(statbuf->st_blocks));
Dmitry V. Levinab21a942014-12-28 18:15:25 +000067 } else {
Dmitry V. Levin8d374382016-08-03 14:05:39 +000068 tprints("st_mode=");
69 print_symbolic_mode_t(statbuf->st_mode);
Dmitry V. Levinab21a942014-12-28 18:15:25 +000070 }
71
72 switch (statbuf->st_mode & S_IFMT) {
73 case S_IFCHR: case S_IFBLK:
Dmitry V. Levin8d374382016-08-03 14:05:39 +000074 tprintf(", st_rdev=makedev(%u, %u)",
Dmitry V. Levine6e475c2015-01-08 03:13:59 +000075 (unsigned int) STAT_MAJOR(statbuf->st_rdev),
76 (unsigned int) STAT_MINOR(statbuf->st_rdev));
Dmitry V. Levinab21a942014-12-28 18:15:25 +000077 break;
78 default:
Dmitry V. Levin8d374382016-08-03 14:05:39 +000079 tprintf(", st_size=%llu", widen_to_ull(statbuf->st_size));
Dmitry V. Levinab21a942014-12-28 18:15:25 +000080 break;
81 }
82
83 if (!abbrev(tcp)) {
Dmitry V. Levinbce1ff52015-03-12 16:59:01 +000084 const bool cast = sizeof(statbuf->st_atime) == sizeof(int);
85
Dmitry V. Levin8d374382016-08-03 14:05:39 +000086 tprints(", st_atime=");
Dmitry V. Levin525eed32015-08-08 12:12:13 +000087 tprints(sprinttime(cast ? (time_t) (int) statbuf->st_atime:
Dmitry V. Levinbce1ff52015-03-12 16:59:01 +000088 (time_t) statbuf->st_atime));
Dmitry V. Levin525eed32015-08-08 12:12:13 +000089#ifdef HAVE_STRUCT_STAT_ST_ATIME_NSEC
90 if (statbuf->st_atime_nsec)
91 tprintf(".%09lu", (unsigned long) statbuf->st_atime_nsec);
92#endif
93 tprints(", st_mtime=");
94 tprints(sprinttime(cast ? (time_t) (int) statbuf->st_mtime:
Dmitry V. Levinbce1ff52015-03-12 16:59:01 +000095 (time_t) statbuf->st_mtime));
Dmitry V. Levin525eed32015-08-08 12:12:13 +000096#ifdef HAVE_STRUCT_STAT_ST_MTIME_NSEC
97 if (statbuf->st_mtime_nsec)
98 tprintf(".%09lu", (unsigned long) statbuf->st_mtime_nsec);
99#endif
100 tprints(", st_ctime=");
101 tprints(sprinttime(cast ? (time_t) (int) statbuf->st_ctime:
Dmitry V. Levinbce1ff52015-03-12 16:59:01 +0000102 (time_t) statbuf->st_ctime));
Dmitry V. Levin525eed32015-08-08 12:12:13 +0000103#ifdef HAVE_STRUCT_STAT_ST_CTIME_NSEC
104 if (statbuf->st_ctime_nsec)
105 tprintf(".%09lu", (unsigned long) statbuf->st_ctime_nsec);
106#endif
Dmitry V. Levinab21a942014-12-28 18:15:25 +0000107 } else {
Dmitry V. Levin8d374382016-08-03 14:05:39 +0000108 tprints(", ...");
Dmitry V. Levinab21a942014-12-28 18:15:25 +0000109 }
Dmitry V. Levin8d374382016-08-03 14:05:39 +0000110 tprints("}");
Dmitry V. Levinab21a942014-12-28 18:15:25 +0000111}
112
Dmitry V. Levine6e475c2015-01-08 03:13:59 +0000113#undef STAT_MINOR
114#undef STAT_MAJOR
Dmitry V. Levinab21a942014-12-28 18:15:25 +0000115#undef STRUCT_STAT
116#undef DO_PRINTSTAT