]> granicus.if.org Git - strace/blob - fetch_struct_stat64.c
rtnl_link: print pad field in the struct ifla_port_vsi decoder
[strace] / fetch_struct_stat64.c
1 /*
2  * Copyright (c) 2014-2016 Dmitry V. Levin <ldv@altlinux.org>
3  * Copyright (c) 2016-2018 The strace developers.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: LGPL-2.1-or-later
7  */
8
9 #include "defs.h"
10
11 #include DEF_MPERS_TYPE(struct_stat64)
12
13 #include "asm_stat.h"
14
15 #if defined MPERS_IS_m32
16 # undef HAVE_STRUCT_STAT64
17 # undef HAVE_STRUCT_STAT64_ST_MTIME_NSEC
18 # ifdef HAVE_M32_STRUCT_STAT64
19 #  define HAVE_STRUCT_STAT64 1
20 #  ifdef HAVE_M32_STRUCT_STAT64_ST_MTIME_NSEC
21 #   define HAVE_STRUCT_STAT64_ST_MTIME_NSEC 1
22 #  endif /* HAVE_M32_STRUCT_STAT64_ST_MTIME_NSEC */
23 # endif /* HAVE_M32_STRUCT_STAT64 */
24 #elif defined MPERS_IS_mx32
25 # undef HAVE_STRUCT_STAT64
26 # undef HAVE_STRUCT_STAT64_ST_MTIME_NSEC
27 # ifdef HAVE_MX32_STRUCT_STAT64
28 #  define HAVE_STRUCT_STAT64 1
29 #  ifdef HAVE_MX32_STRUCT_STAT64_ST_MTIME_NSEC
30 #   define HAVE_STRUCT_STAT64_ST_MTIME_NSEC 1
31 #  endif /* HAVE_MX32_STRUCT_STAT64_ST_MTIME_NSEC */
32 # endif /* HAVE_MX32_STRUCT_STAT64 */
33 #endif /* MPERS_IS_m32 || MPERS_IS_mx32 */
34
35 #ifndef HAVE_STRUCT_STAT64
36 struct stat64 {};
37 #endif
38
39 typedef struct stat64 struct_stat64;
40
41 #include MPERS_DEFS
42
43 #include "stat.h"
44
45 #ifdef HAVE_STRUCT_STAT64_ST_MTIME_NSEC
46 # define TIME_NSEC(arg) zero_extend_signed_to_ull(arg)
47 # define HAVE_NSEC true
48 #else
49 # define TIME_NSEC(arg) 0
50 # define HAVE_NSEC false
51 #endif
52
53 MPERS_PRINTER_DECL(bool, fetch_struct_stat64,
54                    struct tcb *const tcp, const kernel_ulong_t addr,
55                    struct strace_stat *const dst)
56 {
57 #ifdef HAVE_STRUCT_STAT64
58         struct_stat64 buf;
59         if (umove_or_printaddr(tcp, addr, &buf))
60                 return false;
61
62         dst->dev = zero_extend_signed_to_ull(buf.st_dev);
63         dst->ino = zero_extend_signed_to_ull(buf.st_ino);
64         dst->rdev = zero_extend_signed_to_ull(buf.st_rdev);
65         dst->size = zero_extend_signed_to_ull(buf.st_size);
66         dst->blocks = zero_extend_signed_to_ull(buf.st_blocks);
67         dst->blksize = zero_extend_signed_to_ull(buf.st_blksize);
68         dst->mode = zero_extend_signed_to_ull(buf.st_mode);
69         dst->nlink = zero_extend_signed_to_ull(buf.st_nlink);
70         dst->uid = zero_extend_signed_to_ull(buf.st_uid);
71         dst->gid = zero_extend_signed_to_ull(buf.st_gid);
72         dst->atime = sign_extend_unsigned_to_ll(buf.st_atime);
73         dst->ctime = sign_extend_unsigned_to_ll(buf.st_ctime);
74         dst->mtime = sign_extend_unsigned_to_ll(buf.st_mtime);
75         dst->atime_nsec = TIME_NSEC(buf.st_atime_nsec);
76         dst->ctime_nsec = TIME_NSEC(buf.st_ctime_nsec);
77         dst->mtime_nsec = TIME_NSEC(buf.st_mtime_nsec);
78         dst->has_nsec = HAVE_NSEC;
79         return true;
80 #else /* !HAVE_STRUCT_STAT64 */
81         printaddr(addr);
82         return false;
83 #endif
84 }