]> granicus.if.org Git - strace/blob - fetch_struct_stat.c
rtnl_link: use internal rtnl_link_stats* and ifla_port_vsi definitions
[strace] / fetch_struct_stat.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_stat)
12
13 #include "asm_stat.h"
14
15 #if defined MPERS_IS_m32
16 # undef HAVE_STRUCT_STAT
17 # undef HAVE_STRUCT_STAT_ST_MTIME_NSEC
18 # ifdef HAVE_M32_STRUCT_STAT
19 #  define HAVE_STRUCT_STAT 1
20 #  ifdef HAVE_M32_STRUCT_STAT_ST_MTIME_NSEC
21 #   define HAVE_STRUCT_STAT_ST_MTIME_NSEC 1
22 #  endif /* HAVE_M32_STRUCT_STAT_ST_MTIME_NSEC */
23 # endif /* HAVE_M32_STRUCT_STAT */
24 #elif defined MPERS_IS_mx32
25 # undef HAVE_STRUCT_STAT
26 # undef HAVE_STRUCT_STAT_ST_MTIME_NSEC
27 # ifdef HAVE_MX32_STRUCT_STAT
28 #  define HAVE_STRUCT_STAT 1
29 #  ifdef HAVE_MX32_STRUCT_STAT_ST_MTIME_NSEC
30 #   define HAVE_STRUCT_STAT_ST_MTIME_NSEC 1
31 #  endif /* HAVE_MX32_STRUCT_STAT_ST_MTIME_NSEC */
32 # endif /* HAVE_MX32_STRUCT_STAT */
33 #else /* !MPERS_IS_m32 && !MPERS_IS_mx32 */
34 # define HAVE_STRUCT_STAT 1
35 #endif
36
37 #ifndef HAVE_STRUCT_STAT
38 struct stat {};
39 #endif
40
41 typedef struct stat struct_stat;
42
43 #include MPERS_DEFS
44
45 #include "stat.h"
46
47 #ifdef HAVE_STRUCT_STAT_ST_MTIME_NSEC
48 # define TIME_NSEC(arg) zero_extend_signed_to_ull(arg)
49 # define HAVE_NSEC true
50 #else
51 # define TIME_NSEC(arg) 0
52 # define HAVE_NSEC false
53 #endif
54
55 MPERS_PRINTER_DECL(bool, fetch_struct_stat,
56                    struct tcb *const tcp, const kernel_ulong_t addr,
57                    struct strace_stat *const dst)
58 {
59 #ifdef HAVE_STRUCT_STAT
60         struct_stat buf;
61         if (umove_or_printaddr(tcp, addr, &buf))
62                 return false;
63
64         dst->dev = zero_extend_signed_to_ull(buf.st_dev);
65         dst->ino = zero_extend_signed_to_ull(buf.st_ino);
66         dst->rdev = zero_extend_signed_to_ull(buf.st_rdev);
67         dst->size = zero_extend_signed_to_ull(buf.st_size);
68         dst->blocks = zero_extend_signed_to_ull(buf.st_blocks);
69         dst->blksize = zero_extend_signed_to_ull(buf.st_blksize);
70         dst->mode = zero_extend_signed_to_ull(buf.st_mode);
71         dst->nlink = zero_extend_signed_to_ull(buf.st_nlink);
72         dst->uid = zero_extend_signed_to_ull(buf.st_uid);
73         dst->gid = zero_extend_signed_to_ull(buf.st_gid);
74         dst->atime = sign_extend_unsigned_to_ll(buf.st_atime);
75         dst->ctime = sign_extend_unsigned_to_ll(buf.st_ctime);
76         dst->mtime = sign_extend_unsigned_to_ll(buf.st_mtime);
77         dst->atime_nsec = TIME_NSEC(buf.st_atime_nsec);
78         dst->ctime_nsec = TIME_NSEC(buf.st_ctime_nsec);
79         dst->mtime_nsec = TIME_NSEC(buf.st_mtime_nsec);
80         dst->has_nsec = HAVE_NSEC;
81         return true;
82 #else /* !HAVE_STRUCT_STAT */
83         printaddr(addr);
84         return false;
85 #endif
86 }