1 /*
2 * Copyright (c) 2005-2015 Dmitry V. Levin <ldv@strace.io>
3 * Copyright (c) 2015-2021 The strace developers.
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: LGPL-2.1-or-later
7 */
8
9 #include "defs.h"
10 #include "stat.h"
11
12 static void
13 decode_struct_stat(struct tcb *const tcp, const kernel_ulong_t addr)
14 {
15 struct strace_stat st;
16
17 if (fetch_struct_stat(tcp, addr, &st))
18 print_struct_stat(tcp, &st);
19 }
20
21 SYS_FUNC(stat)
22 {
23 if (entering(tcp)) {
24 /* pathname */
25 printpath(tcp, tcp->u_arg[0]);
26 tprint_arg_next();
27 } else {
28 /* statbuf */
29 decode_struct_stat(tcp, tcp->u_arg[1]);
30 }
31 return 0;
32 }
33
34 SYS_FUNC(fstat)
35 {
36 if (entering(tcp)) {
37 /* fd */
38 printfd(tcp, tcp->u_arg[0]);
39 tprint_arg_next();
40 } else {
41 /* statbuf */
42 decode_struct_stat(tcp, tcp->u_arg[1]);
43 }
44 return 0;
45 }
46
47 SYS_FUNC(newfstatat)
48 {
49 if (entering(tcp)) {
50 /* dirfd */
51 print_dirfd(tcp, tcp->u_arg[0]);
52 tprint_arg_next();
53
54 /* pathname */
55 printpath(tcp, tcp->u_arg[1]);
56 tprint_arg_next();
57 } else {
58 /* statbuf */
59 decode_struct_stat(tcp, tcp->u_arg[2]);
60 tprint_arg_next();
61
62 /* flags */
63 printflags(at_flags, tcp->u_arg[3], "AT_???");
64 }
65 return 0;
66 }