1 /*
2 * Copyright (c) 2014-2016 Dmitry V. Levin <ldv@altlinux.org>
3 * Copyright (c) 2016-2017 The strace developers.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include "defs.h"
30
31 #include DEF_MPERS_TYPE(struct_statfs)
32 #include DEF_MPERS_TYPE(struct_statfs64)
33
34 #include <linux/types.h>
35 #include <asm/statfs.h>
36 typedef struct statfs struct_statfs;
37 typedef struct statfs64 struct_statfs64;
38
39 #include MPERS_DEFS
40
41 #include "statfs.h"
42
MPERS_PRINTER_DECL(bool,fetch_struct_statfs,struct tcb * const tcp,const kernel_ulong_t addr,struct strace_statfs * const p)43 MPERS_PRINTER_DECL(bool, fetch_struct_statfs,
44 struct tcb *const tcp, const kernel_ulong_t addr,
45 struct strace_statfs *const p)
46 {
47 struct_statfs b;
48
49 if (umove_or_printaddr(tcp, addr, &b))
50 return false;
51
52 p->f_type = zero_extend_signed_to_ull(b.f_type);
53 p->f_bsize = zero_extend_signed_to_ull(b.f_bsize);
54 p->f_blocks = zero_extend_signed_to_ull(b.f_blocks);
55 p->f_bfree = zero_extend_signed_to_ull(b.f_bfree);
56 p->f_bavail = zero_extend_signed_to_ull(b.f_bavail);
57 p->f_files = zero_extend_signed_to_ull(b.f_files);
58 p->f_ffree = zero_extend_signed_to_ull(b.f_ffree);
59 #if defined HAVE_STRUCT_STATFS_F_FSID_VAL
60 p->f_fsid[0] = zero_extend_signed_to_ull(b.f_fsid.val[0]);
61 p->f_fsid[1] = zero_extend_signed_to_ull(b.f_fsid.val[1]);
62 #elif defined HAVE_STRUCT_STATFS_F_FSID___VAL
63 p->f_fsid[0] = zero_extend_signed_to_ull(b.f_fsid.__val[0]);
64 p->f_fsid[1] = zero_extend_signed_to_ull(b.f_fsid.__val[1]);
65 #endif
66 p->f_namelen = zero_extend_signed_to_ull(b.f_namelen);
67 #ifdef HAVE_STRUCT_STATFS_F_FRSIZE
68 p->f_frsize = zero_extend_signed_to_ull(b.f_frsize);
69 #endif
70 #ifdef HAVE_STRUCT_STATFS_F_FLAGS
71 p->f_flags = zero_extend_signed_to_ull(b.f_flags);
72 #endif
73
74 return true;
75 }
76
77 #if defined ARM || (defined AARCH64 && defined IN_MPERS)
78 /* See arch/arm/kernel/sys_oabi-compat.c for details. */
79 # define COMPAT_STATFS64_PADDED_SIZE (sizeof(struct_statfs64) + 4)
80 #endif
81
MPERS_PRINTER_DECL(bool,fetch_struct_statfs64,struct tcb * const tcp,const kernel_ulong_t addr,const kernel_ulong_t size,struct strace_statfs * const p)82 MPERS_PRINTER_DECL(bool, fetch_struct_statfs64,
83 struct tcb *const tcp, const kernel_ulong_t addr,
84 const kernel_ulong_t size, struct strace_statfs *const p)
85 {
86 struct_statfs64 b;
87
88 if (sizeof(b) != size
89 #ifdef COMPAT_STATFS64_PADDED_SIZE
90 && sizeof(b) != COMPAT_STATFS64_PADDED_SIZE
91 #endif
92 ) {
93 printaddr(addr);
94 return false;
95 }
96
97 if (umove_or_printaddr(tcp, addr, &b))
98 return false;
99
100 p->f_type = zero_extend_signed_to_ull(b.f_type);
101 p->f_bsize = zero_extend_signed_to_ull(b.f_bsize);
102 p->f_blocks = zero_extend_signed_to_ull(b.f_blocks);
103 p->f_bfree = zero_extend_signed_to_ull(b.f_bfree);
104 p->f_bavail = zero_extend_signed_to_ull(b.f_bavail);
105 p->f_files = zero_extend_signed_to_ull(b.f_files);
106 p->f_ffree = zero_extend_signed_to_ull(b.f_ffree);
107 #if defined HAVE_STRUCT_STATFS64_F_FSID_VAL
108 p->f_fsid[0] = zero_extend_signed_to_ull(b.f_fsid.val[0]);
109 p->f_fsid[1] = zero_extend_signed_to_ull(b.f_fsid.val[1]);
110 #elif defined HAVE_STRUCT_STATFS64_F_FSID___VAL
111 p->f_fsid[0] = zero_extend_signed_to_ull(b.f_fsid.__val[0]);
112 p->f_fsid[1] = zero_extend_signed_to_ull(b.f_fsid.__val[1]);
113 #endif
114 p->f_namelen = zero_extend_signed_to_ull(b.f_namelen);
115 #ifdef HAVE_STRUCT_STATFS64_F_FRSIZE
116 p->f_frsize = zero_extend_signed_to_ull(b.f_frsize);
117 #endif
118 #ifdef HAVE_STRUCT_STATFS64_F_FLAGS
119 p->f_flags = zero_extend_signed_to_ull(b.f_flags);
120 #endif
121
122 return true;
123 }
124