]> granicus.if.org Git - strace/blob - statx.c
Always print raw values of time data fields
[strace] / statx.c
1 /*
2  * Copyright (c) 2017 The strace developers.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #include "defs.h"
29 #include "statx.h"
30
31 #include <sys/stat.h>
32
33 #include "xlat/statx_masks.h"
34 #include "xlat/statx_attrs.h"
35 #include "xlat/at_statx_sync_types.h"
36
37 SYS_FUNC(statx)
38 {
39         if (entering(tcp)) {
40                 print_dirfd(tcp, tcp->u_arg[0]);
41                 printpath(tcp, tcp->u_arg[1]);
42                 tprints(", ");
43
44                 unsigned int flags = tcp->u_arg[2];
45                 printflags(at_statx_sync_types, flags & AT_STATX_SYNC_TYPE,
46                            NULL);
47                 flags &= ~AT_STATX_SYNC_TYPE;
48                 if (flags) {
49                         tprints("|");
50                         printflags(at_flags, flags, NULL);
51                 }
52
53                 tprints(", ");
54                 printflags(statx_masks, tcp->u_arg[3], "STATX_???");
55                 tprints(", ");
56         } else {
57 #define PRINT_FIELD_U(field) \
58         tprintf(", %s=%llu", #field, (unsigned long long) stx.field)
59
60 #define PRINT_FIELD_TIME(field)                                         \
61         do {                                                            \
62                 tprintf(", " #field "={tv_sec=%" PRId64                 \
63                         ", tv_nsec=%" PRIu32 "}",                       \
64                         stx.field.sec, stx.field.nsec);                 \
65                 tprints_comment(sprinttime_nsec(stx.field.sec,          \
66                         zero_extend_signed_to_ull(stx.field.nsec)));    \
67         } while (0)
68
69                 struct_statx stx;
70                 if (umove_or_printaddr(tcp, tcp->u_arg[4], &stx))
71                         return 0;
72
73                 tprints("{stx_mask=");
74                 printflags(statx_masks, stx.stx_mask, "STATX_???");
75
76                 if (!abbrev(tcp))
77                         PRINT_FIELD_U(stx_blksize);
78
79                 tprints(", stx_attributes=");
80                 printflags(statx_attrs, stx.stx_attributes, "STATX_ATTR_???");
81
82                 if (!abbrev(tcp)) {
83                         PRINT_FIELD_U(stx_nlink);
84                         printuid(", stx_uid=", stx.stx_uid);
85                         printuid(", stx_gid=", stx.stx_gid);
86                 }
87
88                 tprints(", stx_mode=");
89                 print_symbolic_mode_t(stx.stx_mode);
90
91                 if (!abbrev(tcp))
92                         PRINT_FIELD_U(stx_ino);
93
94                 PRINT_FIELD_U(stx_size);
95
96                 if (!abbrev(tcp)) {
97                         PRINT_FIELD_U(stx_blocks);
98
99                         tprints(", stx_attributes_mask=");
100                         printflags(statx_attrs, stx.stx_attributes_mask,
101                                    "STATX_ATTR_???");
102
103                         PRINT_FIELD_TIME(stx_atime);
104                         PRINT_FIELD_TIME(stx_btime);
105                         PRINT_FIELD_TIME(stx_ctime);
106                         PRINT_FIELD_TIME(stx_mtime);
107                         PRINT_FIELD_U(stx_rdev_major);
108                         PRINT_FIELD_U(stx_rdev_minor);
109                         PRINT_FIELD_U(stx_dev_major);
110                         PRINT_FIELD_U(stx_dev_minor);
111                 } else {
112                         tprints(", ...");
113                 }
114                 tprints("}");
115         }
116         return 0;
117 }