Branch data Line data Source code
1 : : /*
2 : : * Copyright (c) 2014-2016 Dmitry V. Levin <ldv@altlinux.org>
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 : :
30 : : #include DEF_MPERS_TYPE(struct_stat64)
31 : :
32 : : #include "asm_stat.h"
33 : :
34 : : #if defined MPERS_IS_m32
35 : : # undef HAVE_STRUCT_STAT64
36 : : # undef HAVE_STRUCT_STAT64_ST_MTIME_NSEC
37 : : # ifdef HAVE_M32_STRUCT_STAT64
38 : : # define HAVE_STRUCT_STAT64 1
39 : : # ifdef HAVE_M32_STRUCT_STAT64_ST_MTIME_NSEC
40 : : # define HAVE_STRUCT_STAT64_ST_MTIME_NSEC 1
41 : : # endif /* HAVE_M32_STRUCT_STAT64_ST_MTIME_NSEC */
42 : : # endif /* HAVE_M32_STRUCT_STAT64 */
43 : : #elif defined MPERS_IS_mx32
44 : : # undef HAVE_STRUCT_STAT64
45 : : # undef HAVE_STRUCT_STAT64_ST_MTIME_NSEC
46 : : # ifdef HAVE_MX32_STRUCT_STAT64
47 : : # define HAVE_STRUCT_STAT64 1
48 : : # ifdef HAVE_MX32_STRUCT_STAT64_ST_MTIME_NSEC
49 : : # define HAVE_STRUCT_STAT64_ST_MTIME_NSEC 1
50 : : # endif /* HAVE_MX32_STRUCT_STAT64_ST_MTIME_NSEC */
51 : : # endif /* HAVE_MX32_STRUCT_STAT64 */
52 : : #endif /* MPERS_IS_m32 || MPERS_IS_mx32 */
53 : :
54 : : #ifndef HAVE_STRUCT_STAT64
55 : : struct stat64 {};
56 : : #endif
57 : :
58 : : typedef struct stat64 struct_stat64;
59 : :
60 : : #include MPERS_DEFS
61 : :
62 : : #include "stat.h"
63 : :
64 : : #ifdef HAVE_STRUCT_STAT64_ST_MTIME_NSEC
65 : : # define TIME_NSEC(arg) zero_extend_signed_to_ull(arg)
66 : : #else
67 : : # define TIME_NSEC(arg) 0
68 : : #endif
69 : :
70 : 18 : MPERS_PRINTER_DECL(bool, fetch_struct_stat64,
71 : : struct tcb *const tcp, const kernel_ulong_t addr,
72 : : struct strace_stat *const dst)
73 : : {
74 : : #ifdef HAVE_STRUCT_STAT64
75 : : struct_stat64 buf;
76 [ + + ]: 18 : if (umove_or_printaddr(tcp, addr, &buf))
77 : 4 : return false;
78 : :
79 : 14 : dst->dev = zero_extend_signed_to_ull(buf.st_dev);
80 : 14 : dst->ino = zero_extend_signed_to_ull(buf.st_ino);
81 : 14 : dst->rdev = zero_extend_signed_to_ull(buf.st_rdev);
82 : 14 : dst->size = zero_extend_signed_to_ull(buf.st_size);
83 : 14 : dst->blocks = zero_extend_signed_to_ull(buf.st_blocks);
84 : 14 : dst->blksize = zero_extend_signed_to_ull(buf.st_blksize);
85 : 14 : dst->mode = zero_extend_signed_to_ull(buf.st_mode);
86 : 14 : dst->nlink = zero_extend_signed_to_ull(buf.st_nlink);
87 : 14 : dst->uid = zero_extend_signed_to_ull(buf.st_uid);
88 : 14 : dst->gid = zero_extend_signed_to_ull(buf.st_gid);
89 : 14 : dst->atime = sign_extend_unsigned_to_ll(buf.st_atime);
90 : 14 : dst->ctime = sign_extend_unsigned_to_ll(buf.st_ctime);
91 : 14 : dst->mtime = sign_extend_unsigned_to_ll(buf.st_mtime);
92 : 14 : dst->atime_nsec = TIME_NSEC(buf.st_atime_nsec);
93 : 14 : dst->ctime_nsec = TIME_NSEC(buf.st_ctime_nsec);
94 : 14 : dst->mtime_nsec = TIME_NSEC(buf.st_mtime_nsec);
95 : 18 : return true;
96 : : #else /* !HAVE_STRUCT_STAT64 */
97 : 0 : printaddr(addr);
98 : 0 : return false;
99 : : #endif
100 : : }
|